Extreme Optimization > User's Guide > Statistics Library > Analysis of Variance > One-way ANOVA

Extreme Optimization User's Guide

User's Guide

Up: Analysis of Variance Next: One-way ANOVA with Repeated Measures Previous: ANOVA Models Contents

One Way ANOVA

The simplest ANOVA design considers one factor only. This is called one-way ANOVA. The one-way analysis of variance is implemented by the OneWayAnovaModel class.

Constructing One-Way ANOVA Models

The OneWayAnovaModel class has three constructors.

The first constructor takes two parameters: a NumericalVariable that specifies the dependent variable, and a CategoricalVariable that specifies the independent variable. The two variables must have the same number of observations.

As an example, we construct an ANOVA model for measurements of the resistance of silicon wafers using 5 different instruments. The factor is the instrument. The numerical value is the resistance.

C# CopyCode imageCopy Code
int[] instrumentData = 
     {1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5};
CategoricalVariable factor =    new CategoricalVariable("Instrument", instrumentData);
double[] resistanceData = {
    196.3052, 196.1240, 196.1890, 196.2569, 196.3403,
    196.3042, 196.3825, 196.1669, 196.3257, 196.0422,
    196.1303, 196.2005, 196.2889, 196.0343, 196.1811,
    196.2795, 196.1748, 196.1494, 196.1485, 195.9885,
    196.2119, 196.1051, 196.1850, 196.0052, 196.2090};
NumericalVariable dependent =    new NumericalVariable("Resistance", resistanceData);
OneWayAnovaModel anova1 =    new OneWayAnovaModel(dependent, factor);
Visual Basic CopyCode imageCopy Code
Dim instrumentData As Integer() = _
     {1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5}
Dim factor As CategoricalVariable = _
    New CategoricalVariable("Instrument", instrumentData)
Dim resistanceData As Double{} = { _
    196.3052, 196.1240, 196.1890, 196.2569, 196.3403, _
    196.3042, 196.3825, 196.1669, 196.3257, 196.0422, _
    196.1303, 196.2005, 196.2889, 196.0343, 196.1811, _
    196.2795, 196.1748, 196.1494, 196.1485, 195.9885, _
    196.2119, 196.1051, 196.1850, 196.0052, 196.2090}
Dim dependent As NumericalVariable = _
    New NumericalVariable("Resistance", resistanceData)
Dim anova1 As OneWayAnovaModel =    New OneWayAnovaModel(dependent, factor)

The second constructor takes three parameters. The first parameter is a VariableCollection that contains the variables you wish to use in the analysis. The second parameter is the name of the dependent variable in the collection. The third parameter is the name of the independent variable in the collection. Using the variables we created in the previous example, we get:

C# CopyCode imageCopy Code
VariableCollection variables = new VariableCollection();
variables.Add(dependent);
variables.Add(factor);
OneWayAnovaModel anova2 =    new OneWayAnovaModel(variables, "Resistance", class="str">"Instrument");
Visual Basic CopyCode imageCopy Code
Dim variables As VariableCollection = New VariableCollection()
variables.Add(dependent)
variables.Add(factor)
Dim anova2 As OneWayAnovaModel =    New OneWayAnovaModel(variables, "Resistance", class="str">"Instrument")

The third constructor also takes three parameters. The first parameter is a DataTable that contains the data for the analysis. The second parameter is the name of the column that contains the dependent variable data. The third parameter is the name of the column that contains the independent variable data.

C# CopyCode imageCopy Code
DataTable table = new DataTable();
// Fill the DataTable from some data source...
OneWayAnovaModel anova3 =    new OneWayAnovaModel(table, "Resistance", class="str">"Instrument");
Visual Basic CopyCode imageCopy Code
Dim table As DataTable = New DataTable()
' Fill the DataTable from some data source...
Dim anova3 As OneWayAnovaModel =    New OneWayAnovaModel(table, "Resistance", class="str">"Instrument")

