One Way ANOVA Demo Example (C#)
[C#]
/* 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.
using System;
using Simplexar.Statsar;
using Simplexar.Statsar.Anova;
// Start namespace.
namespace Simplexar.Examples.Statsar
{
/// <summary>
/// This example illustrates how to perform a one way
/// analysis of variance by using the OneWayAnova class
/// from the Statsar.Simplexar.Anova namespace.
/// </summary>
public static class Example
{
/// <summary>
/// The application entry point.
/// </summary>
public static void Main()
{
try
{
RunExample();
}
catch(Exception exception)
{
Console.WriteLine(exception);
}
Console.WriteLine("Press ENTER to terminate.");
Console.ReadLine();
}
private static void RunExample()
{
// Create sheet.
StatsCalculator calculator = new StatsCalculator();
DataSheet sheet = calculator.Sheet;
ColumnList columns = sheet.Columns;
columns.Add("Level1", typeof(double));
columns.Add("Level2", typeof(double));
columns.Add("Level3", typeof(double));
// Populate data.
RowList rows = sheet.Rows;
rows.Add(6.9, 8.3, 8.0);
rows.Add(5.4, 6.8, 10.5);
rows.Add(5.8, 7.8, 8.1);
rows.Add(4.6, 9.2, 6.9);
rows.Add(4.0, 6.5, 9.3);
Console.WriteLine(sheet);
// Perform analysis of variance.
OneWayAnova anova = new OneWayAnova(sheet);
// Access ANOVA table. This holds the results.
OneWayAnovaTable anovaTable = anova.AnovaTable;
Console.WriteLine(anovaTable);
// Access individual ANOVA properties.
Console.WriteLine(
"Treatments sum of squares: {0}",
anovaTable.SumOfSquareTreatments);
Console.WriteLine(
"Error sum of squares: {0}",
anovaTable.SumOfSquareError);
Console.WriteLine(
"Total sum of squares: {0}",
anovaTable.SumOfSquareTotal);
Console.WriteLine(
"Treatments degrees of freedom: {0}",
anovaTable.DegreesOfFreedomTreatments);
Console.WriteLine(
"Error degrees of freedom: {0}",
anovaTable.DegreesOfFreedomError);
Console.WriteLine(
"Total degrees of freedom: {0}",
anovaTable.DegreesOfFreedomTotal);
Console.WriteLine(
"Treatments mean square: {0}",
anovaTable.MeanSquareTreatments);
Console.WriteLine(
"Error mean square: {0}",
anovaTable.MeanSquareError);
Console.WriteLine(
"Total mean square: {0}",
anovaTable.MeanSquareTotal);
Console.WriteLine(
"F-statistic: {0}",
anovaTable.FStatistic);
Console.WriteLine(
"P-value: {0}",
anovaTable.PValue);
}
}
}