Two Way 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
' analysis of variance by using the TwoWayAnova 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("Labs", GetType(Integer))
columns.Add("Materials", GetType(Integer))
columns.Add("Coating", GetType(Double))
' Populate data.
Dim rows As RowList = sheet.Rows
rows.Add(1, 1, 4.1)
rows.Add(1, 1, 3.9)
rows.Add(1, 1, 4.3)
rows.Add(1, 2, 3.1)
rows.Add(1, 2, 2.8)
rows.Add(1, 2, 3.3)
rows.Add(1, 3, 3.5)
rows.Add(1, 3, 3.2)
rows.Add(1, 3, 3.6)
rows.Add(2, 1, 2.7)
rows.Add(2, 1, 3.1)
rows.Add(2, 1, 2.6)
rows.Add(2, 2, 1.9)
rows.Add(2, 2, 2.2)
rows.Add(2, 2, 2.3)
rows.Add(2, 3, 2.7)
rows.Add(2, 3, 2.3)
rows.Add(2, 3, 2.5)
Console.WriteLine(sheet)
' Perform analysis of variance.
' Factor A is stored in the "Labs" column.
' Factor B is stored in the "Materials" column.
' Observations are stored in the "Coating" column.
Dim anova As New TwoWayAnova( _
sheet, "Labs", "Materials", "Coating")
' Access ANOVA table. This holds the results.
Dim anovaTable As TwoWayAnovaTable = 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( _
"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( _
"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( _
"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