STATISTICA







STATISTICA BASIC Program Interval.stb

{ This program computes one-sided and two-sided confidence, prediction, and tolerance intervals for various statistics including mean, standard deviation, proportions, and number of occurances. The user is required to input points estimates, sample sizes, and the desired confidence. Formulas were taken from "Statistical Intervals - A Guide for Practitioners" by Gerald Hahn and William Meeker.

Program written by Jim Zalnoski, Harris Semiconductor, Palm Bay, Florida}


randomaccess;
{STATISTICAL INTERVALS};
dim intv(5,2);
type:=displaybuttonbox('Select type of interval','Confidence|Prediction|Tolerance');
				{CONFIDENCE INTERVAL SECTION};
if type=1 then begin
stat1:=displaybuttonbox('Select statistics','Mean|Standard Deviation|Proportion|# Occurances');
if stat1=0 then stop;
if stat1=1 then begin
displayinputbox('Input parameters for the mean','Mean |'+'Standard Deviation |'+'Sample Size |'+'% Confidence Level',in1$);
getdelimitedstring(in1$,1,x1$); xbar:=val(x1$);
getdelimitedstring(in1$,2,s1$); s:=val(s1$);
getdelimitedstring(in1$,3,n1$); n:=val(n1$);
getdelimitedstring(in1$,4,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=xbar+vstudent(1-alpha/2,n-1)*(s/Sqrt (n));
ll2:=xbar-vstudent(1-alpha/2,n-1)*(s/Sqrt (n));
ul1:=xbar+vstudent(1-alpha,n-1)*(s/Sqrt (n));
ll1:=xbar-vstudent(1-alpha,n-1)*(s/Sqrt (n));
intv(1,1):=ul2 ; intv(2,1):=xbar; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=xbar; intv(3,2):=ll1 ; intv(4,2):=n; intv(5,2):=(1-alpha)*100 ;
title$:='Confidence Interval for the Mean';
goto scrl;
end;
if stat1=2 then begin
displayinputbox('Input parameters for the standard deviation','Standard Deviation |'+'Sample Size |'+'% Confidence
Level',in1$);
getdelimitedstring(in1$,1,s1$); s:=val(s1$);
getdelimitedstring(in1$,2,n1$); n:=val(n1$);
getdelimitedstring(in1$,3,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=s*sqrt((n-1)/vchi2(alpha/2,n-1));
ll2:=s*sqrt((n-1)/vchi2(1-alpha/2,n-1));
ul1:=s*sqrt((n-1)/vchi2(alpha,n-1));
ll1:=s*sqrt((n-1)/vchi2(1-alpha,n-1));
intv(1,1):=ul2 ; intv(2,1):=s; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=s; intv(3,2):=ll1 ; intv(4,2):=n; intv(5,2):=(1-alpha)*100 ;
title$:='Confidence Interval for the Standard Deviation';
goto scrl;
end;
if stat1=3 then begin
displayinputbox('Input parameters for the proportion','Proportion|'+'Sample Size |'+'% Confidence Level',in1$);
getdelimitedstring(in1$,1,s1$); p:=val(s1$);
getdelimitedstring(in1$,2,n1$); n:=val(n1$);
getdelimitedstring(in1$,3,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=p+vnormal(1-alpha/2,0,1)*sqrt((p*(1-p))/n);
ll2:=p-vnormal(1-alpha/2,0,1)*sqrt((p*(1-p))/n);
ul1:=p+vnormal(1-alpha,0,1)*sqrt((p*(1-p))/n);
ll1:=p-vnormal(1-alpha,0,1)*sqrt((p*(1-p))/n);
intv(1,1):=ul2 ; intv(2,1):=p; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=p; intv(3,2):=ll1 ; intv(4,2):=n; intv(5,2):=(1-alpha)*100 ;
title$:='Confidence Interval for the Proportion';
goto scrl;
end;
if stat1=4 then begin
displayinputbox('Input parameters for the count','Total Count|'+'Sample Size |'+'% Confidence Level',in1$);
getdelimitedstring(in1$,1,s1$); cnt:=val(s1$);
getdelimitedstring(in1$,2,n1$); n:=val(n1$);
getdelimitedstring(in1$,3,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=(.5*vchi2(1-alpha/2,2*cnt+2))/n;
ll2:=(.5*vchi2(alpha/2,2*cnt))/n;
ul1:=(.5*vchi2(1-alpha,2*cnt+2))/n;
ll1:=(.5*vchi2(alpha,2*cnt))/n;
intv(1,1):=ul2 ; intv(2,1):=cnt; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=cnt; intv(3,2):=ll1 ; intv(4,2):=n; intv(5,2):=(1-alpha)*100 ;
title$:='Confidence Interval for the Average Count';
goto scrl;
end; end;
				{PREDICTION INTERVAL SECTION};
if type=2 then begin
stat1:=displaybuttonbox('Select statistics','Mean|Standard Deviation|All Observations|Proportion|# Occurances');
if stat1=0 then stop;
if stat1=1 then begin
displayinputbox('Input parameters for the mean','Mean|'+'Standard Deviation|'+'Sample Size |'+'Future Sample Size|'+'%
Confidence Level',in1$);
getdelimitedstring(in1$,1,s1$); xbar:=val(s1$);
getdelimitedstring(in1$,2,s1$); s:=val(s1$);
getdelimitedstring(in1$,3,n1$); n:=val(n1$);
getdelimitedstring(in1$,4,k1$); k:=val(k1$);
getdelimitedstring(in1$,5,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=xbar+vstudent(1-alpha/2,n-1)*sqrt(1/k+1/n)*s;
ll2:=xbar-vstudent(1-alpha/2,n-1)*sqrt(1/k+1/n)*s;
ul1:=xbar+vstudent(1-alpha,n-1)*sqrt(1/k+1/n)*s;
ll1:=xbar-vstudent(1-alpha,n-1)*sqrt(1/k+1/n)*s;
intv(1,1):=ul2 ; intv(2,1):=xbar; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=xbar; intv(3,2):=ll1 ; intv(4,2):=k; intv(5,2):=(1-alpha)*100 ;
title$:='Prediction Interval for a Future Mean';
goto scrl;
end;
if stat1=2 then begin
displayinputbox('Input parameters for the standard deviation','Standard Deviation|'+'Sample Size |'+'Future Sample Size|'+'%
Confidence Level',in1$);
getdelimitedstring(in1$,1,s1$); s:=val(s1$);
getdelimitedstring(in1$,2,n1$); n:=val(n1$);
getdelimitedstring(in1$,3,k1$); k:=val(k1$);
getdelimitedstring(in1$,4,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=s*sqrt(vf(1-alpha/2,k-1,n-1));
ll2:=s*sqrt(1/vf(1-alpha/2,n-1,k-1));
ul1:=s*sqrt(vf(1-alpha,k-1,n-1));
ll1:=s*sqrt(1/vf(1-alpha,n-1,k-1));
intv(1,1):=ul2 ; intv(2,1):=s; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=s; intv(3,2):=ll1 ; intv(4,2):=k; intv(5,2):=(1-alpha)*100 ;
title$:='Prediction Interval for a Future Standard Deviation';
goto scrl;
end;
if stat1=3 then begin
displayinputbox('Input parameters for all observations','Mean|'+'Standard Deviation|'+'Sample Size |'+'Future Sample
Size|'+'% Confidence Level',in1$);
getdelimitedstring(in1$,1,s1$); xbar:=val(s1$);
getdelimitedstring(in1$,2,s1$); s:=val(s1$);
getdelimitedstring(in1$,3,n1$); n:=val(n1$);
getdelimitedstring(in1$,4,k1$); k:=val(k1$);
getdelimitedstring(in1$,5,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=xbar+vstudent(1-alpha/(2*k),n-1)*sqrt((n+1)/n)*s;
ll2:=xbar-vstudent(1-alpha/(2*k),n-1)*sqrt((n+1)/n)*s;
ul1:=xbar+vstudent(1-alpha/k,n-1)*sqrt((n+1)/n)*s;
ll1:=xbar-vstudent(1-alpha/k,n-1)*sqrt((n+1)/n)*s;
intv(1,1):=ul2 ; intv(2,1):=xbar; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=xbar; intv(3,2):=ll1 ; intv(4,2):=k; intv(5,2):=(1-alpha)*100 ;
title$:='Prediction Interval for all future observations in sample k';
goto scrl;
end;
if stat1=4 then begin
displayinputbox('Input parameters for the proportion','Proportion of Successes|'+'Sample Size |'+'Future Sample Size|'+'%
Confidence Level',in1$);
getdelimitedstring(in1$,1,s1$); p:=val(s1$);
getdelimitedstring(in1$,2,n1$); n:=val(n1$);
getdelimitedstring(in1$,3,k1$); k:=val(k1$);
getdelimitedstring(in1$,4,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
ul2:=k*p+vnormal(1-alpha/2,0,1)*sqrt((k*p*(1-p)*(k+n))/n);
ll2:=k*p-vnormal(1-alpha/2,0,1)*sqrt((k*p*(1-p)*(k+n))/n);
ul1:=k*p+vnormal(1-alpha,0,1)*sqrt((k*p*(1-p)*(k+n))/n);
ll1:=k*p-vnormal(1-alpha,0,1)*sqrt((k*p*(1-p)*(k+n))/n);
intv(1,1):=ul2 ; intv(2,1):=p*k; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=p*k; intv(3,2):=ll1 ; intv(4,2):=k; intv(5,2):=(1-alpha)*100 ;
title$:='Prediction Interval for future number of successes in sample k';
goto scrl;
end;
if stat1=5 then begin
displayinputbox('Input parameters for the number of occurances','Total # Occurances|'+'Sample Size |'+'Future Sample
Size|'+'% Confidence Level',in1$);
getdelimitedstring(in1$,1,s1$); cnt:=val(s1$);
getdelimitedstring(in1$,2,n1$); n:=val(n1$);
getdelimitedstring(in1$,3,k1$); k:=val(k1$);
getdelimitedstring(in1$,4,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
lamda:=cnt/n;
ul2:=k*lamda+vnormal(1-alpha/2,0,1)*k*sqrt(lamda*(1/n+1/k));
ll2:=k*lamda-vnormal(1-alpha/2,0,1)*k*sqrt(lamda*(1/n+1/k));
ul1:=k*lamda+vnormal(1-alpha,0,1)*k*sqrt(lamda*(1/n+1/k));
ll1:=k*lamda-vnormal(1-alpha,0,1)*k*sqrt(lamda*(1/n+1/k));
intv(1,1):=ul2 ; intv(2,1):=lamda*k; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=lamda*k; intv(3,2):=ll1 ; intv(4,2):=k; intv(5,2):=(1-alpha)*100 ;
title$:='Prediction Interval for future count in sample k';
goto scrl;
end;
end;
					{TOLERANCE INTERVAL SECTION};
if type=3 then begin
displayinputbox('Input parameters for tolerance interval','Mean|'+'Standard Deviation|'+'Population Proportion|'+'Sample Size
|'+'% Confidence Level',in1$);
getdelimitedstring(in1$,1,x1$); xbar:=val(x1$);
getdelimitedstring(in1$,2,s1$); s:=val(s1$);
getdelimitedstring(in1$,3,n1$); p:=val(n1$);
getdelimitedstring(in1$,4,k1$); n:=val(k1$);
getdelimitedstring(in1$,5,a1$); alpha:=val(a1$);
alpha:=(100-alpha)/100;
a1:=1-((vnormal(1-alpha,0,1))^2)/(2*(n-1));
b1:=((vnormal(p,0,1))^2)-(((vnormal(1-alpha,0,1))^2)/n);
ul2:=xbar+vnormal((1+p)/2,0,1)*(1+(1/(2*n)))*s*sqrt((n-1)/(vchi2(alpha,n-1)));
ll2:=  xbar-vnormal((1+p)/2,0,1)*(1+(1/(2*n)))*s*sqrt((n-1)/(vchi2(alpha,n-1)));
ul1:=xbar+((vnormal(p,0,1)+sqrt(((vnormal(p,0,1))^2)-a1*b1))/a1)*s;
ll1:=  xbar-((vnormal(p,0,1)+sqrt(((vnormal(p,0,1))^2)-a1*b1))/a1)*s;
intv(1,1):=ul2 ; intv(2,1):=xbar; intv(3,1):=ll2 ; intv(4,1):=n; intv(5,1):=(1-alpha)*100 ;
intv(1,2):=ul1 ; intv(2,2):=xbar; intv(3,2):=ll1 ; intv(4,2):=n; intv(5,2):=(1-alpha)*100 ;
title$:='Tolerance Interval to include proportion p of the population';
goto scrl;
end;
scrl:
newscrollsheet(5,2,intv,title$,'Upper Limit|Point Estimate|Lower Limit|Sample Size|Confidence Level','2 Sided|1 Sided');
Back to List of Programs



[StatSoft]
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217

[StatSoft]e-mail: info@statsoft.com

©Copyright StatSoft, Inc., 1984-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.