Chapter 8 Analysis of binary outcomes
Binary outcomes are ubiquitous in medical research and the comparison of binary outcomes in RCTs is very common. This chapter discusses various statistical quantities that can be calculated for comparing binary outcomes. We discuss statistical tests, suitable effect measures and methods to adjust for possible baseline variables.
8.1 Comparison of two proportions
Throughout this section, we will work with the following example.
Example 8.1 The APSAC Study is an RCT to compare a new thrombolytikum (APSAC) with the standard treatment (Heparin) in patients with acute cardiac infarction (Meinertz, Kasper, and Just 1988). The outcome is mortality within 28 days of hospital stay. Table 8.1 summarizes the results of this study, including 95% Wilson CIs for the proportion of patients who died in the respective treatment groups.
Therapy | Dead | Alive | Total | Percent Dead | Standard Error | 95% Wilson-CI |
---|---|---|---|---|---|---|
APSAC | 9 | 153 | 162 | 5.6% | 1.8% | 0.04 to 0.07 |
Heparin | 19 | 132 | 151 | 12.6% | 2.7% | 0.1 to 0.2 |
Total | 28 | 285 | 313 |
A visual comparison for the two separate CIs in Figure 8.1 shows that they overlap. However, overlapping CIs are not necessarily an indication for a non-significant treatment effect. Instead, we should rather look at CIs for combined effect measures such as the ones defined in Definition 8.1.

Figure 8.1: 95% Wilson confidence intervals for the death risks in the APSAC Study.
8.1.1 Statistical tests
Commonly used tests to compare two proportions are the and Fisher’s “exact” test, explained in Appendix B. The null hypothesis in these tests is that there is no difference between groups. Both methods give a P-value, but no effect measure. There is a second version of the χ2-test with continuity correction. There are at least three different versions to calculate the two-sided P-value for Fisher’s exact’’ test (see the package for details). Fisher’s exact test should be used for small samples.
Example 8.2 R code for statistical tests comparing two proportions in the APSAC Study:
## dead alive
## APSAC 9 153
## Heparin 19 132
## dead alive
## APSAC 14.49201 147.508
## Heparin 13.50799 137.492
##
## Pearson's Chi-squared test with Yates' continuity
## correction
##
## data: APSAC.table
## X-squared = 3.9146, df = 1, p-value = 0.04787
##
## Pearson's Chi-squared test
##
## data: APSAC.table
## X-squared = 4.7381, df = 1, p-value = 0.0295
##
## Fisher's Exact Test for Count Data
##
## data: APSAC.table
## p-value = 0.04588
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 0.1576402 0.9892510
## sample estimates:
## odds ratio
## 0.409812
Note that the function fisher.test also provides an odds ratio (with 95% CI) as effect measure. The output from the χ2-test can also be used to compute an estimate of the relative risk based on the observed to expected death ratios:
mytest <- chisq.test(APSAC.table)
o <- mytest$observed[,"dead"]
e <- mytest$expected[,"dead"]
print(ratio <- (o/e))
## APSAC Heparin
## 0.6210317 1.4065752
## APSAC
## 0.4415205
8.1.2 Effect measures and confidence intervals
Let π0 and π1 be the true’’ risks of death in the Control and APSAC group, respectively with π0≥π1. The following quantities are used to compare π0 and π1:
Definition 8.1 The absolute risk reduction is defined as ARR=π0−π1.
The number needed to treat is defined as NNT=1/ARR.
The relative risk is defined as RR=π1/π0.
The relative risk reduction is defined as RRR=ARRπ0=1−RR.
The odds ratio is defined as OR=π1/(1−π1)π0/(1−π0).
No difference between groups (i.e. π0=π1) corresponds to ARR=RRR=0 and RR=OR=1. We now discuss each of these effect measures together with their CIs for the example of the APSAC Study.
8.1.2.1 Absolute Risk Reduction
The ARR is also called risk difference (RD) or probability difference. The estimated ARR
^ARR = 12.6%−5.6%=7%
with standard error
se(^ARR)=√ˆπ0(1−ˆπ0)n0+ˆπ1(1−ˆπ1)n1=3.2%
Here we obtain se(^RD)=3.2%. can be used to calculate a Wald CI for the ARR. An improved Wilson CI for the ARR can be calculated using the square-and-add’’ approach (Robert G. Newcombe 1998b,Newcombe), see Appendix A.2.3 for details. (Newcombe, 1998).
Example 8.3 The following R code provides both Wald and Wilson CIs for the ARR in the APSAC Study. They are visually compared in Figure 8.2. There are no large differences between the two types of confidence intervals, only the upper limit of the Wilson is slightly larger than the corresponding Wald upper limit.
## $rd
## [,1]
## [1,] 0.07027226
##
## $CIs
## type lower upper
## 1 Wald 0.006691788 0.1338527
## 2 Wilson 0.006303897 0.1378381
The lower plot in Figure 8.2 illustrates the distinct advantage of the Wilson CI that it avoids overshoot with artificial data. Indeed, the upper limit of the Wald confidence interval for the risk difference is larger than 1 whereas this is not the case for the Wilson interval.
## $rd
## [,1]
## [1,] 0.8333333
##
## $CIs
## type lower upper
## 1 Wald 0.6121830 1.054484
## 2 Wilson 0.4507227 0.930162

