Example 1: NormTwoSample

This example taken from Conover and Iman(1983, p294), involves scores on arithmetic tests of two grade-school classes.

Scores for Standard Group Scores for Experimental Group
72 111
75 118
77 128
80 138
104 140
110 150
125 163
164
169

The question is whether a group taught by an experimental method has a higher mean score. The difference in means and the t test are ouput. The variances of the two populations are assumed to be equal. It is seen from the output that there is strong reason to believe that the two means are different (t value of -4.804). Since the lower 97.5-percent confidence limit does not include 0, the null hypothesis is that \mu_1 \leq \mu_2 would be rejected at the 0.05 significance level. (The closeness of the values of the sample variances provides some qualitative substantiation of the assumption of equal variances.)

using System;
using Imsl.Stat;

public class NormTwoSampleEx1
{
    public static void  Main(String[] args)
    {
        double mean;
        double[] x1 = 
            new double[]{72.0, 75.0, 77.0, 80.0, 104.0, 110.0, 125.0};
        double[] x2 = 
            new double[]{   111.0, 118.0, 128.0, 138.0, 140.0,
                            150.0, 163.0, 164.0, 169.0};
        
        /* Perform Analysis for one sample x2*/
        NormTwoSample n2samp = new NormTwoSample(x1, x2);
        mean = n2samp.DiffMean;
        
        Console.Out.WriteLine("x1mean-x2mean  = " + mean);
        Console.Out.WriteLine("X1 mean =" + n2samp.MeanX);
        Console.Out.WriteLine("X2 mean =" + n2samp.MeanY);
        
        double pVar = n2samp.PooledVariance;
        Console.Out.WriteLine("pooledVar = " + pVar);
        
        double loCI = n2samp.LowerCIDiff;
        double upCI = n2samp.UpperCIDiff;
        Console.Out.WriteLine
            ("95% CI for the mean is " + loCI + " " + upCI);
        
        loCI = n2samp.LowerCIDiff;
        upCI = n2samp.UpperCIDiff;
        Console.Out.WriteLine
            ("95% CI for the ueq mean is " + loCI + " " + upCI);
        
        Console.Out.WriteLine("T Test Results");
        double tDF = n2samp.TTestDF;
        double tT = n2samp.TTest;
        double tPval = n2samp.TTestP;
        Console.Out.WriteLine("T default = " + tDF);
        Console.Out.WriteLine("t = " + tT);
        Console.Out.WriteLine("p-value = " + tPval);
        
        double stdevX = n2samp.StdDevX;
        double stdevY = n2samp.StdDevY;
        Console.Out.WriteLine("stdev x1 =" + stdevX);
        Console.Out.WriteLine("stdev x2 =" + stdevY);
    }
}

Output

x1mean-x2mean  = -50.4761904761905
X1 mean =91.8571428571428
X2 mean =142.333333333333
pooledVar = 434.632653061224
95% CI for the mean is -73.0100196252951 -27.9423613270859
95% CI for the ueq mean is -73.0100196252951 -27.9423613270859
T Test Results
T default = 14
t = -4.80436150471634
p-value = 0.000280258365677279
stdev x1 =20.8760514420118
stdev x2 =20.8266655996585

Link to C# source.