Hypothesis Tests

Daniel D. Warner
July 31, 1999

Z Tests

The Z Test provides a variety of different standardization-based tests. They make it possible to test whether

or not a sample accurately represents the population when the standard deviation of the population is

known from previous tests.

Z Test Preliminary Definitions

> Digits := 20;

[Maple Math]

> Ncd := (a,b,sigma,mu) -> (1/2)*(erf((b-mu)/(sigma*sqrt(2))) - erf((a-mu)/(sigma*sqrt(2))));

[Maple Math]

1-Sample Z Test

The 1-Sample Z Test tests the population mean when the standard deviation is known.

In the following xbar is the sample mean, [Maple Math] is the assumed population mean, [Maple Math] is the

standard deviation of the population, and n is the sample size.

Sample Data

Data from Casio Manual, Section 18-6, page 278.

> n[1] := 5; x[1] := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n[1]; sigma[1] := 3; mu[0] := 11.5;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Calculate z statistic

> z := (x[1] - mu[0])/(sigma[1]/sqrt(n[1])); evalf(z);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Ncd(-z,z,1,0);evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

2-Sample Z Test

The 2-Sample Z Test tests whether the population means of two populations are equal when the standard deviations

of the two populations are known.

In the following [Maple Math] and [Maple Math] are the two sample means,

[Maple Math] and [Maple Math] are the standard deviations of the two populations,

and [Maple Math] and [Maple Math] are the two sample sizes.

Sample Data

Data from Casio Manual, Section 18-6, page 280.

> n[1] := 5; x[1] := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n[1]; sigma[1] := 15.5;

[Maple Math]

[Maple Math]

[Maple Math]

> n[2] := 5; x[2] := (0.84 + 0.9 + 0.14 + (-0.75) + (-0.95))/n[2]; sigma[2] := 13.5;

[Maple Math]

[Maple Math]

[Maple Math]

Calculate z statistic

> z := (x[1] - x[2])/sqrt((sigma[1]^2/n[1]) + (sigma[2]^2/n[2])); evalf(z);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Ncd(-z,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1 - Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

1-Prop Z Test

The 1-Prop Z Test tests whether data that satisfies certain criteria reaaches a specific proportion

of the population given the sample size and the number of data satisfying the criteria.

In the following x is the number of data satisfying the criteria, [Maple Math] is the assumed population proportion,

and n is the sample size.

Sample Data

Sample Data is taken from Casio Manual, Section 18-6, page 281.

> n[1] := 4040; x[1] := 2048; p[0] := 0.5;

[Maple Math]

[Maple Math]

[Maple Math]

Calculate z statistic

> z := (x[1]/n[1] - p[0])/sqrt(p[0]*(1-p[0])/n[1]); evalf(z);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Ncd(-z,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

2-Prop Z Test

The 2-Prop Z Test is used to compare the proportions of two samples that satisfy certain criteria.

In the following [Maple Math] and [Maple Math] are the number of data in the two samples that satisfy the criteria,

and [Maple Math] and [Maple Math] are the two sample sizes.

Sample Data

Sample Data is taken from the Casio manual, Section 18-6, page 282.

> x[1] := 225; n[1] := 300; x[2] := 230; n[2] := 300;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the z statistic

> phat := (x[1]+x[2])/(n[1]+n[2]);
z := (x[1]/n[1] - x[2]/n[2])/sqrt(phat*(1-phat)*(1/n[1] + 1/n[2]));
evalf(z);

[Maple Math]

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Ncd(-abs(z),abs(z),1,0); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Ncd(-10^10,z,1,0); evalf(p);

[Maple Math]

[Maple Math]

t Tests

t Test Preliminary Definitions

> Digits := 20; z := 'z';

[Maple Math]

[Maple Math]

> Tcd := (a,b,df) -> evalf((GAMMA((df+1)/2)/(GAMMA(df/2)*sqrt(Pi*df)))*int(exp((-(df+1)/2)*log(1+z^2/df)),z=a..b));

[Maple Math]

1-Sample t Test

The 1-Sample t Test uses the sample size and population mean to test the hypothesis that
the sample is taken from the population.

Sample Data

This Sample Data is taken from the Casio Manual, Section 18-6, page 284.

> n[1] := 5; x[1] := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n[1]; mu[0] := 11.3;

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the t statistic

Note : In the following calculation, df = n-1 and it is used in both the calculation of the sample standard deviation
and in the calculation of the probability. It is not used in calculating the t-score.

> df := n[1]-1;
s := sqrt(((11.2-x[1])^2+(10.9-x[1])^2+(12.5-x[1])^2+(11.3-x[1])^2+(11.7-x[1])^2)/df);
s[1] := sqrt((11.2^2 + 10.9^2 + 12.5^2 + 11.3^2 + 11.7^2 - n[1]*x[1]^2)/df);
t := (x[1] - mu[0])/(s[1]/sqrt(n[1]));
evalf(s[1]); evalf(t);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1 - Tcd(-abs(t),abs(t),df);evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := Tcd(-10^10,t,df); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math]

> p := 1-Tcd(-10^10,t,df); evalf(p);

[Maple Math]

[Maple Math]

2-Sample t Test

The 2-Sample t Test uses the sample sizes, the samples variances, and the sample sizes to
test the hypothesis that the two samples were taken from the same population.

>

Sample Data

This Sample Data is taken from the Casio Manual, Section 18-6, page 286.

> n[1] := 8; x[1] := (55 + 54 + 51 + 55 + 53 + 53 + 54 + 53)/n[1];

[Maple Math]

[Maple Math]

> n[2] := 5; x[2] := (55.5 + 52.3 + 51.8 + 57.2 + 56.5)/n[2];

[Maple Math]

[Maple Math]

Calculate the t statistic. Pooling not in effect.

> s[1] := sqrt((55^2+54^2+51^2+55^2+53^2+53^2+54^2+53^2 - n[1]*x[1]^2)/(n[1]-1));
s[2] := sqrt((55.5^2+52.3^2+51.8^2+57.2^2+56.5^2 - n[2]*x[2]^2)/(n[2]-1));
zeta := (s[1]^2/n[1])/((s[1]^2/n[1]) + (s[2]^2/n[2]));
df := 1/((zeta^2/(n[1]-1)) + (1-zeta)^2/(n[2]-1));
t := (x[1] - x[2])/sqrt(s[1]^2/n[1] + s[2]^2/n[2]); evalf(t);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math] Pooling not in effect

