Example 1: NormOneSample

This example uses data from Devore (1982, p335), which is based on data published in the Journal of Materials . There are 15 observations. The hypothesis H0: \mu = 20.0 is tested. The extremely large t value and the correspondingly small p -value provide strong evidence to reject the null hypothesis.

using System;
using Imsl.Stat;

public class NormOneSampleEx1
{
	public static void  Main(String[] args)
	{
		
		double mean, stdev, lomean, upmean;
		int df;
		double t, pvalue;
		double[] x = new double[]{   26.7, 25.8, 24.0, 24.9, 26.4, 
									 25.9, 24.4, 21.7, 24.1, 25.9,
									 27.3, 26.9, 27.3, 24.8, 23.6};
		
		/* Perform Analysis*/
		
		NormOneSample n1samp = new NormOneSample(x);
		
		mean = n1samp.Mean;
		stdev = n1samp.StdDev;
		lomean = n1samp.LowerCIMean;
		upmean = n1samp.UpperCIMean;
		n1samp.TTestNull = 20.0;
		df = n1samp.TTestDF;
		t = n1samp.TTest;
		pvalue = n1samp.TTestP;
		
		
		/* Print results */
		
		Console.Out.WriteLine("Sample Mean = " + mean);
		Console.Out.WriteLine("Sample Standard Deviation = " + stdev);
		Console.Out.WriteLine
			("95% CI for the mean is " + lomean + "   " + upmean);
		Console.Out.WriteLine("T Test results");
		Console.Out.WriteLine("df = " + df);
		Console.Out.WriteLine("t = " + t);
		Console.Out.WriteLine("pvalue = " + pvalue);
		Console.Out.WriteLine("");
		
		/* CI variance */
		double ciLoVar = n1samp.LowerCIVariance;
		double ciUpVar = n1samp.UpperCIVariance;
		Console.Out.WriteLine
			("CI variance is " + ciLoVar + "    " + ciUpVar);
		/*chi-squared test */
		df = n1samp.ChiSquaredTestDF;
		t = n1samp.ChiSquaredTest;
		pvalue = n1samp.ChiSquaredTestP;
		Console.Out.WriteLine("Chi-squared Test results");
		Console.Out.WriteLine("Chi-squared df = " + df);
		Console.Out.WriteLine("Chi-squared t = " + t);
		Console.Out.WriteLine("Chi-squared pvalue = " + pvalue);
	}
}

Output

Sample Mean = 25.3133333333333
Sample Standard Deviation = 1.57881812336528
95% CI for the mean is 24.4390129997097   26.187653666957
T Test results
df = 14
t = 13.0340861992294
pvalue = 3.21471738118362E-09

CI variance is 1.33609260499922    6.19986346723949
Chi-squared Test results
Chi-squared df = 14
Chi-squared t = 34.8973333333333
Chi-squared pvalue = 0.0015223176141822

Link to C# source.