# NMath User's Guide

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

Class 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:

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.

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.

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.

Creating UnbalancedTwo-Way ANOVA Objects

Unbalanced two-way ANOVA instances are constructed in the same manner as balanced TwoWayAnova objects (Section 44.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 );
```

Code Example – VB Unbalanced ANOVA

```Dim Type1Anova As New TwoWayAnovaType(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 44.3). For instance, this code prints the ANOVA table.

Code Example – C# Unbalanced ANOVA

```Console.WriteLine( type1anova.AnovaTable );
```

Code Example – VB 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();
```
```}
```

Code Example – VB Unbalanced ANOVA

```Console.WriteLine("FACTOR A ANOVA --------")
```
```Dim FA As AnovaRegressionFactorParam() =
Type1Anova.FactorARegressionFactorParameters
```
```For I As Integer = 0 To FA.Length - 1
```
```  Console.WriteLine(FA(I))
```
```  Console.WriteLine()
```
```Next

```

```Console.WriteLine("\nFACTOR B ANOVA --------")
```
```Dim FB As AnovaRegressionFactorParam() =
Type1Anova.FactorBRegressionFactorParameters
```
```For I As Integer = 0 To FB.Length - 1
```
```  Console.WriteLine(FB(I))
```
```  Console.WriteLine()
```
```Next

```

```Console.WriteLine("\nINTERACTION FACTOR ANOVA --------")
```
```Dim FI As AnovaRegressionInteractionParam() =
Type2Anova.InteractionRegressionFactorParameters
```
```For I As Integer = 0 To FI.Length - 1
```
```  Console.WriteLine(FI(I))
```
```  Console.WriteLine()
```
```Next
```

Top

Top