Application Center - Maplesoft

App Preview:

High School Advanced Topics - Hypothesis Testing

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Hypothesis Testing.mws

High School Modules > Advanced Miscellaneous Topics

     Hypothesis Testing


An exposition of several variations of hypothesis testing using a visual aids.

[Directions : Execute the Code Resource section first. Although there will be no output immediately, these definitions are used later in this worksheet.]

  0. Code

>    restart;

>    with(plots):  with(stats):

Warning, the name changecoords has been redefined

>    pc := COLOR(RGB, .95,.3,.45):
bc := COLOR(RGB, .45,.3,.95):

>    x_plot := proc(x, mean, sd)
local xvalue, f, p, delta, index, n, area, Left, Right,A,B,ec,bc;
ec := COLOR(RGB, .70, .65,.50):
bc := COLOR(RGB, .38, .31,.28 ):
f:= u -> exp( -((u-mean)^2)/ (2*sd^2) )/(sd*sqrt(2*Pi));
     
Right := fsolve( f(mean)/100 = f(xvalue), xvalue, mean..((1+mean)*4));
Left := mean - (Right-mean);  
Print(Left, Right);                   
A := plot( f(t), t = Left..x, color = ec, filled = true);
B := plot( f(t), t = x..Right, color = bc, filled = true);
#area := int( f(u), u = x..infinity);
plots[display](A,B);

end:

>    HypRight := proc(z, w)
local xvalue, f, p, delta, index, n, area, Left, Right,A,B,C,C2;

f := x -> exp(-(x^2)/2)/sqrt(2*Pi);
A := plot( f(t), t = -3..z, color = red, filled = true);
B := plot( f(t), t = z..3,  color = black, filled = true);
C := plot( [[w-.15,0],[w+.15,0],[w,.05],[w-.15,0]],
             color = coral, filled = true):
C2 := plot( [[w,0],[w,.4]],
             color = coral, linestyle = 3):
plots[display]([C,C2, A,B]);

end:

>    HypLeft := proc(z, w)
local xvalue, f, p, delta, index, n, area, Left, Right,A,B,C,C2;

f := x -> exp(-(x^2)/2)/sqrt(2*Pi);
A := plot( f(t), t = z..3,  color = red, filled = true);
B := plot( f(t), t = -3..z, color = black, filled = true);
C := plot( [[w-.15,0],[w+.15,0],[w,.05],[w-.15,0]],
             color = coral, filled = true):
C2 := plot( [[w,0],[w,.4]],
             color = coral, linestyle = 3):
plots[display]([C,C2, A,B]);

end:



>    HypBoth := proc(z, w)
local xvalue, f, p, delta, index, n, area, Left, Right,A1,A2,B,C,C2, border;

f := x -> exp(-(x^2)/2)/sqrt(2*Pi);
border := abs(z);
A1 := plot( f(t), t = -3..(-border), color = black, filled = true);
B  := plot( f(t), t = (-border)..border,  color = red, filled = true);
A2 := plot( f(t), t = border..3,  color = black, filled = true);

C := plot( [[w-.15,0],[w+.15,0],[w,.05],[w-.15,0]],
             color = coral, filled = true):
C2 := plot( [[w,0],[w,.4]],
             color = coral, linestyle = 3):
plots[display]([C,C2,A1,A2,B]);

end:




>   

  1. Hypothesis Testing


Suppose a hypothesis is that the mean of a data set is 11 and standard deviation is 1.8. We take a sample and find that the sample mean is 14. Is this a reasonable variation? If the mean were truly 11, its possible that we might get a sample mean of 14 with the luck of the draw.

>    x_plot( 14, 11, 1.8);

[Maple Plot]


 Somehow we need to quantify our "apprehension" about this number, and decide if its reasonable. The way that we do that, is to decide on how much probability we consider adequate to assure us. Is it enough that there is a 80% of it happening, 90% chance, 95% chance, 99% chance, 99.9% chance. Once we decide on how much certainty we need,  then we can determine if this value fits the hypothesis or not. In most problems, you will be given this - often a
level of significance , which is 1 - ( level of confidence ).