All three examples produce the same ANOVA model.

Performing the analysis

The Compute method performs the actual analysis.

The results of the analysis can be obtained through the model's AnovaTable property. The ANOVA table for a one-way design has three rows. These are commonly labeled Between Groups, Within Groups, and Total.

The crucial data is provided by the Between Groups row, which shows the contribution to the total variation of the factor under consideration. It is the first row in the ANOVA table, and therefore has index 0. It can be retrieved through the GetModelRow method. Since the entire model of a one-way analysis of variance consists of the contribution of one factor, this property is also available as the CompleteModelRow property.

The AnovaModelRow obtained in this way shows the results of the test for significance of the variation due to the factor compared to the variation not explained by the factor. The FStatistic property gives the value of the F statistic for this ratio, while the PValue gives the actual significance of the F statistic.

The Within Groups row shows the variation of the data around the group means. It corresponds to the error or residual of the variation in the data after the model has been taken into account. The row is available through the ANOVA table's ErrorRow property.

The Total row contains the summary data for the entire data set. It can be retrieved through the TotalRow property of the ANOVA table.

The example below illustrates these properties:

C# CopyCode imageCopy Code
anova.Compute();
            
Console.WriteLine("F statistic: {0}", anova.AnovaTable.ModelRow.FStatistic);
Console.WriteLine("P-value     : {0}", anova.AnovaTable.ModelRow.PValue);
Console.WriteLine("Sum of sq. total: {0}",
    anova.AnovaTable.TotalRow.SumOfSquares);
Console.WriteLine("Sum of sq. error: {0}",
    anova.AnovaTable.ErrorRow.SumOfSquares);
Console.WriteLine("Sum of sq. model: {0}",
    anova.AnovaTable.ModelRow.SumOfSquares);
Console.WriteLine(anova.AnovaTable.ToString());
Visual Basic CopyCode imageCopy Code
anova.Compute();
            
Console.WriteLine("F statistic: {0}", anova.AnovaTable.ModelRow.FStatistic)
Console.WriteLine("P-value     : {0}", anova.AnovaTable.ModelRow.PValue)
Console.WriteLine("Sum of sq. total: {0}", _
    anova.AnovaTable.TotalRow.SumOfSquares)
Console.WriteLine("Sum of sq. error: {0}", _
    anova.AnovaTable.ErrorRow.SumOfSquares)
Console.WriteLine("Sum of sq. model: {0}", _
    anova.AnovaTable.ModelRow.SumOfSquares)
Console.WriteLine(anova.AnovaTable.ToString())

For the example using the silicon wafers, we find that the F statistic is 1.1804, corresponding to a p-value of ???.

The group means can be accessed through the model's Cells property. In the example below, we first obtain the CategoricalScale object corresponding to the factor. We then iterate through the levels of the scale, and print the group means:

C# CopyCode imageCopy Code
CategoricalScale instrumentFactor = anova.GetFactor(0);
foreach(object level in instrumentFactor.GetLevels())
    Console.WriteLine("Mean for group '{0}': {1:F4}",
        level, anova.Cells[level].Mean);
Visual Basic CopyCode imageCopy Code
CategoricalScale instrumentFactor = anova.GetFactor(0)
For Each level As Object In instrumentFactor.GetLevels()
    Console.WriteLine("Mean for group '{0}': {1:F4}", _
        level, anova.Cells[level].Mean)
Next

The grand mean can be obtained through the cell with index Cell.All:

C# CopyCode imageCopy Code
Console.WriteLine("Grand mean: {0:F4}", anova.Cells[Cell.All].Mean);
Visual Basic CopyCode imageCopy Code
Console.WriteLine("Grand mean: {0:F4}", anova.Cells[Cell.All].Mean)

Up: Analysis of Variance Next: One-way ANOVA with Repeated Measures Previous: ANOVA Models Contents

Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Information
Resources
Contact Us
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army