Confidence Intervals for Paired Proportions in R

Introduction

This page covers confidence intervals for comparisons of two paired proportions in R, including risk difference (RD) \(\theta_{RD} = p_1 - p_2\) or relative risk (RR) \(\theta_{RR} = p_1 / p_2\). For odds ratio (OR) in the context of paired data, and of particular interest for case-control studies, the OR is estimated conditional on the number of discordant pairs, calculated as \(\theta_{OR} = p_{12} / p_{21}\).

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

You may experience paired data in any of the following types of situation:

  • Tumour assesssments classified as Progressive Disease or Not Progressive Disease performed by an Investigator and separately by an independent panel.

  • A paired case-control study (each subject taking active treatment is matched to a patient taking control)

  • A cross-over trial where the same subjects take both medications

In all these cases, the calculated proportions for the 2 groups are not independent, as the outcomes in each pair of observations are expected to be correlated.

Using a cross-over study as our example, a 2 x 2 table can be formed as follows:

Placebo
Response= Yes
Placebo
Response = No
Total
Active Response = Yes r s r+s
Active Response = No t u t+u
Total r+t s+u N = r+s+t+u

The table below indicates the proportions that are estimated from the data (note the difference in structure compared to the usual 2x2 table for independent proportions).

Placebo
Response= Yes
Placebo
Response = No
Total
Active Response = Yes \(p_{11}\) \(p_{12}\) \(p_1\)
Active Response = No \(p_{21}\) \(p_{22}\) \((1-p_1)\)
Total \(p_2\) \((1-p_2)\)

The proportions of subjects responding on each treatment are:

Active: \(\hat p_1 = (r+s)/N\) and Placebo: \(\hat p_2= (r+t)/N\)

The estimated difference between the proportions for each treatment is: \(D=\hat p_1 - \hat p_2 = (s-t)/N\)

The estimated relative risk is \((r+s)/(r+t)\).

The estimated conditional odds ratio is \(s/t\).

Data used

Worked examples below use the following artificial dataset:

Placebo
Response= Yes
Placebo
Response = No
Total
Active Response = Yes r = 20 s = 15 r+s = 35
Active Response = No t = 6 u = 5 t+u = 11
Total r+t = 26 s+u = 20 N = 46

The estimated paired RD is (35-26)/46 = 0.196. RR is 35/26 = 1.346, and the conditional odds ratio is 15/6 = 2.5.

Packages

The table below indicates which methods can be produced for paired RD and RR using each package. Methods are grouped by those that aim to achieve the nominal confidence interval on average, then the ‘exact’ and continuity adjusted methods that aim to achieve the nominal confidence level as a minimum. {ExactCIdiff} appears to be the only package offering an ‘exact’ method for paired RD, but run times can be prohibitively long.

For the conditional OR contrast, both {ratesci} and {contingencytables} offer a selection of transformed intervals.

ratesci contingencytables MKinfer PropCIs
For proximate coverage:
Wald/log RD,RR RD,RR RD RD
Agresti-Min RD RD - RD
MOVER-W RD,RR RR RD -
MOVER-NW (Newcombe) RD,RR RD RD
MOVER-J/-NJ RD,RR - - -
Asymptotic Score methods:
Tango/Tang RD,RR RD,RR - -
SCAS/SCASu RD,RR - - -
For conservative coverage:
Wald-cc RD RD - -
Bonett-Price-cc RR RR - -
MOVER-W/-NW-cc RD,RR - - -
MOVER-J/-NJ-cc RD,RR - - -
Tango/Tang-cc RD,RR - - -
SCAS-cc RD,RR - - -

The {ratesci} package includes the scorepairci() function for computing approximate Score confidence intervals for paired RD, RR and OR, with or without skewness correction. The moverpairci() function provides MOVER methods for paired RD and RR. The convenience functions rdpairci(), rrpairci() and orpairci() may be used for a side-by-side comparison of computed intervals for each contrast, and these include other inferior methods such as Wald and other normal approximations.

The {contingencytables} package also provides a selection of different methods, including Wald, MOVER and asymptotic score methods for RD and RR, and transformed Wald, Wilson, Clopper-Pearson and mid-P methods for OR.

The {PropCIs} package offers the diffpropci.Wald.mp and diffpropci.mp functions for RD only, which give the Wald and Agresti-Min adjusted Wald methods respectively.

The {MKinfer} package provides binomDiffCI() with a paired argument to cater for paired data. When the recommended method = "wilson-cc" is used, the MOVER-Wilson method for RD is produced, incorporating Newcombe’s adjustment to the estimated correlation (note that here the ‘cc’ does not refer to a ‘continuity correction’ in the usual sense).

The {ExactCIdiff} package produces exact CIs for paired RD with the PairedCI() function. However, it should only be used when the sample size is not too large as it can be computationally intensive with prohibitively long run times.

Paired Proportion Difference

For technical details on the methods for calculating confidence intervals for a paired RD see the corresponding SAS page.

From our example dataset, we have estimates as follows: \(\hat p_1 = (r+s)/n\) = 35/46 = 0.761 and \(\hat p_2= (r+t)/n\) = 26/46 = 0.565

Difference = 0.761-0.565 = 0.196, then selected confidence intervals can be obtained from R as shown below:

Example code for {ratesci}

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

# Selected methods for proximate coverage:
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 

Example code for {contingencytables}

xmat <- matrix(x, nrow = 2, byrow = TRUE)
contingencytables::the_paired_2x2_table_CIs_difference(xmat)
Estimate of pi_1+: 35/46 = 0.761
Estimate of pi_+1: 26/46 = 0.565
Estimate of delta = pi_1+ - pi_+1: 0.196

