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)
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.
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.
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.