One 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 199, 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.AnovaOneWayResult; public class AnovaOneWayExample { public static void main(String args[]) { String[] group = {"1","1","1","1","1","1", "2","2","2","2","2","2","2","2", "3","3","3","3","3"}; double[] time = {93,67,77,92,97,62, 136,120,115,104,115,121,102,130, 198,217,209,221,190}; // 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". **********************************************************************/ data.addPredictor(group, DataType.FACTOR); data.addResponse(time, DataType.QUANTITATIVE); try { AnovaOneWayResult result = data.modelAnovaOneWay(); if (result != null) { // Getting the model's parameter estiamtes and statistics. int dfCTotal = result.getDFTotal(); int dfModel = result.getDFModel(); int dfError = result.getDFError(); double rssTotal = result.getRSSTotal(); double rssModel = result.getRSSModel(); double rssError = result.getRSSError(); double mssModel = result.getMSSModel(); double mssError = result.getMSSError(); double fValue = result.getFValue(); String pValue = result.getPValue(); 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("rssTotal = " + rssTotal); System.out.println("rssModel = " + rssModel); System.out.println("rssError = " + rssError); 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 < residuals.length; i++) { System.out.println("residuals["+i+"] = " + residuals[i]); } } } catch (Exception e) { System.out.println(e); } } }
"-----
Translate this page: