Example: ANOVA
This example computes a one-way analysis of variance for data discussed by Searle (1971, Table 5.1, pages 165-179). The responses are plant weights for 6 plants of 3 different types - 3 normal, 2 off-types, and 1 aberrant. The 3 normal plant weights are 101, 105, and 94. The 2 off-type plant weights are 84 and 88. The 1 aberrant plant weight is 32. Note in the results that for the group with only one response, the standard deviation is undefined and is set to NaN (not a number).
using System;
using Imsl.Stat;
using Imsl.Math;
public class ANOVAEx1
{
public static void Main(String[] args)
{
double[][] y = { new double[]{101, 105, 94},
new double[]{84, 88},
new double[]{32}};
ANOVA anova = new ANOVA(y);
double[] aov = anova.GetArray();
Console.Out.WriteLine
("Degrees Of Freedom For Model = " + aov[0]);
Console.Out.WriteLine
("Degrees Of Freedom For Error = " + aov[1]);
Console.Out.WriteLine
("Total (Corrected) Degrees Of Freedom = " + aov[2]);
Console.Out.WriteLine("Sum Of Squares For Model = " + aov[3]);
Console.Out.WriteLine("Sum Of Squares For Error = " + aov[4]);
Console.Out.WriteLine
("Total (Corrected) Sum Of Squares = " + aov[5]);
Console.Out.WriteLine("Model Mean Square = " + aov[6]);
Console.Out.WriteLine("Error Mean Square = " + aov[7]);
Console.Out.WriteLine("F statistic = " + aov[8]);
Console.Out.WriteLine("P value= " + aov[9]);
Console.Out.WriteLine("R Squared (in percent) = " + aov[10]);
Console.Out.WriteLine
("Adjusted R Squared (in percent) = " + aov[11]);
Console.Out.WriteLine
("Model Error Standard deviation = " + aov[12]);
Console.Out.WriteLine("Mean Of Y = " + aov[13]);
Console.Out.WriteLine
("Coefficient Of Variation (in percent) = " + aov[14]);
Console.Out.WriteLine
("Total number of missing values = " + anova.TotalMissing);
PrintMatrixFormat pmf = new PrintMatrixFormat();
String[] labels =
new String[]{"Group", "N", "Mean", "Std. Deviation"};
pmf.SetColumnLabels(labels);
pmf.NumberFormat = null;
new PrintMatrix("Group Information").Print(pmf,
(Object)anova.GetGroupInformation());
}
}
Output
Degrees Of Freedom For Model = 2
Degrees Of Freedom For Error = 3
Total (Corrected) Degrees Of Freedom = 5
Sum Of Squares For Model = 3480
Sum Of Squares For Error = 70
Total (Corrected) Sum Of Squares = 3550
Model Mean Square = 1740
Error Mean Square = 23.3333333333333
F statistic = 74.5714285714286
P value= 0.00276888252534978
R Squared (in percent) = 98.0281690140845
Adjusted R Squared (in percent) = 96.7136150234742
Model Error Standard deviation = 4.83045891539648
Mean Of Y = 84
Coefficient Of Variation (in percent) = 5.75054632785295
Total number of missing values = 0
Group Information
Group N Mean Std. Deviation
0 0 3 100 5.56776436283002
1 1 2 86 2.82842712474619
2 2 1 32 NaN
Link to C# source.