Exact Confidence Intervals for a Single Proportion

Theodora Chatzimichail, MD  
tc@hcsl.com
Aristides T. Hatjimihail, MD, PhD
 ath@hcsl.com

Hellenic Complex Systems Laboratory, Kostis Palamas 21, 66131 Drama, Greece.

Initialization Code

ci[x_,n_,cl_]:=Quiet[Module[
{a},
a=(x+1)InverseCDF[FRatioDistribution[2(x+1),2(n-x)],((1+cl)/2)];
{(x/(x+(n-x+1)InverseCDF[FRatioDistribution[2(n-x+1),2x],((1+cl)/2)])),(a/((n-x)+a))}
]]

r[x_,n_,p_]:=(x/n)

pl[p_]:= If[p<0.051,0.001,If[0.999-p>0.05,p-0.05,0.899]]

pu[p_]:= If [0.999-p<0.05,0.999,If[p<0.051,0.101,p+0.05]]

pop[x_,n_]:=Text@Grid[Transpose[{{"population statistics","population obeying condition","total population"},{SpanFromLeft,x,n}}],Frame->All, FrameStyle->Blend[{Blue,Cyan},0.35],Spacings->{1,1},ItemSize->{{18,5},Automatic}]

prci[x_,n_,cl_]:=Text@Grid[Transpose[{{StringJoin[ToString[100 cl], "% confidence interval of the proportion"],"point estimation","lower bound","upper bound"},{SpanFromLeft,ToString[NumberForm[N@(x/n),{6,3}]],ToString[NumberForm[N@ci[x,n,cl][[1]],{6,3}]],ToString[NumberForm[N@ci[x,n,cl][[2]],{6,3}]]}}
],Frame->All, FrameStyle->Orange,Spacings->{1,1},ItemSize->{{20,6},Automatic}]

Manipulate[
Grid[{{
Pane[pop[x,x+y], {320,80},Alignment->Center]},
{prci[x,x+y,cl]},{Plot[{ci[x,x+y,p][[1]],r[x,x+y,p],ci[x,x+y,p][[2]]},{p,pl[cl],pu[cl]}, PlotLegends->Placed[{"CI lower bound", "point estimation","CI upper bound"},Above],AxesLabel->{Style["p",Italic],"proportion"}, AspectRatio->0.55,ImageSize-> {350,200}]}},Spacings->{0,2}],
"population ",
"obeying the condition",
{{x,90,""},1,200,1,Appearance->"Labeled",ImageSize->Tiny},"",
"violating the condition",
{{y,10,""},1,200,1,Appearance->"Labeled",ImageSize->Tiny} ,Delimiter,
Row[{Style["p",Italic],"-value"}],
{{cl,0.95,""},0.001,0.999,0.001,Appearance->"Labeled", ImageSize->Tiny},"",
ControlPlacement->Left, ContinuousAction->False,SaveDefinitions->True,ContentSize->{480, 500},Alignment->Center]

Description

This Demonstration shows calculations of point estimations and confidence intervals for various single proportions of populations obeying a condition (or trait), as well as their plots versus p-value. This is done for differing populations obeying and violating a condition (or trait) and differing p-values for estimating the lower and upper bounds of the confidence intervals.

Snapshots

Details

The exact method using the F-distribution is applied for calculating the confidence interval of each single proportion [1].

Reference

[1] J. L. Fleiss, B. Levin and M. C. Paik, Statistical Methods for Rates and Proportions, 3rd ed., Hoboken, NJ: J. Wiley, 2003.

Keywords

proportion
confidence interval
exact method
F distribution
inference

Disclaimer of Warranties

The notebook is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or Hellenic Complex Systems Laboratory or any of its members be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the notebook or the use or other dealings in the notebook.

About

Exact Confidence Intervals for a Single Proportion
Version Number 1.1.0
Hellenic Complex Systems Laboratory 2021
First published at Wolfram Demonstrations Project at: (HyperlinkURL["demonstrations.wolfram.com/ExactConfidenceIntervalsForASingleProportion/", https://demonstrations.wolfram.com/ExactConfidenceIntervalsForASingleProportion/])
The notebook is distributed under  an Attribution - NonCommercial - ShareAlike 4.0 International Creative Commons License.