Two Paired Sample T-Test

From Socr

Revision as of 21:03, 31 July 2006 by Annie (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/*

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


Source of example data: 
Mathematical Statistics and Data Analysis, John Rice, Second Edition. 
Page 412, example A, effect of cigarette smoking on platelet aggregation.

*/
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.result.TwoPairedTResult;


public class TwoPairedTExample {
	public static void main(String args[]) {
		double[] before = {25, 25, 27, 44, 30, 67, 53, 53, 52, 60, 28};
		double[] after = {27, 29, 37, 56, 46, 82, 57, 80, 61, 59, 43};

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

		// then use the following line to get the result.
		try {
			TwoPairedTResult result = 
                        (TwoPairedTResult) data.modelTwoPairedT(before, after);
			// modelTwoPairedT: order of first and second argumentd does NOT matter.


			if (result != null) {

				// Getting the model's parameter estiamtes and statistics.
				double meanX = result.getMeanX();
				double meanY = result.getMeanY();

				// sum of variance of x and variance of y.
				double sampleVar = result.getSampleVariance();

				int degreesFreedome = result.getDF();
				double tStat = result.getTStat();
				String pValue = result.getPValue();

				System.out.println("meanX = " + meanX);
				System.out.println("meanY = " + meanY);
				System.out.println("sampleVar = " + sampleVar);
				System.out.println("degreesFreedome = " + degreesFreedome);
				System.out.println("tStat = " + tStat);
				System.out.println("pValue = " + pValue);


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