Figure 8.2: Wald and Wilson CIs for the ARR in the APSAC Study (upper plot) and in an example with artifical data illustrating overshoot (lower plot).
8.1.2.2 Number Needed to Treat
Suppose we have n patients in each treatment group. The expected number of deaths in the control and intervention group are: N0=nπ0,N1=nπ1. The difference is therefore N0−N1=n(π0−π1). Suppose we want the difference N0−N1 to be one patient. The required sample size n to achieve this is n=1/(π0−π1)=1/ARR. This is the number needed to treat, the required number of patients to be treated with the intervention rather than control to avoid one death. Depending on the direction of the effect, the NNT is also called number needed to benefit or number needed to harm.
The interpretation of the estimated NNT % ^NNT = 1/^ARR = 1/0.07 = 14.2 % in the APSAC study is the following: To avoid one death, we need to treat ^NNT=14.2 patients with APSAC rather than with Heparin. A CI for NNT can be obtained by inverting the limits L\scriptsize ARR and U\scriptsize ARR of the CI for ARR.
Example 8.4 The following R code shows this for the APSAC Study.
## type lower upper
## 2 Wilson 0.006303897 0.1378381
## lower upper
## 2 7.3 158.6
The CI for NNT in the APSAC Study is: 1/0.138 to 1/0.006 = 7.3 to 158.6.
Note that the CI for NNT is only well-defined as long as the CI for ARR does not contain 0. Otherwise, the confidence interval is actually a confidence region, comprising two different intervals depending on the direction of the treatment effect (Douglas G. Altman 1998). This problem can be circumvented by plotting the number needed to treat on the absolute risk reduction scale, as illustrated in the following example.
Example 8.5 Figure 8.3 shows a forest plot from Douglas G. Altman (1998) where an overall number needed to benefit is calculated from a meta-analysis of data from randomized trials comparing bypass surgery with coronary angioplasty in relation to angina in one year. For three studies (CABRI, RITA, EAST) the 95% confidence interval for NNT is a regular interval and includes only values that indicate a benefit of therapy. However, for two other entries (GABI and Other) the confidence region for NNT splits into two intervals. For example, for GABI the two intervals are 7.5 to infinity for benefit and 14.5 to infinity for harm. This indicates that this trial is inconclusive regarding the direction of the treatment effect with large uncertainty regarding the actual value of NNT.
![Forest plot for NNT in a meta-analysis [@altman1998].](figures/altd5400_f3.jpg)
Figure 8.3: Forest plot for NNT in a meta-analysis (Douglas G. Altman 1998).
8.1.2.3 Relative Risk
The RR is also called risk ratio. The estimated death risks in both treatment groups are
- x1/n1=9/162=5.6% for APSAC and
- x0/n0=19/151=12.6% for Heparin.
The estimated RR is therefore
^RR=5.6%12.6%=0.44.
The calculation of a CI for the RR is based on the RR as explained in Table 8.3. With the standard error of the log RR
se(log(^RR))=√1x1−1n1+1x0−1n0
and the corresponding EF.95=exp{1.96⋅se(log(^RR))}, we can directly calculate the limits of the CI for the RR as
^RR/EF.95 and ^RR⋅EF.95.
Example 8.6 This calculation is implemented in the function from package .
## lower Risk Ratio upper
## 0.2061781 0.4415205 0.9454948
We can see that the data are compatible with a relative risk between 0.21 and 0.95.
Quantity | Estimate | Standard Error | 95%-confidence interval |
---|---|---|---|
RR | 0.44 |
|
0.21 to 0.95 |
↓ log ↓ | ↑ exp ↑ | ||
RR | -0.82 | 0.39 | -1.58 to -0.06 |
The square-and-add method can also be applied to ratio measures such as the risk ratio R. G. Newcombe (2013) (Section 7.3.4), but this is rarely used in practice. One reason might be that the simple approach (8.1) based on error factors is - by construction - not prone to overshoot below zero.
8.1.2.4 Relative Risk Reduction
Either ARR or RR can be used to estimate RRR: ^RRR=^ARRˆπ0 = 0.070.126 = 56% or^RRR=1−^RR = 1−0.44 = 56% A CI for RRR can be obtained based on the limits L\scriptsize RR and U\scriptsize RR of the CI for RR:
(1−U\scriptsize RR) to (1−L\scriptsize RR)=(1−0.95) to (1−0.21)=0.05 to 0.79
So, the risk of death with APSAC has been reduced by 56% (95% CI: 5% to 79%) compared to Heparin.
8.1.2.5 Odds Ratio
Yes | No | Total | |
---|---|---|---|
APSAC | a=9 | b=153 | 162 |
Heparin | c=19 | d=132 | 151 |
n=313 |
From Table 8.4, we can read that the estimated odds of death for APSAC are a/b=9/153 (c/d=19/132 for Heparin). The estimated OR is therefore ^OR=a/bc/d=9/15319/132=9⋅132153⋅19 =0.41. This means that the odds of death are under APSAC 59% lower than under Heparin treatment. The formulation ^OR=(a⋅d)/(b⋅c) motivates the alternative name cross-product ratio.
Dead | Alive | Total | Percent Alive | Standard Error | 95% CI | |
---|---|---|---|---|---|---|
APSAC | 9 | 153 | 162 | 94.4% | 1.8% | 98.0 to 90.9% |
Heparin | 19 | 132 | 151 | 87.4% | 2.7% | 92.7 to 82.1% |
An advantage of the ORs is that they can be inverted for complementary events. If we consider the survival probability rather than the death risk as in Table 8.6, we can see that:
- The odds ratio for death risk is OR=0.41.
- The odds ratio for survival then is
(1−π1)/π1(1−π0)/π0=π0/(1−π0)π1/(1−π1)=1/OR=1/0.41=2.45.
Such a relationship does not hold for relative risks: 1/RR=1/0.44=2.25, but 94.4%/87.4%=1.08.
A disadvantage of the ORs is their noncollapsibility (S. Senn 2021). Consider an example: Table 8.8 presents a contingency table stratified by strata while Table 8.10 present the collapsed contingeny table.
Yes | No | Total | Yes | No | Total | |
---|---|---|---|---|---|---|
Therapy A | 10 | 20 | 30 | 15 | 25 | 40 |
Therapy B | 30 | 40 | 70 | 35 | 45 | 80 |
Yes | No | Total | |
---|---|---|---|
Therapy A | 10 | 20 | 30 |
Therapy B | 30 | 40 | 70 |
The OR for Stratum 1 is OR=10⋅4020⋅30=2.67
The OR for Stratum 2 is OR=15⋅4525⋅35=2.67
The OR from the collapsed analysis is OR=10⋅4020⋅30=2.53
[→] The ORs are the same in both strata, but the OR collapsed over strata is different
As for RR (see Table 8.3), we calculate the standard error of the OR on the log scale: se(log(^OR))=√1a+1b+1c+1d
The CI can be directly calculated using the 95% error factor % EF.95=exp{1.96⋅se(log(^OR))} Note that CIs for odds ratios may differ even if group sample sizes remain the same:
## lower Odds Ratio upper
## 0.4565826 1.0000000 2.1901841
## lower Odds Ratio upper
## 0.06081319 1.00000000 16.44380070
8.1.2.6 Odds Ratios and Relative Risks
There are the following relations between the OR and the RR:
- If π0=π1 then OR=RR=1
- OR and RR always go in the same direction (<1 or >1)
- If <1, then OR<RR
- If >1, then OR>RR
- Rare disease assumption: If disease risks π0 and π1 are small, then OR≈RR
Example 8.7 The twoby2 function from the R package Epi computes the RR (relative risk), OR (in two versions) and ARR (probability difference). The second version of the odds ratio is the conditional Maximum Likelihood estimate under a hypergeometric likelihood function. There is no closed-form expression for this estimate, which may explain why it is rarely used, but it is compatible to the p-value from Fisher’s exact test (denoted here as Exact P-value).
## 2 by 2 table analysis:
## ------------------------------------------------------
## Outcome : dead
## Comparing : APSAC vs. Heparin
##
## dead alive P(dead) 95% conf. interval
## APSAC 9 153 0.0556 0.0292 0.1033
## Heparin 19 132 0.1258 0.0817 0.1889
##
## 95% conf. interval
## Relative Risk: 0.4415 0.2062 0.9455
## Sample Odds Ratio: 0.4087 0.1788 0.9340
## Conditional MLE Odds Ratio: 0.4098 0.1576 0.9893
## Probability difference: -0.0703 -0.1378 -0.0063
##
## Exact P-value: 0.0459
## Asymptotic P-value: 0.0338
## ------------------------------------------------------
Compatible p-values can be obtained for each of these effect estimates and the corresponding standard error. They will be similar, but not identical:
## transform normal test statistic z to two-sided p-value
z2p <- function(z) return(2*(1-pnorm(abs(z))))
z <- c(arr/se.arr, log(rr)/se.log.rr, log(or)/se.log.or)
names(z) <- c("risk difference", "log relative risk", "log odds ratio")
pvalues <- z2p(z)
formatPval(pvalues)
## [1] "0.03" "0.04" "0.03"
The one for OR is called in .
8.1.2.7 Absolute and relative effect measures
Let us consider an example of an RCT with death risk={0.3%in the placebo group0.1%in the treatment group Then we have ARR=0.2%=0.002 and NNT=500, so there is a very small absolute effect of treatment. However, we have RR=1/3 and RRR=2/3=67%, so there is a large relative effect of treatment. We cannot transform absolute to relative effect measures (and vice versa) without knowledge of the underlying risks.
8.2 Adjusting for baseline
For binary outcomes, adjusting for baseline variables is usually done using logistic regression and will produce adjusted odds ratios. Alternatively, the Mantel-Haenszel method (MH) can be used, which gives a weighted average of strata-specific odds ratios. The MH method can also be applied to strata-specific risk ratios. However, adjustment for continuous variables using MH is only possible after suitable categorization.
8.2.1 Logistic regression
Example 8.8 PUVA
The PUVA trial compares PUVA (drug followed by UVA exposure) versus TL-01 lamp therapy for treatment of psoriasis. The primary outcome is yes if the patient was clear of psoriasis at or before the end of the treatment, and no otherwise. The treatment allocation used RPBs stratified according to whether predominant plaque size was large or small. This ensures a balanced distribution in treatment arms (29:22 vs. 28:21).
## plaqueSize treatment cleared total
## 1 Small TL-01 23 29
## 3 Small PUVA 25 28
## 2 Large TL-01 9 22
## 4 Large PUVA 16 21
Unadjusted analysis:
m1 <- glm(cbind(cleared, total-cleared) ~ treatment,
data=puva, family=binomial)
## tableRegression gives profile confidence intervals
knitr::kable(tableRegression(m1, latex = FALSE))
Odds Ratio | 95%-confidence interval | p-value | |
---|---|---|---|
treatmentTL-01 | 0.33 | from 0.12 to 0.82 | 0.021 |
With standard formulae (p. 18):
## puva$treatment
## TL-01 PUVA
## 32 41
## puva$treatment
## TL-01 PUVA
## 51 49
## lower Odds Ratio upper
## 0.13 0.33 0.85
Strata-specific estimates:
m2Small <- glm(cbind(cleared, total-cleared) ~ treatment,
subset=(plaqueSize=="Small"), data=puva, family=binomial)
knitr::kable(tableRegression(m2Small, latex = FALSE))
Odds Ratio | 95%-confidence interval | p-value | |
---|---|---|---|
treatmentTL-01 | 0.46 | from 0.09 to 1.96 | 0.31 |
m2Large <- glm(cbind(cleared, total-cleared) ~ treatment,
subset=(plaqueSize=="Large"), data=puva, family=binomial)
knitr::kable(tableRegression(m2Large, latex = FALSE))
Odds Ratio | 95%-confidence interval | p-value | |
---|---|---|---|
treatmentTL-01 | 0.22 | from 0.05 to 0.77 | 0.023 |
Adjusted analysis with logistic regression:
m3 <- glm(cbind(cleared, total-cleared) ~ treatment + plaqueSize,
data=puva, family=binomial)
knitr::kable(tableRegression(m3, latex = FALSE))
Odds Ratio | 95%-confidence interval | p-value | |
---|---|---|---|
treatmentTL-01 | 0.30 | from 0.10 to 0.78 | 0.017 |
plaqueSizeLarge | 0.24 | from 0.09 to 0.61 | 0.004 |
The adjusted treatment effect is ^OR=0.30 with 95% CI from 0.10 to 0.78. Logistic regression also quantifies the effect of the variable used for adjustment, here plaque size.
8.3 Additional references
Relevant references for this chapter are in particular Chapters 13 “The Analysis of Cross-Tabulations” and 15.10 “Logistic Regression” in M. Bland (2015) as well as Chapter 7.1–7.4 “Further Analysis: Binary Data” in J. N. S. Matthews (2006). The use of odds ratios is discussed in Sackett, Deeks, and Altman (1996) and Douglas G. Altman, Deeks, and Sackett (1998). Studies where the methods from this chapter are used in practice are for example Heal et al. (2009),fagerstroem and Vadillo-Ortega et al. (2011).