Application Center - Maplesoft

App Preview:

High School Advanced Topics - Confidence Intervals

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

Learn about Maple
Download Application


 

Confidence Intervals.mws

High School Modules > Advanced Miscellaneous Topics

     Confidence Intervals


An exploration of confidence intervals with particular attention to visualization and computation.

[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):

Warning, the name changecoords has been redefined

>    makebox  :=  proc( mid, wid, level, CL )
 local Tl,Tr,TL,TR,P1,P2,c,nl,nr, delta, ht;
 delta := .6; ht := delta*level;
 c  := COLOR(RGB, 1, .9-level*.22,0);
 nl := evalf(mid-wid,3);     nr := evalf(mid+wid,3);
 Tl  := plots[textplot]( [mid-wid, ht, nl],
             align={ABOVE,RIGHT},font=[TIMES,ROMAN,12]):
 Tr  := plots[textplot]( [mid+wid, ht, nr],
             align={ABOVE,LEFT},font=[TIMES,ROMAN,12]):

 TL  := plots[textplot]( [mid-wid, -ht, CL],
             align={BOTTOM,LEFT},font=[TIMES,BOLD,15], color = c):
 TR  := plots[textplot]( [mid+wid, -ht, CL],
             align={BOTTOM,RIGHT},font=[TIMES,BOLD,15], color = c):

 P1 := plot( [[mid-wid,+ht],
             [mid-wid,-ht],[mid-wid/5,-ht],[mid,0],[mid+wid/5,-ht],
             [mid+wid,-ht],[mid+wid,ht]],
             thickness = 1, color = c ):
 P2 := plot( [[mid-wid,ht],[mid+wid,ht]],
        thickness = 6, color = c ):
 plots[display]( [P1,P2,Tl,Tr,TL,TR], scaling = constrained);
 end proc:

>    makeboxb  :=  proc( mid, wid, level, CL )
 local Tl,Tr,TL,TR,P1,P2,P3,c,nl,nr, delta, ht;
 delta := .26; ht := delta*level;
 c  := COLOR(RGB, 0, 0, .78);
 nl := evalf(mid-wid,3);     nr := evalf(mid+wid,3);
 Tl  := plots[textplot]( [mid-wid, 2*ht, nl],
             align={ABOVE,MIDDLE},font=[TIMES,ROMAN,13]):
 Tr  := plots[textplot]( [mid+wid, 2*ht, nr],
             align={ABOVE,MIDDLE},font=[TIMES,ROMAN,13]):

 TL  := plots[textplot]( [mid-wid, -2*ht, CL],
             align={BOTTOM,LEFT},font=[TIMES,BOLD,15], color = c):
 TR  := plots[textplot]( [mid+wid, -2*ht, CL],
             align={BOTTOM,RIGHT},font=[TIMES,BOLD,15], color = c):

 P1 := plot( [[mid+wid,ht],[mid-wid,ht],[mid-wid,+ht],
             [mid-wid,-ht],[mid-wid/5,-ht],[mid,0],[mid+wid/5,-ht],
             [mid+wid,-ht],[mid+wid,ht]],
             thickness = 1, color = c, filled = true ):
 #P2 := plot( [],thickness = 8, color = c ):
 P3 := plot( [[mid-(1.4*wid),0],[mid+(1.4*wid),0]],
              thickness = 1, color = COLOR(RGB, .8, .6, 0) ):
 plots[display]( [P1,P3,Tl,Tr,TL,TR], scaling = constrained);
 end proc:

>    #______________________________________________________________
Conf80  :=  proc( m, sd)
 local A80;
 A80 := makeboxb(  m, 1.28 *sd, 2, 80):
 plots[display]( A80 );
 end proc:

>    Conf90  :=  proc( m, sd)
 local A90 ;
 A90 := makeboxb(  m, 1.645*sd, 2, 90):
 
 plots[display]( A90 );
 end proc:

>    Conf95  :=  proc( m, sd)
 local A95;
 A95 := makeboxb(  m, 1.96 *sd, 2, 95):
 plots[display]( A95 );
 end proc:

>    Conf99  :=  proc( m, sd)
 local A99;
 A99 := makeboxb(  m, 2.575*sd, 2, 99):
 plots[display]( A99 );
 end proc:

