Confidence Intervals
Daniel D. Warner
June 7, 1999
Normal Distribution
The Normal Probability Density
The normal probability density is given by
,
where
.
> Npd := (x,sigma,mu) -> (1/(sigma*sqrt(2*Pi)))*exp(-((x-mu)/(sigma*sqrt(2)))^2);
> Digits := 20;
> sigma := 2; mu := 35;
> evalf(Npd(36,sigma,mu));
The Normal Probability Distribution
The Normal Probability Distribution,
, is given by
,
where
is the lower boundary and
is the upper boundary.
> sigma := 'sigma'; mu := 'mu';
> Ncd := (a,b,sigma,mu) -> int(Npd(x,sigma,mu),x=a..b);
> evalf(Ncd(-10^99,36,2,35));
> Ncd2 := (a,b,sigma,mu) -> (1/2)*(erf((b-mu)/(sigma*sqrt(2))) - erf((a-mu)/(sigma*sqrt(2))));
> p2 := evalf(Ncd2(-10^99,36,2,35));
The Inverse Cumulative Normal Distribution
The Inverse Cumulative Normal Probability Distribution finds
given
,
> InvN := (p,sigma,mu) -> solve(Ncd2(-infinity,x,sigma,mu)=p,x);
> InvN(1/2,1,0);
> evalf(%);
> InvN(p2,2,35);
One Sample Confidence Interval (1-S)
Given the confidence level,
, determine
z
* such that
P(z* < z < z*) = C
, where
z
is the normalized statistic
.
>
Z1S := C -> solve(Ncd2(0,x,1,0)=C/2,x);
> C := 0.95; xbar := 11.52; sigma := 3; n :=5;
> zhat := Z1S(C);
> d := evalf(zhat*sigma/sqrt(n)); xLeft := xbar - d; xRight := xbar + d;
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
.
> Z2S := C -> solve(Ncd2(0,x,1,0)=C/2,x);
> C := 0.95; x1 := 53.5; x2 := 54.66; sigma[1] := 15.5; sigma[2] := 13.5; n1 := 8; n2 := 5;
> zhat := evalf(Z2S(C));
> d := zhat*sqrt((sigma[1]^2/n1 + sigma[2]^2/n2)); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;
1-Prop Confidence Interval
Uses the number of data to calculate the confidence interval when the proportion is not known.
Given the confidence level,
, determine
z
* such that
P(z* < z < z*) = C
, where
z
is the normalized statistic
.
>
Z1P := C -> solve(Ncd2(0,x,1,0)=C/2,x);
> C := 0.99; xs := 55; n := 100;
> zhat := evalf(Z1P(C));
> d := zhat*sqrt((1.0/n)*(xs/n)*(1.0-xs/n)); xLeft := xs/n - d; xRight := xs/n + d;
2-Prop Confidence Interval
Uses the number of data to calculate the confidence interval when the proportion is not known.
Given the confidence level,
, determine
z
* such that
P(z* < z < z*) = C
, where
z
is the normalized statistic
> Z2P := C -> solve(Ncd2(0,x,1,0)=C/2,x);
> C := 0.95; x1 := 49; n1:= 61; x2:= 38; n2 := 62;
> zhat := evalf(Z2P(C));
> 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;
Student-t Distribution
Student-t Probability Density
The Student-t Probability Density,
, is given by
,
> Tpd := (x,df) -> (GAMMA((df+1)/2)/GAMMA(df/2))*(1+x^2/df)^(-(df+1)/2)/sqrt(Pi*df);
> Tpd(1,2);
> evalf(%);
Student-t Cumulative Distribution
The Student-t Probability Distribution,
, is given by
,
where
is the lower boundary and
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));
> Tcd(-2,3,18);
> Tcd(0,2.7764451051978,4);
One Sample t Interval (1-S)
Given the confidence level,
, determine
t
* such that
P(t* < t < t*) = C
, where
t
is the student
t
statistic
.
>
T1S := (df,C) -> fsolve(Tcd(0,t,df)=C/2,t);
> C := 0.95; xbar := 11.52; s := 0.61806; n :=5;
> that := T1S(n-1,C);
> d := evalf(that*s/sqrt(n)); xLeft := xbar - d; xRight := xbar + d;
Two Sample t Interval (2-S)
Given the confidence level,
, determine
t
* such that
P(t* < t < t*) = C
, where
t
is the student
t
statistic
representing the difference of the sample means
.
The degrees of freedom are given by
, where
.
or if the data is pooled, then
.
> T2S := (df,C) -> fsolve(Tcd(0,t,df)=C/2,t);
> C := 0.95; x1 := 53.5; x2 := 54.66; s1 := 1.3093; s2 := 2.4643; n1 := 8; n2 := 5;
> 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);
> d := that*sqrt(s1^2/n1 + s2^2/n2); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;
For pooled calculations we have
, and
, where
is the pooled standard deviation.
For the preceding problem we would have
> sp := 1.8163; df := n1 + n2 - 2; that := T2S(df,C);
> d := that*sqrt(sp^2*(1/n1 + 1/n2)); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;
Example from Freund (pooled approach).
> C := 0.95; x1 := 94.3; s1 := 5.7; n1 := 8; x2 := 85.7; s2 := 6.2; n2 := 7;
> df := n1 + n2 - 2; sp := sqrt(((n1-1)*s1^2 + (n2-1)*s2^2)/df); that := T2S(df,C);
> d := that*sqrt(sp^2*(1/n1 + 1/n2)); xbar := x1 - x2; xLeft := xbar - d; xRight := xbar + d;
>