# Two Way ANOVA

/*

July 2006. Annie Che <chea@stat.ucla.edu>. UCLA Statistics.

Source of example data: An Introduction to Computational Statitics by Robert I Jennrich,
Page 207, example of regression on time for coins to reach bottom of fountains.

*/
package edu.ucla.stat.SOCR.analyses.example;

import java.util.HashMap;
import edu.ucla.stat.SOCR.analyses.data.Data;
import edu.ucla.stat.SOCR.analyses.data.DataType;
import edu.ucla.stat.SOCR.analyses.result.AnovaTwoWayResult;

public class AnovaTwoWayExample {
public static void main(String args[]) {
String[] group1 = {"1","1","1","2","2","2"};
String[] group2 = {"1","2","3","1","2","3"};
double[] score = {93,136,198,88,148,279};

// you'll need to instantiate a data instance first.
Data data = new Data();

/*********************************************************************
then put the data into the Data Object.
append the predictor data using method "addPredictor".
append the response data using method "addResponse".
**********************************************************************/

try {
AnovaTwoWayResult result = data.modelAnovaTwoWay();
System.out.println("result = " + result);
if (result != null) {

// Getting the model's parameter estiamtes and statistics.
int dfCTotal = result.getDFTotal();
int dfModel = result.getDFModel();
int dfError = result.getDFError();
System.out.println("dfCTotal = " + dfCTotal);
System.out.println("dfModel = " + dfModel);
System.out.println("dfError = " + dfError);

double mssModel = result.getMSSModel();
double mssError = result.getMSSError();

System.out.println("mssModel = " + mssModel);
System.out.println("mssError = " + mssError);

double fValue = result.getFValue();
String pValue = result.getPValue();
System.out.println("fValue = " + fValue);
System.out.println("pValue = " + pValue);

String[] varList = result.getVariableList();
int[] dfGroup = result.getDFGroup();
double[] mseGourp = result.getMSEGroup();
double[] fValueGroup = result.getFValueGroup();
String[] pValueGroup = result.getPValueGroup();
double[] residuals = result.getResiduals();
double[] predicted = result.getPredicted();

// residuals after being sorted ascendantly.
double[] sortedResiduals = result.getSortedResiduals();

// sortedResiduals after being standardized.
double[] sortedStandardizedResiduals =
result.getSortedStandardizedResiduals();

// the original index of sortedResiduals, stored as integer array.
int[] sortedResidualsIndex = result.getSortedResidualsIndex();

// the normal quantiles of sortedResiduals.
double[] sortedNormalQuantiles = result.getSortedNormalQuantiles();

// sortedNormalQuantiles after being standardized.
double[] sortedStandardizedNormalQuantiles =
result.getSortedStandardizedNormalQuantiles();

System.out.println("dfCTotal = " + dfCTotal);
System.out.println("dfModel = " + dfModel);
System.out.println("dfError = " + dfError);

System.out.println("mssModel = " + mssModel);
System.out.println("mssError = " + mssError);

System.out.println("fValue = " + fValue);
System.out.println("pValue = " + pValue);

for (int i = 0; i < varList.length; i++) {
System.out.println("varList["+i+"] = " + varList[i]);
}
for (int i = 0; i < residuals.length; i++) {
System.out.println("residuals["+i+"] = " + residuals[i]);
}

}
} catch (Exception e) {
System.out.println(e);
}
}
}