>    Conf95Plot  :=  proc( m, sd)
 local A95,P,f,w;
 f := x -> 50*exp( -((x-m)^2)/ (2*sd^2) )/(sd*sqrt(2*Pi));
 w := 3*sd;
 P   := plot( f(x), x = (m-w)..(m+w),
              color = COLOR(RGB, .8,.6,.2), filled = true):
 
 A95 := makeboxb(  m, 1.96 *sd, 3, 95):
 
 plots[display]( [A95,P] );
 end proc:

>    #______________________________________________________________
ConfInts  :=  proc( m, sd)
 local A80,A90,A95,A99;
 
 A80 := makebox(  m, 1.28 *sd, 1, 80):
 A90 := makebox(  m, 1.645*sd, 2, 90):
 A95 := makebox(  m, 1.96 *sd, 3, 95):
 A99 := makebox(  m, 2.575*sd, 4, 99):
 plots[display]( A80,A90,A95,A99 );
 end proc:

#______________________________________________________________

>    ConfIntPlot  :=  proc( m, sd)
 local A80,A90,A95,A99,P,f,w;
 f := x -> 50*exp( -((x-m)^2)/ (2*sd^2) )/(sd*sqrt(2*Pi));
 w := 3*sd;
 P   := plot( f(x), x = (m-w)..(m+w),
              color = COLOR(RGB, .4,.4,.8), filled = true):
 A80 := makebox(  m, 1.28 *sd, 1, 80):
 A90 := makebox(  m, 1.645*sd, 2, 90):
 A95 := makebox(  m, 1.96 *sd, 3, 95):
 A99 := makebox(  m, 2.575*sd, 4, 99):
  
 plots[display]( [A80,A90,A95,A99,P] );
 end proc:

>   

>   

>   

>   

  1. What is a Confidence Interval?


A confidence interval is an estimate - a range estimate in fact. And unlike most estimates, it comes along with a probability of its correctness.

This is what a confidence interval looks like :

>    [ 5.6, 11.3];

[5.6, 11.3]


To which we would be able to say with 90% certainty that the number we are looking for, lives inside of this range of numbers.
 

  2. Visualizing a Confidence Interval


A confidence interval is closely related to the normal distribution. This is the 95% confidence interval when the mean is 10 and standard deviation is 3. This means that 95% of the possible values are in this range (4.12, 15.9).

>    Conf95Plot(10,3);

[Maple Plot]


Here are four confidence intervals for the same mean (10) and standard deviation (3). Can you explain what is happening as the level of confidence goes up?

>    Conf80(10,3);

[Maple Plot]

>    Conf90(10,3);

[Maple Plot]

>    Conf95(10,3);

[Maple Plot]

>    Conf99(10,3);

[Maple Plot]


As you can see, as the level of confidence goes up, the range of values gets wider and less precise - a trade-off.
 

  3. Comparing Confidence Intervals


Lets see several confidence intervals for the same mean and standard deviation on the same graph.

>    ConfInts( 10, 3 );

[Maple Plot]

>    ConfIntPlot( 10, 3 );

[Maple Plot]



Here is another example, where the mean is 30 and standard deviation 4.21.

>    ConfInts( 30, 4.21 );

[Maple Plot]

>    ConfIntPlot( 30, 4.21 );

[Maple Plot]



Let the mean be 7.3 and standard deviation 1.09.

>    ConfInts(  17.3, 1.79 );

[Maple Plot]

>    ConfIntPlot(  17.3, 1.79 );

[Maple Plot]

>   


 

  4. Computing Confidence Intervals


Its not difficult to compute a confidence interval. Its much like computing an x value, given a z value.

We need to be given the mean, the standard deviation, and level of confidence.

>    m := 25;  sd := 4.1;   loc = .95;

m := 25

sd := 4.1

loc = .95

 
The level of confidence is also how much of the normal distribution we want to be centered around the mean. This leaves two "tails" - one on the far left and one on the far right. Take half of the level of confidence, to find the amount of area to the right of the mean, and then look this value up in the body of a normal distribution table to find the corresponding z score.

>    .95/2;

.4750000000

>    z := 1.96;

z := 1.96


Now plug in these values into the familiar formulas to find the right and left extremes of the 95% confidence interval for this example.

>    m + z*sd;
m - z*sd;

33.036

16.964

>   

>   


 


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