Confidence Intervals

Daniel D. Warner
June 7, 1999

Normal Distribution

The Normal Probability Density

The normal probability density is given by [Maple Math] [Maple Math] ,

where [Maple Math] .

> Npd := (x,sigma,mu) -> (1/(sigma*sqrt(2*Pi)))*exp(-((x-mu)/(sigma*sqrt(2)))^2);

[Maple Math]

> Digits := 20;

[Maple Math]

> sigma := 2; mu := 35;

[Maple Math]

[Maple Math]

> evalf(Npd(36,sigma,mu));

[Maple Math]

The Normal Probability Distribution

The Normal 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.

> sigma := 'sigma'; mu := 'mu';

[Maple Math]

[Maple Math]

> Ncd := (a,b,sigma,mu) -> int(Npd(x,sigma,mu),x=a..b);

[Maple Math]

> evalf(Ncd(-10^99,36,2,35));

[Maple Math]

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

[Maple Math]

> p2 := evalf(Ncd2(-10^99,36,2,35));

[Maple Math]

The Inverse Cumulative Normal Distribution

The Inverse Cumulative Normal Probability Distribution finds [Maple Math] given [Maple Math] [Maple Math] ,

> InvN := (p,sigma,mu) -> solve(Ncd2(-infinity,x,sigma,mu)=p,x);

[Maple Math]

> InvN(1/2,1,0);

[Maple Math]

> evalf(%);

[Maple Math]

> InvN(p2,2,35);

[Maple Math]

One Sample Confidence Interval (1-S)

Given the confidence level, [Maple Math] , determine z * such that P(­z* < z < z*) = C , where z is the normalized statistic
[Maple Math] .

> Z1S := C -> solve(Ncd2(0,x,1,0)=C/2,x);

[Maple Math]

> C := 0.95; xbar := 11.52; sigma := 3; n :=5;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> zhat := Z1S(C);

[Maple Math]

> d := evalf(zhat*sigma/sqrt(n)); xLeft := xbar - d; xRight := xbar + d;

[Maple Math]

[Maple Math]

[Maple Math]

Two Sample Confidence Interval (2-S)


Given the confidence level,
C , determine z* such that P(­z* < z < z*) = C , where z is the normalized statistic
[Maple Math] .

> Z2S := C -> solve(Ncd2(0,x,1,0)=C/2,x);

[Maple Math]

> C := 0.95; x1 := 53.5; x2 := 54.66; sigma[1] := 15.5; sigma[2] := 13.5; n1 := 8; n2 := 5;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> zhat := evalf(Z2S(C));

[Maple Math]

> d := zhat*sqrt((sigma[1]^2/n1 + sigma[2]^2/n2)); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

1-Prop Confidence Interval

Uses the number of data to calculate the confidence interval when the proportion is not known.
Given the confidence level,
[Maple Math] , determine z * such that P(­z* < z < z*) = C , where z is the normalized statistic
[Maple Math] .

> Z1P := C -> solve(Ncd2(0,x,1,0)=C/2,x);

[Maple Math]

> C := 0.99; xs := 55; n := 100;

[Maple Math]

[Maple Math]

[Maple Math]

> zhat := evalf(Z1P(C));

[Maple Math]

> d := zhat*sqrt((1.0/n)*(xs/n)*(1.0-xs/n)); xLeft := xs/n - d; xRight := xs/n + d;

[Maple Math]

[Maple Math]

[Maple Math]

2-Prop Confidence Interval

Uses the number of data to calculate the confidence interval when the proportion is not known.
Given the confidence level,
[Maple Math] , determine z * such that P(­z* < z < z*) = C , where z is the normalized statistic
[Maple Math]

> Z2P := C -> solve(Ncd2(0,x,1,0)=C/2,x);

[Maple Math]

> C := 0.95; x1 := 49; n1:= 61; x2:= 38; n2 := 62;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> zhat := evalf(Z2P(C));

[Maple Math]

> d := zhat*sqrt(((x1/n1)*(1.0-x1/n1))/n1 + ((x2/n2)*(1.0-x2/n2))/n2); p := x1/n1 - x2/n2; xLeft := p - d; xRight := p + d;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Student-t Distribution

Student-t Probability Density

The Student-t Probability Density, [Maple Math] , is given by [Maple Math] [Maple Math] ,

> Tpd := (x,df) -> (GAMMA((df+1)/2)/GAMMA(df/2))*(1+x^2/df)^(-(df+1)/2)/sqrt(Pi*df);

[Maple Math]

> Tpd(1,2);

[Maple Math]

> evalf(%);

[Maple Math]

Student-t Cumulative Distribution

The Student-t 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.

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

[Maple Math]

> Tcd(-2,3,18);

[Maple Math]

> Tcd(0,2.7764451051978,4);

[Maple Math]

One Sample t Interval (1-S)

Given the confidence level, [Maple Math] , determine t * such that P(­t* < t < t*) = C , where t is the student t statistic
[Maple Math] .

> T1S := (df,C) -> fsolve(Tcd(0,t,df)=C/2,t);

[Maple Math]

> C := 0.95; xbar := 11.52; s := 0.61806; n :=5;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> that := T1S(n-1,C);

[Maple Math]

> d := evalf(that*s/sqrt(n)); xLeft := xbar - d; xRight := xbar + d;

[Maple Math]

[Maple Math]

[Maple Math]

Two Sample t Interval (2-S)


Given the confidence level,
[Maple Math] , determine t * such that P(­t* < t < t*) = C , where t is the student t statistic
representing the difference of the sample means


[Maple Math] .
The degrees of freedom are given by
[Maple Math] , where [Maple Math] .
or if the data is pooled, then
[Maple Math] .

> T2S := (df,C) -> fsolve(Tcd(0,t,df)=C/2,t);

[Maple Math]

> C := 0.95; x1 := 53.5; x2 := 54.66; s1 := 1.3093; s2 := 2.4643; n1 := 8; n2 := 5;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> zeta := (s1^2/n1)/(s1^2/n1+s2^2/n2); df := 1/(zeta^2/(n1-1)+(1-zeta)^2/(n2-1)); that := T2S(df,C);

[Maple Math]

[Maple Math]

[Maple Math]

> d := that*sqrt(s1^2/n1 + s2^2/n2); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

For pooled calculations we have [Maple Math] , and [Maple Math] , where [Maple Math] is the pooled standard deviation.
For the preceding problem we would have

> sp := 1.8163; df := n1 + n2 - 2; that := T2S(df,C);

[Maple Math]

[Maple Math]

[Maple Math]

> d := that*sqrt(sp^2*(1/n1 + 1/n2)); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Example from Freund (pooled approach).

> C := 0.95; x1 := 94.3; s1 := 5.7; n1 := 8; x2 := 85.7; s2 := 6.2; n2 := 7;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> df := n1 + n2 - 2; sp := sqrt(((n1-1)*s1^2 + (n2-1)*s2^2)/df); that := T2S(df,C);

[Maple Math]

[Maple Math]

[Maple Math]

> d := that*sqrt(sp^2*(1/n1 + 1/n2)); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

>