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;
> Ncd := (a,b,sigma,mu) -> (1/2)*(erf((b-mu)/(sigma*sqrt(2))) - erf((a-mu)/(sigma*sqrt(2))));
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,
is the assumed population mean,
is the
standard deviation of the population, and n is the sample size.
Alternate Hypothesis
> n := 5; xbar := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n; sigma := 3; mu[0] := 11.5;
> z := (xbar - mu[0])/(sigma/sqrt(n)); p := 1-Ncd(-z,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> n := 5; xbar := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n; sigma := 3; mu[0] := 11.5;
> z := (xbar - mu[0])/(sigma/sqrt(n)); p := Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> n := 5; xbar := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n; sigma := 3; mu[0] := 11.5;
> z := (xbar - mu[0])/(sigma/sqrt(n)); p := 1-Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);
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
and
are the two sample means,
and
are the standard deviations of the two populations,
and
and
are the two sample sizes.
Alternate Hypothesis
> n[1] := 5; xbar[1] := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n[1]; sigma[1] := 15.5;
> n[2] := 5; xbar[2] := (0.84 + 0.9 + 0.14 + (-0.75) + (-0.95))/n[2]; sigma[2] := 13.5;
> z := (xbar[1] - xbar[2])/sqrt((sigma[1]^2/n[1]) + (sigma[2]^2/n[2])); p := 1-Ncd(-z,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> n[1] := 5; xbar[1] := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n[1]; sigma[1] := 15.5;
> n[2] := 5; xbar[2] := (0.84 + 0.9 + 0.14 + (-0.75) + (-0.95))/n[2]; sigma[2] := 13.5;
> z := (xbar[1] - xbar[2])/sqrt((sigma[1]^2/n[1]) + (sigma[2]^2/n[2])); p := Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> n[1] := 5; xbar[1] := (11.2 + 10.9 + 12.5 + 11.3 + 11.7)/n[1]; sigma[1] := 15.5;
> n[2] := 5; xbar[2] := (0.84 + 0.9 + 0.14 + (-0.75) + (-0.95))/n[2]; sigma[2] := 13.5;
> z := (xbar[1] - xbar[2])/sqrt((sigma[1]^2/n[1]) + (sigma[2]^2/n[2])); p := 1 - Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);
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,
is the assumed population proportion,
and n is the sample size.
Alternate Hypothesis
> n := 4040; x := 2048; p[0] := 0.5;
> z := (x/n - p[0])/sqrt(p[0]*(1-p[0])/n); p := 1-Ncd(-z,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> n := 4040; x := 2048; p[0] := 0.5;
> z := (x/n - p[0])/sqrt(p[0]*(1-p[0])/n); p := Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> n := 4040; x := 2048; p[0] := 0.5;
> z := (x/n - p[0])/sqrt(p[0]*(1-p[0])/n); p := 1-Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);
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
and
are the number of data in the two samples that satisfy the criteria,
and
and
are the two sample sizes.
Alternate Hypothesis
> x[1] := 225; n[1] := 300; x[2] := 230; n[2] := 300;
>
phat := (x[1]+x[2])/(n[1]+n[2]);
z := abs(x[1]/n[1] - x[2]/n[2])/sqrt(phat*(1-phat)*(1/n[1] + 1/n[2]));
p := 1-Ncd(-z,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> x[1] := 225; n[1] := 300; x[2] := 230; n[2] := 300;
>
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]));
p := Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);
Alternate Hypothesis
> x[1] := 225; n[1] := 300; x[2] := 230; n[2] := 300;
>
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]));
p := 1-Ncd(-10^10,z,1,0);
> evalf(z);evalf(p);