> p := 1-Tcd(-abs(t),abs(t),df); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math] Pooling not in effect

> p := Tcd(-10^10,t,df); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math] Pooling not in effect

> p := 1-Tcd(-10^10,t,df); evalf(p);

[Maple Math]

[Maple Math]

Calculate the t statistic. Pooling in effect.

> s[1] := sqrt((55^2+54^2+51^2+55^2+53^2+53^2+54^2+53^2 - n[1]*x[1]^2)/(n[1]-1));
s[2] := sqrt((55.5^2+52.3^2+51.8^2+57.2^2+56.5^2 - n[2]*x[2]^2)/(n[2]-1));
df := n[1] + n[2] - 2;
t := (x[1] - x[2])/sqrt((((n[1]-1)*s[1]^2 + (n[2]-1)*s[2]^2)/df)*(1/n[1] + 1/n[2]));
evalf(t);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math] Pooling in effect

> p := 1-Tcd(-abs(t),abs(t),df); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math] Pooling in effect

> p := Tcd(-10^10,t,df); evalf(p);

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math] Pooling in effect

> p := 1-Tcd(-10^10,t,df); evalf(p);

[Maple Math]

[Maple Math]

LinearReg t Test

The LinearReg t Test determines the degree to which a linear relationship exists between
two paired-variable data sets.

Sample Data

This Sample Data is taken from the Casio Manual, Section 18-6, page 284.

> x1 := [ 0.5, 1.2, 2.4, 4, 5.2];
y1 := [-2.1, 0.3, 1.5, 5, 2.4];

[Maple Math]

[Maple Math]

Calculate the Basic Statistics

> n[1] := nops(x1);
x[1] := convert(x1,`+`): x[1] := x[1]/n[1];
y[1] := convert(y1,`+`): y[1] := y[1]/n[1];
sx2 := convert(map(x->x^2, x1),`+`): sx2 := sx2 - n[1]*x[1]^2;
sx := sqrt(sx2/(n[1]-1));
sy2 := convert(map(x->x^2, y1),`+`): sy2 := sy2 - n[1]*y[1]^2;
sy := sqrt(sy2/(n[1]-1));
sxy := convert(zip((x,y)->x*y, x1, y1),`+`): sxy := sxy - n[1]*x[1]*y[1];

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the regression coefficients, the correlation coefficient, and the t statistic.

