NMath Stats User's Guide

TOC | Previous | Next | Index

8.4 Two-Way Unbalanced ANOVA (.NET, C#, CSharp, VB, Visual Basic, F#)

Class TwoWayAnovaUnbalanced is the base class for performing a two-way 
ANOVA when the number of observations in each cell is not the same—an 
unbalanced design. Three derived classes are provided:

TwoWayAnovaTypeI performs a Type I ANOVA on unbalanced data. Type I, also called sequential sum of squares, tests the main effect of factor A, followed by the main effect of factor B after the main effect of A, followed by the interaction effect AB after the main effects.

TwoWayAnovaTypeII performs a Type II ANOVA on unbalanced data. This type tests for each main effect after the other main effect. No significant interaction is assumed.

TwoWayAnovaTypeIII performs a Type III ANOVA on unbalanced data. This type tests for the presence of a main effect after the other main effect and interaction.

For more information on the different ways to calculate the sums of squares for ANOVA, see

http://goanna.cs.rmit.edu.au/~fscholer/anova.php

Creating UnbalancedTwo-Way ANOVA Objects

Unbalanced two-way ANOVA instances are constructed in the same manner as balanced TwoWayAnova objects (Section 8.3). For example, this code groups the numeric data in column 3 of DataFrame df by factors constructed from columns 0 and 1:

Code Example – C# Unbalanced ANOVA

var type1anova = new TwoWayAnovaTypeI( df, 0, 1, 2 );

Unbalanced Two-Way ANOVA Tables and Regression Parameters

Using an unbalanced two-way ANOVA object is similar to using a balanced TwoWayAnova object (Section 8.3). For instance, this code prints the ANOVA table.

Code Example – C# Unbalanced ANOVA

Console.WriteLine( type1anova.AnovaTable );

This code prints the regression parameters.

Code Example – C# Unbalanced ANOVA

Console.WriteLine( "FACTOR A ANOVA --------" );
var fa = type1anova.FactorARegressionFactorParameters;
for ( int i = 0; i < fa.Length; i++ )
{
  Console.WriteLine( fa[i] );
  Console.WriteLine();
}

Console.WriteLine( "\nFACTOR B ANOVA --------" );
var fb = type1anova.FactorBRegressionFactorParameters;
for ( int i = 0; i < fb.Length; i++ )
{
  Console.WriteLine( fb[i] );
  Console.WriteLine();
}

Console.WriteLine( "\nINTERACTION FACTOR ANOVA --------" );
var fi = type2anova.InteractionRegressionFactorParameters;
for ( int i = 0; i < fi.Length; i++ )
{
  Console.WriteLine( fi[i] );
  Console.WriteLine();
}

Top

Top