Interval method                           95% CI         width
--------------------------------------------------------------
Wald                                 0.0088 to  0.3825   0.374
Wald w/continuity correction         0.0070 to  0.3843   0.377
Wald w/Agresti-Min adjustment        0.0035 to  0.3715   0.368
Wald w/Bonett-Price adjustment      -0.0010 to  0.3760   0.377
Newcombe square-and-add              0.0026 to  0.3699   0.367
Tango asymptotic score               0.0004 to  0.3772   0.377
--------------------------------------------------------------

Paired Relative Risk

For technical details on the methods for calculating confidence intervals for a paired RR see the corresponding SAS page.

Example code for {ratesci}

# Selected methods for proximate coverage:
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.34615 1.87428
SCASu          1.000640 1.34615 1.86706
Tang score     1.000639 1.34615 1.85982
MOVER-W        1.007274 1.34615 1.83957
MOVER-NW       1.003963 1.34615 1.84443
MOVER-NJ       1.004783 1.34615 1.85187
Wald           0.999512 1.34615 1.81302
Bonett-Price   0.995753 1.34615 1.81986
Bonett-Price-J 0.998712 1.34615 1.82445

$call
level    cc 
 0.95  0.00 

Example code for {contingencytables}

contingencytables::the_paired_2x2_table_CIs_ratio(xmat)

Estimate of pi_1+: 35/46 = 0.761
Estimate of pi_+1: 26/46 = 0.565
Estimate of phi = pi_1+/pi_+1: 1.346

Interval method                              95% CI        log width
--------------------------------------------------------------------
Wald                                    0.9995 to  1.8130     0.595
Tang asymptotic score                   1.0006 to  1.8598     0.620
Bonett-Price hybrid Wilson score        0.9958 to  1.8199     0.603
Bonett-Price hybrid Wilson score w/CC   0.9631 to  1.8822     0.670
MOVER Wilson score                      1.0073 to  1.8396     0.602
--------------------------------------------------------------------
CC = continuity correction

Conditional Odds Ratio

For technical details on the methods for calculating confidence intervals for a conditional OR from paired date see the corresponding SAS page.

Example code for {ratesci}

# Selected methods for proximate coverage:
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.94907
Transformed midp     0.990736 2.5 7.01290
Transformed Wilson   1.001746 2.5 6.23911
Transformed Jeffreys 1.012098 2.5 6.74826
Wald                 0.969997 2.5 6.44332

$call
level    cc 
 0.95  0.00 

Example code for {contingencytables}

contingencytables::the_paired_2x2_table_CIs_OR(xmat)
Estimate of theta_cond = n_12/n_21: 2.500

Interval method                              95% CI        log width
--------------------------------------------------------------------
Wald                                    0.9700 to  6.4433     1.894
Wald with Laplace adjustment            0.9403 to  5.5559     1.776
Transformed Wilson score                1.0017 to  6.2391     1.829
Transformed Clopper-Pearson exact       0.9166 to  7.8645    2.149
Transformed Clopper-Pearson mid-P       0.9907 to  7.0129     1.957
Transformed Blaker exact                0.9761 to  6.5501     1.904
--------------------------------------------------------------------

Continuity Adjusted Methods

There are relatively few methods widely available for aligning the minimum coverage with the nominal confidence level. The most versatile option is to use functions from the {ratesci} package, which provides optional continuity adjustments, on a sliding scale from 0 to \(0.5/N\), for any of the Asymptotic Score or MOVER methods for any contrast.

Example code for {ratesci}

# Selected methods for conservative coverage 

# Using the conventional 0.5 
ratesci::rdpairci(x = x,
                  level = 0.95,
                  cc =0.5,
                  precis = 6)
[[1]]
         Test_2
Test_1    Success Failure
  Success      20      15
  Failure       6       5

$estimates
                   lower      est    upper
SCAS_cc        -0.024953 0.195652 0.403306
SCASu_cc       -0.022654 0.195652 0.401446
Tango score_cc -0.022450 0.195652 0.398076
MOVER-NW_cc    -0.012496 0.195652 0.383201
MOVER-NJ_cc    -0.012233 0.195652 0.386940
Wald_cc         0.006977 0.195652 0.384327

$call
level    cc 
 0.95  0.50 
# Using an intermediate adjustment of magnitude 0.25 

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

$estimates
                         lower      est    upper
SCAS_cc(0.25)        -0.013413 0.195652 0.392761
SCASu_cc(0.25)       -0.011117 0.195652 0.390890
Tango score_cc(0.25) -0.011018 0.195652 0.387642
MOVER-NW_cc(0.25)    -0.004949 0.195652 0.376573
MOVER-NJ_cc(0.25)    -0.004550 0.195652 0.380223
Wald_cc(0.25)         0.007842 0.195652 0.383462

$call
level    cc 
 0.95  0.25 

Consistency with Hypothesis Tests

Test for association

The Asymptotic Score methods for all contrasts based on paired data are inherently consistent with the McNemar \(\chi^2\) test if the ‘N-1’ adjustment is omitted with bcf = FALSE.

Non-inferiority test

One important use for CIs for proportions is in the analysis of clinical trials aiming to demonstrate non-inferiority. The Asymptotic Score methods are naturally suited for this purpose, as they are derived by inverting a score test statistic, so that the hypothesis test for any null hypothesis value of the contrast parameter is guaranteed to be consistent with the confidence interval. A one-sided non-inferiority test may be obtained with the scorepairci function (for example, with a non-inferiority margin of RD = 0.4) as follows:

ratesci::scorepairci(x = x,
                  level = 0.95,
                  theta0 = 0.4,
                  precis = 6)$pval
       chisq pval2sided theta0 scorenull pval_left pval_right
[1,] 3.77329   0.052077    0.4  -2.14678 0.0159052   0.984095

References