[TOC]
Imports System
Imports System.Collections
Imports CenterSpace.NMath.Core
Imports CenterSpace.NMath.Stats
Namespace CenterSpace.NMath.Stats.Examples.VisualBasic
' A .NET example in VB.NET showing some of the advanced features of class OneWayAnova.
Module AdvancedOneWayAnovaExample
Sub Main()
' Name of the file containing the data on which we will operate.
Dim Filename As String = "..\\..\\AdvancedOneWayAnovaExample.dat"
' Construct a DataFrame from the data in the file. The file contains
' data for three goups of people, healty people, melancholic depressed
' people, and nonmelancholic depressed people. For each of these
' groups the cortisol levels in the blood are measured*
' The data consists of two columns. The first column contains the name
' of the group that an individual belongs to and the second column
' contains the level of cortisol for the individual.
Dim AnovaData As DataFrame = DataFrame.Load(Filename, False, False, " ", True)
' The names of the three groups in the study.
Dim Healthy As String = "Healthy"
Dim NonMelancholic As String = "Nonmelanchonic"
Dim Melancholic As String = "Melancholic"
' Construct a OneWayAnova instance from the DataFrame. The first
' integer argument specifies which column contains the group names
' and the second integer argument specifies which column contains
' the numeric data (as zero based indicies).
Dim Anova As OneWayAnova = New OneWayAnova(AnovaData, 0, 1)
' Print out the means for each of the three groups.
Dim HealthGroupMean As Double = Anova.GetGroupMean(Healthy)
Dim NonMelancholicGroupMean As Double = Anova.GetGroupMean(NonMelancholic)
Dim MelancholicGroupMean As Double = Anova.GetGroupMean(Melancholic)
Console.WriteLine()
Console.WriteLine("Healthy group mean = " & HealthGroupMean)
Console.WriteLine("NonMelancholic group mean = " & NonMelancholicGroupMean)
Console.WriteLine("Melancholic group mean = " & MelancholicGroupMean)
' Print out the sum of squares, degrees of freedom and mean square
' for each of the source between groups, within groups, and total.
Console.WriteLine()
Console.WriteLine("Between Groups:")
Console.WriteLine(" Sum of Squares = " & Anova.AnovaTable.SumOfSquaresBetween)
Console.WriteLine(" Degrees of Freedom = " & Anova.AnovaTable.DegreesOfFreedomBetween)
Console.WriteLine(" Mean Square = " & Anova.AnovaTable.MeanSquareBetween)
Console.WriteLine()
Console.WriteLine("Within Groups:")
Console.WriteLine(" Sum of Squares = " & Anova.AnovaTable.SumOfSquaresWithin)
Console.WriteLine(" Degrees of Freedom = " & Anova.AnovaTable.DegreesOfFreedomWithin)
Console.WriteLine(" Mean Square = " & Anova.AnovaTable.MeanSquareWithin)
Console.WriteLine()
Console.WriteLine("Total:")
Console.WriteLine(" Sum of Squares = " & Anova.AnovaTable.SumOfSquaresTotal)
Console.WriteLine(" Degrees of Freedom = " & Anova.AnovaTable.DegreesOfFreedomTotal)
Console.WriteLine(" Mean Square = " & Anova.AnovaTable.MeanSquareTotal)
Console.WriteLine()
' Fetch the F statistic and the critical value for the F statistic and
' decide whether or not to reject the null hypothesis that all group
' means are the same.
Dim F As Double = Anova.AnovaTable.FStatistic
Dim Alpha As Double = 0.01
Dim CriticalValue As Double = Anova.FStatisticCriticalValue(Alpha)
Console.Write("F = ")
Console.WriteLine(F)
Console.WriteLine()
Console.WriteLine("Critical value for alpha < " & Alpha & " = " & CriticalValue)
Console.WriteLine()
If (F > CriticalValue) Then
Console.WriteLine("Reject the null hypothesis that the means are the ")
Console.WriteLine("same in all three groups at the " & Alpha & " significance level.")
Else
Console.WriteLine("Accept the null hypothesis that the means are the ")
Console.WriteLine("same in all three groups at the " & Alpha & " significance level.")
End If
Console.WriteLine()
Console.WriteLine("Press Enter Key")
Console.Read()
End Sub
End Module
End Namespace
' * Source: L. H. Price, D. S. Charney, A. L. Rubin, and F. R.
' Henniger, "alpha2 Adregenric Receptor Function in Depression:
' The Cortisol Response to Yohimbine," Arch. Gen. Psychiatry
' 43:849-858, 1986.
[TOC]