Monday, November 11, 2013

An Application Package on Linear Regression Analysis ~~ VisualBasic Code Snippet + GUI Design

Okkk.. as promised, here is my app package(software) on Simple Linear Regression Analysis Using Visual basic.
Fact! i said in the beginning that every post i make will be for those who know OR have little knowledge about programming. if you don't, then, you need help ~~> 4rm some1 who knows some1 who knows some1 who knows how to program.....lol......just joking....... u need to learn it some how.
"Some1 asked me ~ is it a robust program?" i answered ~~ that 's an meant for you to figure out. you too, yes! you;
          -----------------
          Screen shots
          -----------------


               --------------
                Source Code
               --------------
Public Class frmmain
    Public n As Integer

    Public xCount As Double
    Public countx As Integer, counterx As Integer

    Public yCount As Double
    Public county As Integer, countery As Integer

    Public x_yCount As Double
    Public countxt As Integer, counterxt As Integer

    Public x_xCount As Double
    Public countxSquare As Integer, counterxSquare As Integer

    Public xxCount As Double
    Public countxx As Integer, counterxx As Integer

    Public xyCount As Double
    Public countxy As Integer, counterxy As Integer

    Public y_yCount As Double
    Public countySquare As Integer, counterySquare As Integer

    Public yyCount As Double
    Public countyy As Integer, counteryy As Integer

    Public ymean As Double, xmean As Double

    Public slope As Double, intercept As Double, lstSquare As Double,         pearsons As Double, standarderror As Double

    Public i As Integer ' for scatter plot

    Private Sub CmdAddx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdAddx.Click
        Try
            If txtXvalue.Text = Double.NaN Then
            End If
        Catch ex As Exception
            MessageBox.Show("Value entered is not a number, Enter value of type integer or double", "SLRegression", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtXvalue.Focus()
            GoTo uuu
        End Try

        If txtXvalue.Text = String.Empty Then
        Else
            lstx.Items.Add(txtXvalue.Text)
            txtXvalue.Text = String.Empty

            txtXvalue.Focus()
        End If
uuu:
End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub ClearTheValuesOfXToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearTheValuesOfXToolStripMenuItem.Click
        lstx.Items.Clear()
    End Sub

    Private Sub ClearTheValuesOfYToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearTheValuesOfYToolStripMenuItem.Click
        lsty.Items.Clear()
    End Sub

    Private Sub cmdAddy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddy.Click
        Try
            If txtYvalue.Text = Double.NaN Then
            End If
        Catch ex As Exception
            MessageBox.Show("Value entered is not a number, Enter value of type integer or double", "SLRegression", MessageBoxButtons.OK, MessageBoxIcon.Information)
            txtYvalue.Focus()
            GoTo yyy
        End Try

        If txtYvalue.Text = String.Empty Then
        Else

            lsty.Items.Add(txtYvalue.Text)
            txtYvalue.Text = String.Empty
            txtYvalue.Focus()
        End If
yyy:
    End Sub

    Public Sub AllResultsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllResultsToolStripMenuItem.Click
        If lstx.Items.Count = 0 Or lsty.Items.Count = 0 Then
            MessageBox.Show("No input values for x or y", "SLRegression", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtXvalue.Focus()
            GoTo empty
        End If

        If lstx.Items.Count = 1 Or lsty.Items.Count = 1 Then
            MessageBox.Show("Required input should be more than 1 for both x & y", "SLRegression", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtXvalue.Focus()
            GoTo empty
        End If

        If lstx.Items.Count = lsty.Items.Count Then

            xCount = 0
            yCount = 0
            x_xCount = 0
            y_yCount = 0
            x_yCount = 0
            xxCount = 0
            xyCount = 0
            yyCount = 0
            ymean = 0
            xmean = 0
            slope = 0
            intercept = 0
            lstSquare = 0
            pearsons = 0
            i = 0
            lstxx.Items.Clear()
            lstxy.Items.Clear()
            lstyy.Items.Clear()

            'Public Sub n() ' entry count
            n = lstx.Items.Count
            ' End Sub

            ' Public Sub sumOfx()     ' SUM OF X
            countx = lstx.Items.Count

            For counterx = 1 To countx
                xCount = xCount + lstx.Items(counterx - 1)
            Next
            'End Sub

            ' Public Sub sumOfy()        ' SUM OF Y
            county = lsty.Items.Count

            For countery = 1 To county
                yCount = yCount + lsty.Items(countery - 1)
            Next
            '  End Sub

            ' Public Sub computexXy() ' COMPUTING X TIMES Y // xt, where t for times

            ' initialising variables
            lstxy.Items.Clear()
            countxt = lstx.Items.Count
            For counterxt = 1 To countxt

           x_yCount = ((lstx.Items(counterxt - 1)) * (lsty.Items(counterxt - 1)))

           lstxy.Items.Add(x_yCount)
            Next
            ' End Sub

            ' Public Sub computexXx()    ' COMPUTING X TIMES X
            ' initialising variables
            countxSquare = lstx.Items.Count

            For counterxSquare = 1 To countxSquare
                x_xCount = ((lstx.Items(counterxSquare - 1)) * (lstx.Items(counterxSquare - 1)))

                lstxx.Items.Add(x_xCount)
            Next
            ' End Sub

            '   Public Sub sumOfxx()  'SUM OF X TIMES X
            countxx = lstxx.Items.Count

            For counterxx = 1 To countxx
                xxCount = xxCount + lstxx.Items(counterxx - 1)
            Next
            '   End Sub

            '     Public Sub sumOfxy() ' SUM OF X*Y

            countxy = lstxy.Items.Count
            For counterxy = 1 To countxy
                xyCount = xyCount + lstxy.Items(counterxy - 1)
            Next
            '      End Sub

            ' Public Sub computeyXy()    ' COMPUTING Y TIMES Y

            ' initialising variables
            countySquare = lsty.Items.Count

            For counterySquare = 1 To countySquare
                y_yCount = ((lsty.Items(counterySquare - 1)) * (lsty.Items(counterySquare - 1)))

                lstyy.Items.Add(y_yCount)
            Next
            ' End Sub

            '   Public Sub sumOfyy()  'SUM OF Y TIMES Y

            countyy = lstyy.Items.Count

            For counteryy = 1 To countyy
                yyCount = yyCount + lstyy.Items(counteryy - 1)
            Next
            '   End Sub

            ' FILLING VACANT SPACES
            lblSumOfX.Text = xCount
            lblSumOfY.Text = yCount
            lblSumOfXY.Text = xyCount
            lblSumOfXX.Text = xxCount
            lblSumOfYY.Text = yyCount

            ' GETTING THE MEAN OF X & Y
            ymean = yCount / n
            xmean = xCount / n

            ' Calculating the slope  -- b
            slope = ((n * xyCount) - (xCount * yCount)) / ((n * xxCount) - (xCount * xCount))

            ' Calculating the intercept -- a
            intercept = (yCount / n) - (slope * (xCount / n))

            ' COMPUTIN D LST SQUARE
            lstSquare = Math.Sqrt(((intercept * yyCount) - (slope * xyCount) - (n * (ymean * ymean))) / (yyCount - (n * (ymean * ymean))))

            ' COMPUTING THE STANDARD_ERROR OF ESTIMATION
            standarderror = (Math.Sqrt((yCount * yCount) - (intercept * yCount) - (slope * xyCount)) / Math.Sqrt(n - 2))

            ' COMPUTING PEARSONS CofC
            pearsons = (xyCount - (n * xmean * ymean)) / Math.Sqrt((yyCount - (n * (ymean * ymean))) * (xxCount - (n * (xmean * xmean))))

            lblResult.Text = "  The mean of x is " & Math.Round(xmean, 2) & " ; " & "The mean of y is " & Math.Round(ymean, 2) _
                    & " ; " & "The Regression line y = " & Math.Round(intercept, 2) & " + " & Math.Round(slope, 2) & "x" & _
                    "  " & vbCr & "  The Standard error of estimation = " & Math.Round(standarderror, 2) & _
                    "  " & vbCr & "  The Pearsons Coefficient of Correlation (r) = " & Math.Round(pearsons, 2)

            '' PLOtting the graph
            'TextBox1.Text = lstSquare
            ScatterPlot.chartType = MSChart20Lib.VtChChartType.VtChChartType2dXY

            ScatterPlot.RowCount = n
            ScatterPlot.ColumnCount = 2

            For i = 1 To ScatterPlot.RowCount

                ScatterPlot.Row = i
                ScatterPlot.RowLabel = i

                ScatterPlot.Column = 1
                ScatterPlot.Data = lstx.Items(i - 1)

                ScatterPlot.Column = 2
                ScatterPlot.Data = lsty.Items(i - 1)
            Next
            Scattercover.Visible = Fals
        Else
            MessageBox.Show("No corresponding y value for a given value of x or vice-versa", "SLRegression", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
empty:
        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        Else
        End If

        '' the regression line
        ScatterPlot.Plot.SeriesCollection(1).StatLine.Flag = MSChart20Lib.VtChStats.VtChStatsRegression
    End Sub

    Private Sub ScatterPlotToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScatterPlotToolStripMenuItem.Click
        Me.AllResultsToolStripMenuItem.PerformClick()
        lblResult.Text = String.Empty

        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        End If
    End Sub

    Private Sub XMeanToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XMeanToolStripMenuItem.Click
        Me.AllResultsToolStripMenuItem.PerformClick()

        Scattercover.Visible = True
        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        Else
            lblResult.Text = "The mean of x is " & Math.Round(xmean, 2)
        End If
    End Sub

    Private Sub YMeanToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YMeanToolStripMenuItem.Click
        Me.AllResultsToolStripMenuItem.PerformClick()
        Scattercover.Visible = True

        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        Else
            lblResult.Text = "The mean of y is " & Math.Round(ymean, 2)
        End If
    End Sub

    Private Sub TheRegressionLineToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TheRegressionLineToolStripMenuItem.Click
        Me.AllResultsToolStripMenuItem.PerformClick()
        Scattercover.Visible = True

        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        Else
            lblResult.Text = "The Regression line y = " & Math.Round(intercept, 2) & " + " & Math.Round(slope, 2) & "x"
        End If
    End Sub

    Private Sub LeastSquareToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeastSquareToolStripMenuItem.Click
        Me.AllResultsToolStripMenuItem.PerformClick()
        Scattercover.Visible = True

        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        Else
            lblResult.Text = "The LeastSquare of the Regression line = " & Math.Round(lstSquare, 2)
        End If
    End Sub

    Private Sub PearsonsCOfCToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PearsonsCOfCToolStripMenuItem.Click
        Me.AllResultsToolStripMenuItem.PerformClick()
        Scattercover.Visible = True

        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        Else
            lblResult.Text = "The Pearsons Coefficient of Correlation for the Regression line r = " & Math.Round(pearsons, 2)
        End If
    End Sub

    Private Sub BlankResultPageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
        If Scattercover.Visible = False Then
            Scattercover.Visible = True
        End If
        ResultsToolStripMenuItem.Enabled = True
        ClearTheValuesOfXToolStripMenuItem.Enabled = True
        ClearTheValuesOfYToolStripMenuItem.Enabled = True
        lblcover.Visible = False
        lstx.Items.Clear()
        lsty.Items.Clear()
        lstxy.Items.Clear()
        lstxx.Items.Clear()
        lstyy.Items.Clear()
        lblSumOfX.Text = ""
        lblSumOfY.Text = ""
        lblSumOfXX.Text = ""
        lblSumOfXY.Text = ""
        lblSumOfYY.Text = ""
        lblResult.Text = String.Empty

    End Sub

    Private Sub cmdRemoveX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemoveX.Click
        lstx.Items.Remove(lstx.SelectedItem)
    End Sub

    Private Sub cmdRemoveY_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemoveY.Click
        lsty.Items.Remove(lsty.SelectedItem)
    End Sub

  
    Private Sub StandardErrorOfEstimationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StandardErrorOfEstimationToolStripMenuItem.Click
        Me.AllResultsToolStripMenuItem.PerformClick()
        Scattercover.Visible = True

        If lstx.Items.Count = 0 Then
            lblResult.Text = String.Empty
        Else

            lblResult.Text = "The Standard Error of Estimation = " & Math.Round(standarderror, 2)
        End If
    End Sub
End Class


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Brief Description
Looking at the last screen shot, i included the name(s) of some control(s)/tool  for easy understanding of the program. Some of these contol(s) include
  • txtXValue: - text box for entering values of x
  • cmdAddX: - click on this button to add ‘x’ value(s) into list box x and vice-versa
  • cmdRemoveX: - use this button to remove values entered beginning from the last value
  • lblResult: - displays all results which include “the mean of both x and y”, “the regression line”, “the standard error of estimation” and “pearsons coefficient of correlation”
  • lstX: - shows all values of x entered
  • lstY: - shows all values of Y entered
  • lstXX: - shows the multiplication of each x value
  • lstXY: - shows the multiplication of each x and y value
  • lstYY: - shows the multiplication of each y value
  • ScatterPlot: - a plot of the observed bivariate outcome variable (y axis) against it predictor variable (x axis), with a dot for each pair of bivariate observations.
View the menu item(s) used in the design of this application











       Sample video on this application 

~~need the executable file (software) feel free to reach me

Saturday, November 9, 2013

Java SE 7 Programmer I & II Exam Topics

Are you preparing to sit for either "Oracle certified associate Java Programmer OR Oracle certified professional Java Programmer Exams"? then, trust me, cos, you would want to make sure you cover/deal with every topic listed below.

Oracle Certified Associate Java Programmer I
Java Basics
  • Define the scope of variables
  • Define the structure of a Java class
  • Create executable Java applications with a main method
  • Import other Java packages to make them accessible in your code
Working With Java Data Types
  • Declare and initialize variables
  • Differentiate between object reference variables and primitive variables
  • Read or write to object fields
  • Explain an Object's Lifecycle (creation, "dereference" and garbage collection)
  • Call methods on objects
  • Manipulate data using the StringBuilder class and its methods
  • Creating and manipulating Strings
Using Operators and Decision Constructs  
  • Use Java operators
  • Use parenthesis to override operator precedence
  • Test equality between Strings and other objects using == and equals ()
  • Create if and if/else constructs
  • Use a switch statement
Creating and Using Arrays
  • Declare, instantiate, initialize and use a one-dimensional array
  • Declare, instantiate, initialize and use multi-dimensional array
  • Declare and use an ArrayList
Using Loop Constructs
  • Create and use while loops
  • Create and use for loops including the enhanced for loop
  • Create and use do/while loops
  • Compare loop constructs
  • Use break and continue  
Working with Methods and Encapsulation
  • Create methods with arguments and return values
  • Apply the static keyword  to methods and fields  
  • Create an overloaded method
  • Differentiate between default and user defined constructors
  • Create and overload constructors
  • Apply access modifiers
  • Apply encapsulation principles to a class
  • Determine the effect upon object references and primitive values when they are passed  into methods that change the values
Working with Inheritance
  • Implement inheritance
  • Develop code that demonstrates the use of polymorphism
  • Differentiate between the type of a reference and the type of an object
  • Determine when casting is necessary
  • Use super and this to access objects and constructors
  • Use abstract classes and interfaces
Handling Exceptions
  • Differentiate among checked exceptions, RuntimeExceptions and Errors
  • Create a try-catch block and determine how exceptions alter normal program flow
  • Describe what Exceptions are used for in Java
  • Invoke a method that throws an exception
  • Recognize common exception classes and categories


Oracle Certified Professional Java Programmer II

Java Class Design 
  • Use access modifiers: private, protected, and public
  • Override methods 
  • Overload constructors and methods 
  • Use the instanceof operator and casting
  • Use virtual method invocation
  • Override the hashCode, equals, and toString methods from the Object class to improve the functionality of your class. 
  • Use package and import statements
Advanced Class Design 
  • Identify when and how to apply abstract classes
  • Construct abstract Java classes and subclasses
  • Use the static and final keywords
  • Create top-level and nested classes
  • Use enumerated types
Object-Oriented Design Principles 
  • Write code that declares, implements and/or extends interfaces
  • Choose between interface inheritance and class inheritance
  • Apply cohesion, low-coupling, IS-A, and HAS-A principles
  • Apply object composition principles (including has-a relationships)
  • Design a class using a Singleton design pattern
  • Write code to implement the Data Access Object (DAO) pattern
  • Design and create objects using a factory pattern
Generics and Collections
  • Create a generic class
  • Use the diamond for type inference  
  • Analyze the interoperability of collections that use raw types and generic types 
  • Use wrapper classes, autoboxing and unboxing
  • Create and use List, Set and Deque implementations
  • Create and use Map implementations
  • Use java.util.Comparator and java.lang.Comparable
  • Sort and search arrays and lists
String Processing 
  • Search, parse and build strings (including Scanner, StringTokenizer, StringBuilder, String and Formatter)
  • Search, parse, and replace strings by using regular expressions, using expression patterns for matching limited to: . (dot), * (star), + (plus), ?, \d, \D, \s, \S,  \w, \W, \b. \B, [], ().
  • Format strings using the formatting parameters: %b, %c, %d, %f, and %s in format strings.
Exceptions and Assertions 
  • Use throw and throws statements 
  • Develop code that handles multiple Exception types in a single catch block
  • Develop code that uses try-with-resources statements (including using classes that implement the AutoCloseable interface)
  • Create custom exceptions
  • Test invariants by using assertions
Java I/O Fundamentals 
  • Read and write data from the console
  • Use streams to read from and write to files by using classes in the java.io package including BufferedReader, BufferedWriter, File, FileReader, FileWriter, DataInputStream, DataOutputStream, ObjectOutputStream, ObjectInputStream, and PrintWriter
Java File I/O (NIO.2) 
  • Operate on file and directory paths with the Path class 
  • Check, delete, copy, or move a file or directory with the Files class  
  • Read and change file and directory attributes, focusing on the BasicFileAttributes, DosFileAttributes, and PosixFileAttributes interfaces
  • Recursively access a directory tree using the DirectoryStream and FileVisitor interfaces
  • Find a file with the PathMatcher interface
  • Watch a directory for changes with the WatchService interface
Building Database Applications with JDBC 
  • Describe the interfaces that make up the core of the JDBC API (including the Driver, Connection, Statement, and ResultSet interfaces and their relationship to provider implementations)
  • Identify the components required to connect to a database using the DriverManager class (including the jdbc URL)
  • Submit queries and read results from the database (including creating statements, returning result sets, iterating through the results, and properly closing result sets, statements, and connections)
  • Use JDBC transactions (including disabling auto-commit mode, committing and rolling back transactions, and setting and rolling back to savepoints)
  • Construct and use RowSet objects using the RowSetProvider class and the RowSetFactory interface
  • Create and use PreparedStatement and CallableStatement objects
Threads 
  • Create and use the Thread class and the Runnable interface
  • Manage and control thread lifecycle
  • Synchronize thread access to shared data
  • Identify code that may not execute correctly in a multi-threaded environment.
Concurrency 
  • Use collections from the java.util.concurrent package with a focus on the advantages over and differences from the traditional java.util collections.
  • Use Lock, ReadWriteLock, and ReentrantLock classes in the java.util.concurrent.locks package to support lock-free thread-safe programming on single variables.
  • Use Executor, ExecutorService, Executors, Callable, and Future to execute tasks using thread pools.
  • Use the parallel Fork/Join Framework
Localization 
  • Read and set the locale by using the Locale object
  • Build a resource bundle for each locale
  • Call a resource bundle from an application
  • Format dates, numbers, and currency values for localization with the NumberFormat and DateFormat classes (including number format patterns)
  • Describe the advantages of localizing an application
  • Define a locale using language and country codes

...Best of luck as you sit for your exam