org.statcato.statistics.inferential
Class TwoWayANOVA

java.lang.Object
  extended by org.statcato.statistics.inferential.TwoWayANOVA

public class TwoWayANOVA
extends java.lang.Object

Two-way analysis of variance (two-factor ANOVA). Performs computations for two-way ANOVA given all the observations and their corresponding row and column indices.

Since:
1.0
Version:
%I%, %G%
Author:
Margaret Yau

Constructor Summary
TwoWayANOVA(int a, int b)
          Constructor, given the number of levels in factor A and B.
 
Method Summary
 void addObservation(int i, int j, double data)
          Adds the given data to row i and column j.
 double colSum(int j)
          Returns the column sum B_j = Sum_{i=1...a} {cell sum of y[i][j]}.
 int DOFA()
          Returns the degrees of freedom for factor A = a - 1.
 int DOFAB()
          Returns the degrees of freedom for interaction AB.
 int DOFB()
          Returns the degrees of freedom for factor B = b - 1.
 int DOFE()
          Returns the degrees of freedom for the error.
 int DOFTotal()
          Returns the total degrees of freedom.
 double FA()
          Returns the F test statistics for factor A.
 double FAB()
          Returns the F test statistics for interaction AB.
 double FB()
          Returns the F test statistics for factor B.
 void findCM()
          Computes the correction of the mean, (sum of all observations)^2 / N.
 boolean isValidData()
          Checks if the data is valid for two-way ANOVA.
 double MSA()
          Returns the mean of squares of factor A = SSA / DOFA.
 double MSAB()
          Returns the mean of squares of interaction AB = SSAB / DOFAB.
 double MSB()
          Returns the mean of squares of factor B = SSB / DOFB.
 double MSE()
          Returns the mean of squares of error = SSE / DOFE.
 double PValueA()
          Returns the p-Value corresponding to the F test statistic for factor A.
 double PValueAB()
          Returns the p-Value corresponding to the F test statistic for interaction AB.
 double PValueB()
          Returns the p-Value corresponding to the F test statistic for factor B.
 double rowSum(int i)
          Returns the row sum A_i = Sum_{j=1...b} {cell sum of y[i][j]}.
 double SSA()
          Returns the sum of squares for factor A, (Sum_{i=1..a} A_i^2) / (b*n) - CM.
 double SSAB()
          Returns the sum of squares for interaction AB, (Sum (cell sum)^2) / n - CM - SSA - SSB.
 double SSB()
          Returns the sum of squares for factor B, (Sum_{j=1..b} B_j^2) / (a*n) - CM.
 double SSE()
          Returns sum of squares of error, SSTotal - SSA - SSB - SSAB.
 double SSTotal()
          Returns the total sum of squares, Sum (observation)^2 - CM.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TwoWayANOVA

public TwoWayANOVA(int a,
                   int b)
Constructor, given the number of levels in factor A and B.

Parameters:
a - number of levels in factor A
b - number of levels in factor B
Method Detail

addObservation

public void addObservation(int i,
                           int j,
                           double data)
Adds the given data to row i and column j.

Parameters:
i - row index
j - column index
data - double array

isValidData

public boolean isValidData()
Checks if the data is valid for two-way ANOVA. Sets the treatment group size and the total sample size. Computes the correction of the mean (CM).

Returns:
boolean value of whether the data is valid

rowSum

public double rowSum(int i)
Returns the row sum A_i = Sum_{j=1...b} {cell sum of y[i][j]}.

Returns:
row sum

colSum

public double colSum(int j)
Returns the column sum B_j = Sum_{i=1...a} {cell sum of y[i][j]}.

Returns:
column sum

findCM

public void findCM()
Computes the correction of the mean, (sum of all observations)^2 / N. Should be called before calls to compute sum of squares.


SSA

public double SSA()
Returns the sum of squares for factor A, (Sum_{i=1..a} A_i^2) / (b*n) - CM.

Returns:
sum of squares for factor A

SSB

public double SSB()
Returns the sum of squares for factor B, (Sum_{j=1..b} B_j^2) / (a*n) - CM.

Returns:
sum of squares for factor B

SSAB

public double SSAB()
Returns the sum of squares for interaction AB, (Sum (cell sum)^2) / n - CM - SSA - SSB.

Returns:
sum of squares for interaction AB

SSTotal

public double SSTotal()
Returns the total sum of squares, Sum (observation)^2 - CM.

Returns:
total sum of squares

SSE

public double SSE()
Returns sum of squares of error, SSTotal - SSA - SSB - SSAB.

Returns:
sum of squares of error

MSA

public double MSA()
Returns the mean of squares of factor A = SSA / DOFA.

Returns:
mean of squares of factor A

MSB

public double MSB()
Returns the mean of squares of factor B = SSB / DOFB.

Returns:
mean of squares of factor B

MSAB

public double MSAB()
Returns the mean of squares of interaction AB = SSAB / DOFAB.

Returns:
mean of squares of interaction AB

MSE

public double MSE()
Returns the mean of squares of error = SSE / DOFE.

Returns:
mean of squares of error

DOFA

public int DOFA()
Returns the degrees of freedom for factor A = a - 1.

Returns:
degrees of freedom for A

DOFB

public int DOFB()
Returns the degrees of freedom for factor B = b - 1.

Returns:
degrees of freedom for B

DOFAB

public int DOFAB()
Returns the degrees of freedom for interaction AB.

Returns:
degrees of freedom for AB

DOFE

public int DOFE()
Returns the degrees of freedom for the error.

Returns:
degrees of freedom for error

DOFTotal

public int DOFTotal()
Returns the total degrees of freedom.

Returns:
total degrees of freedom

FA

public double FA()
Returns the F test statistics for factor A.

Returns:
F for factor A

FB

public double FB()
Returns the F test statistics for factor B.

Returns:
F for factor B

FAB

public double FAB()
Returns the F test statistics for interaction AB.

Returns:
F for interaction AB

PValueA

public double PValueA()
Returns the p-Value corresponding to the F test statistic for factor A.

Returns:
p-Value

PValueB

public double PValueB()
Returns the p-Value corresponding to the F test statistic for factor B.

Returns:
p-Value

PValueAB

public double PValueAB()
Returns the p-Value corresponding to the F test statistic for interaction AB.

Returns:
p-Value

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object