Imports System Imports System.Collections Imports CenterSpace.NMath.Core Namespace CenterSpace.NMath.Examples.VisualBasic A .NET example in Visual Basic showing some of the advanced features of class OneWayRanova. Module AdvancedOneWayRanovaExample Sub Main() Construct a OneWayRanova using a DoubleMatrix for the data to be analyzed. Each row of the matrix holds the data for an individual subject while each column represents a treatment. Dim M As DoubleMatrix = New DoubleMatrix("10x4 [ 180 200 160 200 230 250 200 220 280 310 260 270 180 200 160 200 190 210 170 210 140 160 120 110 270 300 250 260 110 130 100 100 190 210 170 210 230 250 200 220 ]") Dim Ranova As OneWayRanova = New OneWayRanova(M) Print out the grand mean and mean for each subject. Console.WriteLine() Console.WriteLine("GrandMean = " & Ranova.GrandMean) Console.WriteLine() Dim SubjectMeans As DoubleVector = Ranova.SubjectMeans Dim I As Integer For I = 0 To SubjectMeans.Length - 1 Console.WriteLine("Subject " & I & " mean = " & SubjectMeans(I)) Next Console.WriteLine() Fetch the RANOVA table and use it to print out the information in a traditional RANOVA table. Dim RanovaTable As OneWayRanovaTable = Ranova.RanovaTable Console.WriteLine("Source: Within Subject") Console.WriteLine(" Sum of Squares = " & RanovaTable.SumOfSquaresWithinSubject.ToString("G7")) Console.WriteLine(" Degrees of Freedom = " & RanovaTable.DegreesOfFreedomWithinSubject) Console.WriteLine(" Mean Square = " & RanovaTable.MeanSquareWithinSubject.ToString("G7")) Console.WriteLine() Console.WriteLine("Source: Treatment") Console.WriteLine(" Sum of Squares = " & RanovaTable.SumOfSquaresTreatment.ToString("G7")) Console.WriteLine(" Degrees of Freedom = " & RanovaTable.DegreesOfFreedomTreatment.ToString("G7")) Console.WriteLine(" Mean Square = " & RanovaTable.MeanSquareTreatment.ToString("G7")) Console.WriteLine() Console.WriteLine("Source: Error") Console.WriteLine(" Sum of Squares = " & RanovaTable.SumOfSquaresError.ToString("G7")) Console.WriteLine(" Degrees of Freedom = " & RanovaTable.DegreesOfFreedomError.ToString("G7")) Console.WriteLine(" Mean Square = " & RanovaTable.MeanSquareError.ToString("G7")) Console.WriteLine() Console.WriteLine("Source: Total") Console.WriteLine(" Sum of Squares = " & RanovaTable.SumOfSquaresTotal.ToString("G7")) Console.WriteLine(" Degrees of Freedom = " & RanovaTable.DegreesOfFreedomTotal) Console.WriteLine(" Mean Square = " & RanovaTable.MeanSquareTotal.ToString("G7")) Console.WriteLine() Print out the F statistic for the test of the null hypothesis that there is no treatment effect. Dim F As Double = RanovaTable.FStatistic What is the critical value for F for alpha = 0.05? Dim Alpha As Double = 0.05 Dim CriticalValue As Double = Ranova.FStatisticCriticalValue(Alpha) Console.WriteLine("F = " & F) Console.WriteLine() Console.WriteLine("Critical value for alpha < " & Alpha & " = " & CriticalValue.ToString("G7")) Console.WriteLine() Based on the value of F and the critical value decide whether or not to reject the null hypothesis. If (F > CriticalValue) Then Console.WriteLine("Reject the null hypothesis of no treatment effect and") Console.WriteLine("conclude that at least one treatment produces a different") Console.WriteLine("result " & Alpha & " significance level.") Else Console.WriteLine("Accept the null hypothesis of no treatment effect ") Console.WriteLine("at the " & Alpha & " significance level.") End If Console.WriteLine() Console.WriteLine() Console.WriteLine("Press Enter Key") Console.Read() End Sub End Module End Namespace← All NMath Code Examples