Basic Process
The basic process is to convert to z scores. There is a z score associated with the level of significance, and another z score for the x value. It boils down to comparing the two. A good way to think of it, is that the level of significance determines a z-score, which in turn determines a "rejection zone" which is always on one edge, the other, or both.

One-Tailed or Two-Tailed Tests

In testing a hypothesis, there are some problems where our concern is that a value may be too large, and other cases we only care if its too small - these are one-tailed situations. If we are concerned about it being too large or too small at the same time, a two-sided test is called for.

This makes a difference in the computations because we need to distribute the "significance" all on one side, or equally distributed with half on one side and half on the other.

  2. Right-Tailed Hypothesis Tests


Example  : Test the hypothesis that the mean is 11, if the sample mean is 14, and standard deviation is 1.7 at a 5% level of significance.
 
We are not concerned that the mean is too small, but it could be too large. This is a one-tailed test. So we find the z value that allows for 5% to the far right, and 95% to the left. (Look in the chart for .4500.. and get z = 1.65.) This sets up our "rejection zone"  - all of the values to the right of z = 1.65.

>    zborder := statevalf[icdf,normald[0,1]](0.95);

zborder := 1.644853627


If the z we compute for the sample mean fall in the rejection zone, then we reject the hypothesis that 11 is the true mean. If it doesn't land in the "rejection zone" (black area below), then we accept the hypothesis.

>    zdata := (14-11)/1.7;

zdata := 1.764705882

>    HypRight( zborder, zdata);

[Maple Plot]


As you can see, it is indeed in the rejection zone. (The yellow triangle represents the data value - and it falls in the black rejection zone.) We reject the hypothesis.


Suppose that we had gotten 13.5 instead of 14 for the sample mean. Would we still reject the hypothesis?

>    zdata := (13.5-11)/1.7;

zdata := 1.470588235

>    HypRight( zborder, zdata);

[Maple Plot]


 
This time the yellow triangle falls in the acceptance area (red). We will accept the hypothesis in this case.

  3. Left-Tailed Hypothesis Tests


Example  : At a 10% level of significance, can we accept the hypothesis that the mean is 24.3, given a standard deviation of 3.7, and a sample mean of 20?

This is a one-tailed hypothesis test - but on the left side rather than the right. We find z for -.4000. ....by finding z for .4000, which is 1.28, then negating it. This sets up our rejection zone.

>    zborder := statevalf[icdf,normald[0,1]](0.10);

zborder := -1.281551566

>    zdata := (20 - 24.3)/3.7;

zdata := -1.162162162

>    HypLeft( zborder, zdata);

[Maple Plot]


This z score does not fall into the rejection zone. We
accept  the hypothesis at a 10% level of significance.


 

  4. Two-Tailed Hypothesis Tests


In a two-tailed case, we proceed as we did above, but we need to split the "level of significance" in half because we are considering both sides.

Example  : At a 5% level of significance, evaluate the hypothesis that the mean is 40, given the sample mean is 44, and standard deviation is 2.7.

We need to look for 2.5% on the far right ( and left). You can search a Normal distribution table for .4750 - which is about 1.96,... or for greater accuracy, you can use this rather cryptic maple command.

>    zborder := statevalf[icdf,normald[0,1]](0.975);

zborder := 1.959963985

>    zdata := (44-40)/2.7;

zdata := 1.481481481

>    HypBoth(zborder, zdata );

[Maple Plot]


This value is not any either of the two black rejection zones at far left and far right, therefore we ACCEPT the hypothesis.




Example  : At a 1% level of significance, evaluate the hypothesis that the mean is 6.6, given the sample mean is 4.1, and standard deviation is 1.02.

We need to look for 0.5% on the far right (and left). Search a Normal distribution table for .4950 - which is about -258.. or more accurately ....

>    zborder := statevalf[icdf,normald[0,1]](0.005);

zborder := -2.575829304

>    zdata = (4.1-6.6)/1.02;

1.481481481 = -2.450980392

>    HypBoth(zborder, zdata );

[Maple Plot]

>   


Although the value is negative, we still ACCEPT the hypothesis.


 


          2002 Waterloo Maple Inc & Gregory Moore, all rights reserved.