Skip to main content

R vs SAS Confidence Intervals for Paired Proportions

Introduction

See the summary page for general introductory information on confidence intervals for proportions, including the principles underlying the most common methods.

For more technical derivation of methods for comparisons of paired proportions, see the corresponding SAS page.

Since SAS/STAT procedures do not provide direct confidence intervals for paired proportions, the %PAIRBINCI macro can be used to calculate asymptotic score confidence intervals for paired risk differences (RD) and relative risks (RR). These methods can be compared directly with the corresponding methods in the R ratesci package. SAS PROC FREQ provides McNemar’s test for paired data, but not these confidence intervals. The %PAIRBINCI macro produces results matching the scorepairci() function from {ratesci}. A workaround exists to produce the Wald normal approximation interval for paired RD using pairs as strata, but the performance of this interval is generally poor. Other methods for RD and RR would need to be manually programmed in SAS.

Methods for analysis of conditional (subject-specific) Odds Ratio from paired data are also available in R {ratesci} and {contingencytables}. These could be derived in SAS by transforming a selected method for the single proportion as described here.

Data

The following artificial dataset is used for the R and SAS examples. Each subject receives both Active and Placebo treatment, and the binary outcome is classified as either a response (Yes) or no response (No).

Placebo: Yes Placebo: No Total
Active: Yes 20 15 35
Active: No 6 5 11
Total 26 20 46

The four cells represent:

  • \(r = 20\): Both treatments resulted in a response.
  • \(s = 15\): Active resulted in a response, but Placebo did not.
  • \(t = 6\): Placebo resulted in a response, but Active did not.
  • \(u = 5\): Neither treatment resulted in a response.

General Comparison Table

The following table provides an overview of the availability of paired-proportion confidence interval methods in R and SAS.

Analysis Supported in R Supported in SAS Results Match Notes
Paired Risk Difference Yes Yes Yes, selected methods SAS %PAIRBINCI macro provides asymptotic score methods
Paired Relative Risk Yes Yes Yes, selected methods SAS %PAIRBINCI macro provides asymptotic score methods
Conditional Odds Ratio Yes Indirectly Not directly compared SAS intervals can be derived by transforming single-proportion intervals

SAS PROC FREQ provides McNemar’s test for paired data but does not directly provide all corresponding paired-proportion confidence intervals.

Matching Implementations: R and SAS

Scenario 1: Paired Risk Difference

The paired risk difference (RD) is the difference between the proportions of subjects responding to Active and Placebo treatment.

R Code Example

The ratesci package provides the rdpairci() function to calculate confidence intervals for the paired risk difference.

x <- c(20, 15, 6, 5)

ratesci::rdpairci(
  x = x,
  level = 0.95,
  precis = 6
)
[[1]]
         Test_2
Test_1    Success Failure
  Success      20      15
  Failure       6       5

$estimates
                 lower      est    upper
SCAS         -0.001869 0.195652 0.382194
SCASu         0.000423 0.195652 0.380312
Tango score   0.000419 0.195652 0.377185
MOVER-NW      0.002602 0.195652 0.369943
MOVER-NJ      0.003161 0.195652 0.373479
Wald          0.008764 0.195652 0.382541
Agresti-Min   0.003470 0.195652 0.371530
Bonett-Price -0.001006 0.195652 0.376006

$call
level    cc 
 0.95  0.00 

SAS Code Example

SAS does not provide a direct PROC FREQ option for calculating asymptotic score confidence intervals for paired risk differences. The %PAIRBINCI macro provides these methods.

/* Tango */
%pairbinci(a=20, b=15, c=6, d=5,
           contrast=RD, skew=FALSE, bcf=FALSE);

/* SCASu */
%pairbinci(a=20, b=15, c=6, d=5,
           contrast=RD, skew=TRUE, bcf=FALSE);

/* SCAS */
%pairbinci(a=20, b=15, c=6, d=5,
           contrast=RD, skew=TRUE, bcf=TRUE);

Results Comparison

Method R Lower 95% CI R Upper 95% CI SAS Lower 95% CI SAS Upper 95% CI Match
Tango Score 0.000419 0.377185 0.000419 0.377185 Yes
SCASu 0.000423 0.380312 0.000423 0.380312 Yes
SCAS -0.001869 0.382194 -0.001869 0.382194 Yes

