Inferences about the Difference between Two Proportions

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

cidp[x1_,x2_,y1_,y2_,cl_]:=Block[{z=InverseCDF[NormalDistribution[0,1],((1+cl)/2)],p1=(x1/(x1+y1)),n1=x1+y1,p2=(x2/(x2+y2)),n2=x2+y2,q1=1-p1, q2=1-p2},{p2-p1-z(Sqrt[Abs[((p1 q1)/n1)-((p2 q2)/n2)]])-(1/2)((1/n1)+(1/n2)),p2-p1+z(Sqrt[Abs[((p1 q1)/n1)-((p2 q2)/n2)]])+(1/2)((1/n1)+(1/n2))}]

pdp[x1_,x2_,y1_,y2_]:=Block[{p1=(x1/(x1+y1)),n1=x1+y1,p2=(x2/(x2+y2)),n2=x2+y2},CDF[NormalDistribution[0,1],((Abs[p2-p1]-(1/2)((1/n1)+(1/n2)))/(Sqrt[Abs[((x1+x2)/(n1+n2))(1-((x1+x2)/(n1+n2)))((1/n1)+(1/n2))]]))]]

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]]

dif[x1_,x2_,y1_,y2_,cl_]:=(x2/(x2+y2))-(x1/(x1+y1))

fodif[x1_,x2_,y1_,y2_]:=Text@Grid[Transpose[{{"first proportion","second proportion","difference (point estimation)","statistical significance of the difference"},{ToString[NumberForm[N[(x1/(x1+y1))],{6,3}]],ToString[NumberForm[N[(x2/(x2+y2))],{6,3}]],ToString[NumberForm[N[(x2/(x2+y2))-(x1/(x1+y1))],{6,3}]],ToString[NumberForm[N@pdp[x1,x2,y1,y2],{6,3}]]}}],Frame->All, FrameStyle->Blend[{Blue,Cyan},0.35],Spacings->{1,1},ItemSize->{{24,8},Automatic}]

foci[x1_,x2_,y1_,y2_,cl_]:=Text@Grid[Transpose[{{StringJoin[ToString[100 cl], " percent confidence interval for the difference"],"lower bound","upper bound"},{SpanFromLeft,ToString[NumberForm[N@cidp[x1,x2,y1,y2,cl][[1]],{6,3}]],ToString[NumberForm[N@cidp[x1,x2,y1,y2,cl][[2]],{6,3}]]}}
],Frame->All, FrameStyle->Orange,Spacings->{1,1},ItemSize->{{24,8},Automatic}]

Manipulate[
Grid[{{Pane[fodif[x1,x2,y1,y2], 1.25{350,100},Alignment->Center]},{Pane[foci[x1,x2,y1,y2,cl], 1.25{350,80},Alignment->Center]},{Pane[Plot[{cidp[x1,x2,y1,y2,pr][[1]],dif[x1,x2,y1,y2,pr],cidp[x1,x2,y1,y2,pr][[2]]},{pr,pl[cl],pu[cl]}, PlotLegends->Placed[{"CI lower bound", "point estimation","CI upper bound"},Above],AxesLabel->{Style["p",Italic],"difference"}, AspectRatio->0.55],Alignment->Center]}}],
"first population","",
"population obeying the condition",
{{x1,90,""},1,100000,1,Appearance->"Labeled",ImageSize->Tiny},"",
"population without the condition",
{{y1,10,""},1,100000,1,Appearance->"Labeled",ImageSize->Tiny} ,"",Delimiter,
"second population","",
"population obeying the condition",
{{x2,850,""},1,100000,1,Appearance->"Labeled",ImageSize->Tiny},"",
"population without the condition",
{{y2,150,""},1,100000,1,Appearance->"Labeled",ImageSize->Tiny} ,"",Delimiter,
Row[{Style["p",Italic],"\[Hyphen]value"}],
{{cl,0.95,""},0.001,0.999,0.001,Appearance->"Labeled", ImageSize->Tiny},"",
ControlPlacement->Left, ContinuousAction->False, SaveDefinitions->True]

Description

This Demonstration explores statistical inferences regarding the difference between two proportions of populations obeying a condition (or trait). It calculates the statistical significance and the confidence intervals for the difference and plots the confidence intervals versus p-value. This is done for differing populations obeying a condition or without the condition and for differing p-values for the estimation of the confidence intervals.

Snapshots

Details

The statistical significance of the difference between the two proportions is assessed by means of the z-score (or critical ratio statistic) [1]. The confidence interval for the difference between the proportions is calculated as in [2].

References

[1] J. L. Fleiss, B. Levin and M. C. Paik, "Methods for Generating a Fourfold Table," Statistical Methods for Rates and Proportions, 3rd ed., Hoboken, NJ: J. Wiley, 2003 pp. 51–52.

[2] J. L. Fleiss, B. Levin and M. C. Paik, "A Simple Confidence Interval for the Difference between Two Independent Proportions," Statistical Methods for Rates and Proportions, 3rd ed., Hoboken, NJ: J. Wiley, 2003 pp. 60–61.

Keywords

proportions
difference between proportions
confidence interval
inference
critical ratio statistic
statistical significance
statistics

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

Inferences about the Difference between Two Proportions
Version Number 1.1.0
Hellenic Complex Systems Laboratory 2021
First published at Wolfram Demonstrations Project at: (HyperlinkURL["demonstrations.wolfram.com/InferencesAboutTheDifferenceBetweenTwoProportions/", https://demonstrations.wolfram.com/InferencesAboutTheDifferenceBetweenTwoProportions/])
The notebook is distributed under  an Attribution - NonCommercial - ShareAlike 4.0 International Creative Commons License.