Statsar Statistics Library

v1.0.1 for .NET

Product Guide



More Information...

Valid XHTML


Two Way Repeated ANOVA Demo Example (VB.NET)

[VB.NET]
' COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
' All rights reserved.
'
' Use of this copyright notice is precautionary only, and does not imply
' publication or disclosure. The content of this work contains confidential
' and proprietary information of Simplexar Software Limited. Any duplication,
' modification, distribution, or disclosure in any form, in whole, or in part,
' is strictly prohibited without express prior written permission.

' Get namespaces.
Imports System
Imports Simplexar.Statsar
Imports Simplexar.Statsar.Anova

' Start namespace.
Namespace Simplexar.Examples.Statsar

    ' This example illustrates how to perform a two way repeated
    ' analysis of variance by using the TwoWayRepeatedAnova class
    ' from the Statsar.Simplexar.Anova namespace.
    Module Example

        ' The application entry point.
        Public Sub Main()
            Try
                RunExample()
            Catch exception As Exception
                Console.WriteLine(exception)
            End Try
            Console.WriteLine("Press ENTER to terminate.")
            Console.ReadLine()
        End Sub

        Private Sub RunExample()

            ' Create sheet.
            Dim calculator As New StatsCalculator()
            Dim sheet As DataSheet = calculator.Sheet
            Dim columns As ColumnList = sheet.Columns
            columns.Add("Store", GetType(Integer))
            columns.Add("Color", GetType(String))
            columns.Add("Shape", GetType(String))
            columns.Add("Sales", GetType(Double))

            ' Populate data.
            Dim rows As RowList = sheet.Rows
            rows.Add(1, "Blue", "Square", 6)
            rows.Add(2, "Blue", "Square", 14)
            rows.Add(3, "Blue", "Rectangle", 19)
            rows.Add(4, "Blue", "Rectangle", 17)
            rows.Add(5, "Red", "Square", 18)
            rows.Add(6, "Red", "Square", 11)
            rows.Add(7, "Red", "Rectangle", 20)
            rows.Add(8, "Red", "Rectangle", 23)
            rows.Add(9, "Green", "Square", 7)
            rows.Add(10, "Green", "Square", 11)
            rows.Add(11, "Green", "Rectangle", 18)
            rows.Add(12, "Green", "Rectangle", 10)
            Console.WriteLine(sheet)

            ' Perform analysis of variance.
            ' Factor A is stored in the "Color" column.
            ' Factor B is stored in the "Shape" column.
            ' Observations are stored in the "Sales" column.
            Dim anova As New TwoWayRepeatedAnova( _
                sheet, "Color", "Shape", "Sales")

            ' Access ANOVA table. This holds the results.
            Dim anovaTable As TwoWayRepeatedAnovaTable = anova.AnovaTable
            Console.WriteLine(anovaTable)

            ' Access individual ANOVA properties.
            Console.WriteLine( _
                "Factor A sum of squares: {0}", _
                anovaTable.SumOfSquareFactorA)

            Console.WriteLine( _
                "Factor B sum of squares: {0}", _
                anovaTable.SumOfSquareFactorB)

            Console.WriteLine( _
                "Subjects sum of squares: {0}", _
                anovaTable.SumOfSquareSubjects)

            Console.WriteLine( _
                "Interaction sum of squares: {0}", _
                anovaTable.SumOfSquareInteraction)

            Console.WriteLine( _
                "Error sum of squares: {0}", _
                anovaTable.SumOfSquareError)

            Console.WriteLine( _
                "Total sum of squares: {0}", _
                anovaTable.SumOfSquareTotal)

            Console.WriteLine( _
                "Factor A degrees of freedom: {0}", _
                anovaTable.DegreesOfFreedomFactorA)

            Console.WriteLine( _
                "Factor B degrees of freedom: {0}", _
                anovaTable.DegreesOfFreedomFactorB)

            Console.WriteLine( _
                "Subjects degrees of freedom: {0}", _
                anovaTable.DegreesOfFreedomSubjects)

            Console.WriteLine( _
                "Interaction degrees of freedom: {0}", _
                anovaTable.DegreesOfFreedomInteraction)

            Console.WriteLine( _
                "Error degrees of freedom: {0}", _
                anovaTable.DegreesOfFreedomError)

            Console.WriteLine( _
                "Total degrees of freedom: {0}", _
                anovaTable.DegreesOfFreedomTotal)

            Console.WriteLine( _
                "Factor A mean square: {0}", _
                anovaTable.MeanSquareFactorA)

            Console.WriteLine( _
                "Factor B mean square: {0}", _
                anovaTable.MeanSquareFactorB)

            Console.WriteLine( _
                "Subjects mean square: {0}", _
                anovaTable.MeanSquareSubjects)

            Console.WriteLine( _
                "Interaction mean square: {0}", _
                anovaTable.MeanSquareInteraction)

            Console.WriteLine( _
                "Error mean square: {0}", _
                anovaTable.MeanSquareError)

            Console.WriteLine( _
                "Total mean square: {0}", _
                anovaTable.MeanSquareTotal)

            Console.WriteLine( _
                "Factor A F-statistic: {0}", _
                anovaTable.FStatisticFactorA)

            Console.WriteLine( _
                "Factor B F-statistic: {0}", _
                anovaTable.FStatisticFactorB)

            Console.WriteLine( _
                "Interaction F-statistic: {0}", _
                anovaTable.FStatisticInteraction)

            Console.WriteLine( _
                "Factor A p-value: {0}", _
                anovaTable.PValueFactorA)

            Console.WriteLine( _
                "Factor B p-value: {0}", _
                anovaTable.PValueFactorB)

            Console.WriteLine( _
                "Interaction p-value: {0}", _
                anovaTable.PValueInteraction)

        End Sub

    End Module

End Namespace