> b := sxy / sx2;
a := y[1] - b*x[1];
r := sxy/((n[1]-1)*sx*sy);
df := n[1] - 2;
t := r*sqrt(df/(1-r^2));

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Alternate Hypothesis [Maple Math] & [Maple Math] : Two-Tail Test

> p := 1-Tcd(-t,t,df);

[Maple Math]

> with(plots):
F := plot((a+b*x),x=0..6,y=-3..6,style=line):
with(stats[statplots]):
G := plot([[0.5,-2.1],[1.2,0.3],[2.4,1.5],[4,5],[5.2,2.4]],style=`point`,symbol=`box`):
display({F,G},axes=`NORMAL`,title=`Simple Linear Regression`);

[Maple Plot]

Alternate Hypothesis [Maple Math] & [Maple Math] : Lower One-Tail Test

> p := Tcd(-10^10,t,df);

[Maple Math]

Alternate Hypothesis [Maple Math] & [Maple Math] : Upper One-Tail Test

> p := 1 - Tcd(-10^10,t,df);

[Maple Math]

[Maple Math] Test

[Maple Math] Test Preliminary Definitions

The [Maple Math] Probability distribution, [Maple Math] is given by [Maple Math] [Maple Math] ,

where [Maple Math] is the lower boundary and [Maple Math] is the upper boundary.

> Digits := 20; z := 'z';
Ccd := (a,b,df) -> (((1/2)^(df/2))/GAMMA(df/2))*int((z^(df/2-1)*exp(-z/2)),z=a..b);

[Maple Math]

[Maple Math]

[Maple Math]

> evalf(Ccd(0,19.023,9));

[Maple Math]

[Maple Math] Test

> A := [[1,4],[5,10]];
n := A[1,1] + A[1,2] + A[2,1] + A[2,2];
E := [[0,0],[0,0]]:
E[1,1] := (A[1,1] + A[1,2])*(A[1,1] + A[2,1])/n:
E[1,2] := (A[1,1] + A[1,2])*(A[1,2] + A[2,2])/n:
E[2,1] := (A[2,1] + A[2,2])*(A[1,1] + A[2,1])/n:
E[2,2] := (A[2,1] + A[2,2])*(A[1,2] + A[2,2])/n:
E;
chi := (A[1,1] - E[1,1])^2/E[1,1] + (A[1,2] - E[1,2])^2/E[1,2] +(A[2,1] - E[2,1])^2/E[2,1] + (A[2,2] - E[2,2])^2/E[2,2];
evalf(chi);
df := (2-1)*(2-1);
evalf(Ccd(chi,10^10,df));

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

2-Sample F Test

The 2-Sample F Test is used to test whether the standard deviations of two populations are different.

F Test Preliminary Definitions

The [Maple Math] probability distribution is given by [Maple Math] [Maple Math] ,

where [Maple Math] is the lower boundary.and [Maple Math] is the upper boundary.

> Digits := 20; z := 'z';
Fcd := (a,b,n,d) -> GAMMA((n+d)/2)/(GAMMA(n/2)*GAMMA(d/2)) * (n/d)^(n/2)*int(z^(n/2-1) * (1+n*z/d)^(-(n+d)/2),z=a..b);

[Maple Math]

[Maple Math]

[Maple Math]

Sample Data

This Sample Data is taken from the Casio Manual, Section 18-6, page 286.

> x1 := [-2.1, 0.3, 1.5, 5, 2.4];
x2 := [ 0.5, 1.2, 2.4, 4, 5.2];

[Maple Math]

[Maple Math]

Calculate the basic statistics

> n[1] := nops(x1); x[1] := convert(x1,`+`): x[1] := x[1]/n[1];
n[2] := nops(x2); x[2] := convert(x2,`+`): x[2] := x[2]/n[2];
s[1] := convert(map(x->x^2, x1),`+`): s[1] := sqrt((s[1] - n[1]*x[1]^2)/(n[1]-1));
s[2] := convert(map(x->x^2, x2),`+`): s[2] := sqrt((s[2] - n[2]*x[2]^2)/(n[2]-1));

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the F statistics

The F test convention assumes that the populations are labeled so that the first population has the larger sample variance.
Now determine the p values for the cases:
[Maple Math] , [Maple Math] , and [Maple Math] .