Scenario 2: Paired Relative Risk

The paired relative risk (RR) is calculated as the ratio of the proportion of subjects responding to Active treatment to the proportion responding to Placebo treatment.

R Code Example

The ratesci package provides the rrpairci() function to calculate confidence intervals for the paired relative risk.

ratesci::rrpairci(
  x = x,
  level = 0.95,
  precis = 6
)
[[1]]
         Test_2
Test_1    Success Failure
  Success      20      15
  Failure       6       5

$estimates
                  lower      est    upper
SCAS           0.997176 1.346154 1.874279
SCASu          1.000640 1.346154 1.867063
Tang score     1.000639 1.346154 1.859820
MOVER-W        1.007274 1.346154 1.839574
MOVER-NW       1.003963 1.346154 1.844430
MOVER-NJ       1.004783 1.346154 1.851871
Wald           0.999512 1.346154 1.813015
Bonett-Price   0.995753 1.346154 1.819859
Bonett-Price-J 0.998712 1.346154 1.824452

$call
level    cc 
 0.95  0.00 

SAS Code Example

The %PAIRBINCI macro also provides asymptotic score methods for the paired relative risk.

/* Tang */
%pairbinci(a=20, b=15, c=6, d=5,
           contrast=RR, skew=FALSE, bcf=FALSE);

/* SCASu */
%pairbinci(a=20, b=15, c=6, d=5,
           contrast=RR, skew=TRUE, bcf=FALSE);

/* SCAS */
%pairbinci(a=20, b=15, c=6, d=5,
           contrast=RR, skew=TRUE, bcf=TRUE);

Results Comparison

Method R Lower 95% CI R Upper 95% CI SAS Lower 95% CI SAS Upper 95% CI Match
Tang Score (AS(Tang)) 1.000639 1.859820 1.000639 1.859820 Yes
SCASu 1.000640 1.867063 1.000640 1.867063 Yes
SCAS 0.997176 1.874279 0.997176 1.874279 Yes

Scenario 3: Conditional Odds Ratio

The conditional odds ratio (OR) for paired data is calculated using the discordant pairs:

\[OR = \frac{s}{t} = \frac{15}{6} = 2.5\]

R Code Example

The ratesci package provides the orpairci() function to calculate confidence intervals for the conditional odds ratio.

ratesci::orpairci(
  x = x,
  level = 0.95,
  precis = 6
)
[[1]]
         Test_2
Test_1    Success Failure
  Success      20      15
  Failure       6       5

$estimates
                        lower est    upper
Transformed SCASp    0.991976 2.5 6.949069
Transformed midp     0.990736 2.5 7.012904
Transformed Wilson   1.001746 2.5 6.239105
Transformed Jeffreys 1.012098 2.5 6.748258
Wald                 0.969997 2.5 6.443316

$call
level    cc 
 0.95  0.00 

The contingencytables package also provides methods for calculating confidence intervals for paired odds ratios.

SAS Implementation

SAS does not provide a direct paired odds ratio confidence interval through PROC FREQ or the %PAIRBINCI macro.

However, a conditional odds ratio confidence interval can be derived by calculating a confidence interval for the single proportion:

\[p = \frac{s}{s+t}\]

The resulting confidence limits can then be transformed to the odds ratio scale:

\[OR_{\text{lower}} = \frac{L}{1-L}\]

\[OR_{\text{upper}} = \frac{U}{1-U}\]

where (L) and (U) are the lower and upper confidence limits for the single proportion.

See the SAS paired proportions page for additional details.

Summary and Recommendation

The ratesci package in R and the %PAIRBINCI macro in SAS provide matching asymptotic score confidence intervals for paired risk differences and relative risks.

For conditional odds ratios, R provides direct functionality through ratesci, whereas SAS requires transforming a confidence interval for a single proportion.

SAS PROC FREQ can additionally produce McNemar’s test, but this does not provide the corresponding confidence interval.

The numerical comparisons demonstrate agreement between selected implementations for the example dataset. However, conclusions about the relative performance of different confidence interval methods cannot be drawn from a single example.

Additional References

R Documentation:

SAS Documentation: