R vs SAS Confidence Intervals for Proportions

Introduction

The methods to use for calculating a confidence interval (CI) for a proportion depend on the type of proportion you have.

  • 1 sample proportion (1 proportion calculated from 1 group of subjects)

  • 2 sample proportions and you want a CI for the difference in the 2 proportions.

    • If the 2 samples come from 2 independent samples (different subjects in each of the 2 groups)

    • If the 2 samples are matched (i.e. the same subject has 2 results, one on each group [paired data]).

The method selected is also dependent on whether your proportion is close to 0 or 1 (or near to the 0.5 midpoint), and your sample size.

For more technical derivation and reasons why you would use one method above another see the corresponding SAS page.

The tables below provide an overview of findings from R & SAS, for calculation of CIs, for a Single Sample Proportion and for calculation of a difference between 2 matched pair proportions or 2 independent sample proportions.

General Comparison Table For Single Sample Proportions

See the corresponding SAS page and R page for results showing a single set of data run through both SAS and R.

Analysis of One Sample Proportion Supported in R Supported in SAS Results Match
Clopper-Pearson Exact Yes {cardx} Yes (default) Yes
Normal approximation (Wald Method) Yes {cardx} Yes (default) Yes
Normal approximation (Wald Method) with continuity correction Yes {cardx} Yes Yes
Wilson (Score, Altman, Newcombe) method Yes {cardx} Yes Yes
Wilson (Score, Altman, Newcombe) method with continuity correction Yes {cardx} Yes Yes
Agresti Coull Yes {cardx} Yes Yes
Jeffreys Bayesian HPD Yes {cardx} Yes Yes
midp Yes {PropCIs} Yes results match to the 3rd decimal place
Blaker Yes {PropCIs} Yes results match to the 5th decimal place
Wilson Stratified score Yes {cardx} No NA

General Comparison Table For Two Matched Samples Proportions

Analysis of Two Matched Sample Proportions Supported in R Supported in SAS Notes
Exact method Yes {ExactCIdiff} No
Normal approximation (Wald Method) No No (proc freq does CIs for the risk difference, not the difference between two proportions) Using the equations provided in the SAS page, You could do this programatically in either package
Wilson (Score method or the Altman, Newcombe method) No No (proc freq does CIs for the risk difference, not the difference between two proportions) Using the equations provided in the SAS page, You could do this programatically in either package

Calculating the Normal approximation and Wilson methods by hand and comparing it to the Exact method gave similar results for the 1 example demonstrated indicating as long as the proportion of responders is not close to 0 or 1, then the faster computation of the approximation methods may be easier to implement than the exact method and produce similar results. Hence {ExactCIdiff} is not recommended for most scenarios.

Method Name Calculated Using matched pair example from R & SAS pages Lower 95% CI Upper 95% CI
Exact R -0.00339 0.38065
Normal by hand using equation from SAS page 0.00911 0.38289
Wilson by hand using equation from SAS page 0.00032 0.36739

General Comparison Table For Two Independent Samples Proportions

Analysis of Two Independant Sample Proportions Supported in R Supported in SAS Results Match
Normal approximation (Wald Method) Yes {cardx} ard_stats_prop_test function uses stats::prop.test Yes (default)

Yes and results match by hand calculation

Note that documentation for stats::prop.test says it’s using newcombe method. However, the results match the Normal Approximation (wald) method.

Normal approximation (Wald Method) with continuity correction Yes {cardx} as per above but with correct=TRUE Yes

Yes

Note that documentation for stats::prop.test says it’s using newcombe method. However, the results match the Normal Approximation (wald) method.

Wilson (Score, Altman, Newcombe) method No Yes SAS results match by hand calculation
Wilson (Score, Altman, Newcombe) method with continuity correction No Yes SAS results match by hand calculation

Prerequisites: R Packages

See the R page for more detail.

# Example R packages required
library(cardx)