> F := s[1]^2/s[2]^2;
p1 := 1 - Fcd(1/F,F,n[1]-1,n[2]-1);
p2 := Fcd(0,F,n[1]-1,n[2]-1);
p3 := Fcd(0,1/F,n[1]-1,n[2]-1);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

ANOVA

The ANOVA analysis is used to determine whether the means of several samples are the same.

Sample Data

This Sample Data is taken from the Casio Manual, Section 18-6, page 291.

> x1 := [6, 7, 8, 6, 7];
x2 := [0, 3, 4, 3, 5, 4, 7];
x3 := [4, 5, 4, 6, 6, 7];

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the basic statistics

> n[1] := nops(x1); x[1] := convert(x1,`+`): x[1] := x[1]/n[1];
n[2] := nops(x2); x[2] := convert(x2,`+`): x[2] := x[2]/n[2];
n[3] := nops(x3); x[3] := convert(x3,`+`): x[3] := x[3]/n[3];
s[1] := convert(map(x->x^2, x1),`+`): s[1] := sqrt((s[1] - n[1]*x[1]^2)/(n[1]-1));
s[2] := convert(map(x->x^2, x2),`+`): s[2] := sqrt((s[2] - n[2]*x[2]^2)/(n[2]-1));
s[3] := convert(map(x->x^2, x3),`+`): s[3] := sqrt((s[3] - n[3]*x[3]^2)/(n[3]-1));
xbar := (n[1]*x[1] + n[2]*x[2] + n[3]*x[3])/(n[1] + n[2] + n[3]);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the ANOVA statistics

> k := 3; Fdf := k - 1; Edf := (n[1] - 1) + (n[2] - 1) + (n[3] - 1);
SS := evalf( n[1]*(x[1] - xbar)^2 + n[2]*(x[2] - xbar)^2 + n[3]*(x[3] - xbar)^2 );
SSe := evalf( (n[1]-1)*s[1]^2 + (n[2]-1)*s[2]^2 + (n[3]-1)*s[3]^2 );
MS := SS/Fdf;
MSe := SSe/Edf;
F := MS/MSe;
p := Fcd(F,10^10,Fdf,Edf);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Second Sample Data

This Sample Data is taken from the Moore and McCabe, page 725.

> x1 := [ 4, 6, 9, 12, 16, 15, 14, 12, 12, 8, 13, 9, 12, 12, 12, 10, 8, 12, 11, 8, 7, 9];
x2 := [ 7, 7, 12, 10, 16, 15, 9, 8, 13, 12, 7, 6, 8, 9, 9, 8, 9, 13, 10, 8, 8, 10];
x3 := [11, 7, 4, 7, 7, 6, 11, 14, 13, 9, 12, 13, 4, 13, 6, 12, 6, 11, 14, 8, 5, 8];

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the basic statistics

> n[1] := nops(x1); x[1] := convert(x1,`+`): x[1] := x[1]/n[1];
n[2] := nops(x2); x[2] := convert(x2,`+`): x[2] := x[2]/n[2];
n[3] := nops(x3); x[3] := convert(x3,`+`): x[3] := x[3]/n[3];
s[1] := convert(map(x->x^2, x1),`+`): s[1] := sqrt((s[1] - n[1]*x[1]^2)/(n[1]-1));
s[2] := convert(map(x->x^2, x2),`+`): s[2] := sqrt((s[2] - n[2]*x[2]^2)/(n[2]-1));
s[3] := convert(map(x->x^2, x3),`+`): s[3] := sqrt((s[3] - n[3]*x[3]^2)/(n[3]-1));
xbar := (n[1]*x[1] + n[2]*x[2] + n[3]*x[3])/(n[1] + n[2] + n[3]);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Calculate the ANOVA statistics

> k := 3; Fdf := k - 1; Edf := (n[1] - 1) + (n[2] - 1) + (n[3] - 1);
SS := evalf( n[1]*(x[1] - xbar)^2 + n[2]*(x[2] - xbar)^2 + n[3]*(x[3] - xbar)^2 );
SSe := evalf( (n[1]-1)*s[1]^2 + (n[2]-1)*s[2]^2 + (n[3]-1)*s[3]^2 );
MS := SS/Fdf;
MSe := SSe/Edf;
F := MS/MSe;
p := Fcd(F,10^10,Fdf,Edf);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]