9  Measures of Association in Cohort Studies

The P value, which is the final common pathway for almost all statistical tests, conveys no information about the extent to which two groups differ or two variables are associated. Highly “significant” P values can accompany negligible differences (if the study is large) and unimpressive P values can accompany strong associations (if the study is small). P values, therefore, are not good measures of the strength of the relation between study variables. (Rothman 1978)

9.1 Measures of association

A measure of association indicates both the direction and magnitude of the difference between two groups, so a point and interval estimate of a measure of association conveys much more information than a hypothesis test (Rothman 1978). We will first consider measures of association in cohort studies, where participants are selected based on exposure and then followed up (prospectively or retrospectively) to measure disease occurrence. As before, let \(X\) be a binary treatment or exposure, and let \(D\) be a binary disease outcome. We assume that the exposure \(X_i\) of person \(i\) is fixed by his or her time origin, that our study sample consists of individuals who were at risk of the outcome, and that there was no left truncation (i.e., delayed entry) or right censoring due to loss to follow-up. Our results can be summarized in a 2x2 table as in Table 2.1.

Ideally, the groups in a cohort study are identical except for exposure so that any difference in the outcomes can be attributed to a causal effect of the difference in exposure. In a clinical trial, this similarity can be achieved by randomizing participants to different levels of exposure. If the number of study participants is large enough, the different groups will be nearly identical in both measured and unmeasured covariates. In an observational study, exposure groups can have differences other than exposure that completely or partially explain the observed differences in outcomes, which is called confounding (Simpson 1951; O. S. Miettinen and Cook 1981). For now, we will not worry about whether the differences between groups are causal effects of treatment or exposure, which is why we call these measures of association.

9.1.1 Risk difference

If the risk of disease onset in \((0, t]\) is \(p_1\) in the exposed and \(p_0\) in the unexposed, then the risk difference is \[ \RD = p_1 - p_0, \] which can take any value in \([-1, 1]\). When exposure and disease are independent, \(\RD = 0\) because \(p_1 = p_0\) (see Section 7.2.1).

When there is no delayed entry or loss to follow-up, the risk (cumulative incidence) in any given time interval \((0, t]\) can be estimated using methods for a binomial proportion. Based on the results from Section 3.1.3, the maximum likelihood estimate (MLE) of the risk difference is \[ \hat{\RD} = \hat{p}_1 - \hat{p}_0 = \frac{a}{r_1} - \frac{c}{r_0}, \tag{9.1}\] which is defined as long as \(r_1 > 0\) and \(r_0 > 0\). It is an unbiased estimate of the true \(\RD\).

Because the outcomes in the two exposure groups are independent, the estimated variance of \(\hat{\RD}\) is \[ \hat{\Var}(\hat{\RD}) = \frac{\hat{p_1}(1 - \hat{p_1})}{r_1} + \frac{\hat{p_0} (1 - \hat{p_0})}{r_0}. \tag{9.2}\] The \(r_1\) and \(r_0\) in the denominators are sometimes replaced with \(r_1 - 1\) and \(r_0 - 1\) by analogy with the \(n - 1\) in the denominator of the sample variance (Rothman, Greenland, and Lash 2008). The Wald test statistic for the null hypothesis \(H_0: \RD = \RD_0\) is \[ Z_{\RD} = \frac{\hat{\RD} - \RD_0}{\sqrt{\hat{\Var}(\hat{\RD})}}. \tag{9.3}\] In large samples under the null, \(Z_{\RD}\) has a standard normal distribution and \(Z_{\RD}^2\) has a chi-squared distribution with one degree of freedom. The corresponding \(1 - \alpha\) Wald confidence limits for the \(\RD\) are \[ \hat{\RD} \pm z_{1 - \frac{\alpha}{2}} \sqrt{\hat{\Var}(\hat{\RD})}. \tag{9.4}\] As in Section 3.4, this confidence interval includes all values of \(\RD_0\) such that the Wald test in Equation 9.3 would fail to reject the null hypothesis at significance level \(\alpha\). For a 95% confidence interval, \(z_{1 - \frac{\alpha}{2}} \approx 1.96\). When the expected numbers of events are small, this confidence interval can have limits outside \([-1, 1]\). Confidence intervals with better performance can be obtained by inverting score or likelihood ratio tests or by using Bayesian methods (Agresti and Min 2005).

riskdiff.R
## Risk difference point and interval estimates

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)
?rats               # type q to exit
dim(rats)
names(rats)

# numbers of events and row sums
# Because follow-up of the rats was complete, risk calculations are valid.
a <- sum(rats$status[rats$rx == 1])
r1 <- sum(rats$rx == 1)
c <- with(subset(rats, rx == 0), sum(status))
r0 <- sum(rats$rx == 0)

# estimated risks of tumor onset in 104 weeks
p1hat <- a / r1
p0hat <- c / r0

# estimated risk difference and its variance
RDhat <- p1hat - p0hat
RDvar <- p1hat * (1 - p1hat) / r1 + p0hat * (1 - p0hat) / r0

# Wald hypothesis test that RD = 0 in normal and chi-squared versions
RDz <- RDhat / sqrt(RDvar)
RDz
2 * pnorm(-abs(RDz))
RDchisq <- RDz^2
RDchisq
1 - pchisq(RDchisq, df = 1)

# point estimate and 95% confidence interval for the risk difference
RDhat
RDhat + c(-1, 1) * qnorm(0.975) * sqrt(RDvar)

9.1.2 Risk ratio

The risk ratio comparing the exposed to the unexposed is \[ \RR = \frac{p_1}{p_0} \] where \(p_1\) is the risk in the exposed and \(p_0\) is the risk in the unexposed. It is defined whenever \(p_1 \geq 0\) and \(p_0 > 0\), and it can take any value in \([0, \infty)\). When exposure and disease are independent, \(\RR = 1\) because \(p_1 = p_0\) (see Section 7.2.1). The MLE of the risk ratio is \[ \hat{\RR} = \frac{\hat{p}_1}{\hat{p}_0} = \frac{a / r_1}{c / r_0}, \tag{9.5}\] which is defined as long as \(c > 0\) (which implies \(r_0 > 0\)) and \(r_1 > 0\).

It is difficult to estimate the variance of a ratio, so we use a log transformation to get a sum: \[ \ln \hat{\RR} = \ln \hat{p}_1 - \ln \hat{p_0}. \] Because outcomes in the two groups are independent, we have \[ \Var(\ln \hat{\RR}) = \Var(\ln \hat{p}_0) + \Var(\ln \hat{p}_1) \] by Equation 1.12. Using the delta method from Section 3.4.1 and the fact that \(\frac{\dif}{\dif x} \ln x = \frac{1}{x}\), we get the estimated variance \[ \hat{\Var}(\ln \hat{p}_i) = \frac{1}{\hat{p}_i^2} \Var(\hat{p}_i) = \frac{1}{\hat{p}_i^2} \times \frac{\hat{p}_i (1 - \hat{p}_i)}{n_i} = \frac{1}{m_i} - \frac{1}{r_i} \] where \(m_1 = a\) and \(m_0 = c\). Therefore, \[ \hat{\Var}(\ln \RR) = \frac{1}{a} - \frac{1}{r_1} + \frac{1}{c} - \frac{1}{r_0}. \tag{9.6}\] This is nonnegative because \(a \leq r_1\) and \(c \leq r_0\).

The Wald test statistic for the null hypothesis \(H_0: \RR = \RR_0\) is calculated on the log scale: \[ Z_{\RR} = \frac{\ln\hat{\RR} - \ln\RR_0}{\sqrt{\hat{\Var}(\ln\hat{\RR})}} = \frac{\ln\hat{\RR} - \ln\RR_0}{\sqrt{\frac{1}{a} - \frac{1}{r_1} + \frac{1}{c} - \frac{1}{r_0}}}. \tag{9.7}\] Because \(a \leq r_1\), we have \(1 / a \geq 1 / r_1\) with equality only if \(a = r_1\). Similarly, \(1 / c \geq 1 / r_0\) with equality only if \(c = r_0\). In large samples under the null, \(Z_{\RR}\) has a standard normal distribution and \(Z_{\RR}^2\) has a chi-squared distribution with one degree of freedom (Katz et al. 1978).

The \(1 - \alpha\) Wald confidence limits for \(\ln \RR\) are \[ \ln \hat{\RR} \pm z_{1 - \frac{\alpha}{2}} \sqrt{\frac{1}{a} - \frac{1}{r_1} + \frac{1}{c} - \frac{1}{r_0}}. \tag{9.8}\] The corresponding log-transformed \(1 - \alpha\) Wald confidence limits for the \(\RR\) are \[ \hat{\RR} \exp\Biggl(\pm z_{1 - \frac{\alpha}{2}} \sqrt{\frac{1}{a} - \frac{1}{r_1} + \frac{1}{c} - \frac{1}{r_0}}\Biggr) \tag{9.9}\] As in Section 3.4, this confidence interval includes all possible values \(\RR_0\) such that the Wald test in Equation 9.7 would fail to reject the null hypothesis at significance level \(\alpha\). The log transformation ensures that the confidence interval has appropriate bounds because \(\ln\RR \in (-\infty, \infty)\) if and only if \(\RR \in (0, \infty)\). Confidence intervals with better performance can be obtained by inverting score or likelihood ratio tests or by using Bayesian methods (Agresti and Min 2005).

riskratio.R
## Risk ratio point and interval estimates

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)
?rats               # type q to exit
dim(rats)
names(rats)

# numbers of events and row sums
# Because follow-up of the rats was complete, risk calculations are valid.
a <- sum(rats$status[rats$rx == 1])
r1 <- sum(rats$rx == 1)
c <- with(subset(rats, rx == 0), sum(status))
r0 <- sum(rats$rx == 0)

# estimated risks of tumor onset in 104 weeks
p1hat <- a / r1
p0hat <- c / r0

# estimated risk ratio, log risk ratio, and variance of ln(RRhat)
RRhat <- p1hat / p0hat
lnRRhat <- log(RRhat)
lnRRvar <- 1 / a - 1 / r1 + 1 / c - 1 / r0

# Wald hypothesis test that ln(RR) = 0 in normal and chi-squared versions
lnRRz <- lnRRhat / sqrt(lnRRvar)
lnRRz
2 * pnorm(-abs(lnRRz))
lnRRchisq <- lnRRz^2
lnRRchisq
1 - pchisq(lnRRchisq, df = 1)

# point estimate and 95% confidence interval for log risk ratio
lnRRci <- lnRRhat + c(-1, 1) * qnorm(0.975) * sqrt(lnRRvar)
lnRRhat
lnRRci

# point estimate and 95% confidence interval for risk ratio
RRhat
exp(lnRRci)

9.1.3 Odds ratio

The odds corresponding to a probability \(p\) is \[ \odds(p) = \frac{p}{1 - p}. \] For \(p \in [0, 1)\), the odds can take any value in \([0, \infty)\). The odds function is one-to-one because \[ \frac{\odds(p)}{1 + \odds(p)} = p \] for any \(p \in [0, 1)\). Thus, any probability can be converted to an odds and vice versa.

The odds ratio comparing the exposed to the unexposed is \[ \OR = \frac{\odds(p_1)}{\odds(p_0)} = \frac{p_1 / (1 - p_1)}{p_0 / (1 - p_0)}, \] which is defined when \(p_1 \geq 0\) and \(p_0 > 0\). It can take any value in \([0, \infty)\). When exposure and disease are independent, \(\OR = 1\) because \(\odds(p_1) = \odds(p_0)\). The MLE of the odds ratio is \[ \hat{\OR} = \frac{\odds(\hat{p}_1)}{\odds(\hat{p}_0)} = \frac{a / (r_1 - a)}{c / (r_0 - c)} = \frac{a d}{b c}, \tag{9.10}\] which is defined as long as \(b > 0\) (which implies \(r_1 > 0\)) and \(c > 0\) (which implies \(r_0 > 0\)).

As with the risk ratio, we use a log transformation to turn the product into a sum for variance calculations: \[ \ln \hat{\OR} = \logit(\hat{p}_1) - \logit(\hat{p}_0) \] where \[ \logit(p) = \ln \frac{p}{1 - p} \] is the logit transformation from Section 3.4.1. Because outcomes in the two groups are independent, we have \[ \Var\big(\ln \hat{\OR}\big) = \Var\bigl(\logit(\hat{p}_1)\bigr) + \Var\bigl(\logit(\hat{p}_0)\bigr) \tag{9.11}\] by Equation 1.12. Because \[ \logit'(p) = \frac{1}{p} + \frac{1}{1 - p} = \frac{1}{p (1 - p)}, \] the delta method gives us the estimated variance \[ \hat{\Var}\bigl(\logit(\hat{p}_i)\bigr) = \frac{1}{\hat{p}^2_i (1 - \hat{p}_i)^2} \Var(\hat{p}_i) = \frac{1}{m_i} + \frac{1}{r_i - m_i} \] where \(m_1 = a\) and \(m_0 = c\). The Wald test statistic for the null hypothesis \(H_0: \OR = \OR_0\) is calculated on the log scale: \[ Z_{\OR} = \frac{\ln\hat{\OR} - \ln\OR_0}{\sqrt{\hat{\Var}(\ln\hat{\OR})}}. \tag{9.12}\] In large samples under the null, \(Z_{\OR}\) has a standard normal distribution and \(Z_{\OR}^2\) has a chi-squared distribution with one degree of freedom (Woolf 1955).

The \(1 - \alpha\) Wald confidence limits for \(\ln \OR\) are \[ \ln \hat{\OR} \pm z_{1 - \frac{\alpha}{2}} \sqrt{\frac{1}{a} + \frac{1}{b} + \frac{1}{c} + \frac{1}{d}}. \tag{9.13}\] The corresponding log-transformed \(1 - \alpha\) Wald confidence limits for the \(\OR\) are \[ \hat{\OR} \exp\Biggl(\pm z_{1 - \frac{\alpha}{2}} \sqrt{\frac{1}{a} + \frac{1}{b} + \frac{1}{c} + \frac{1}{d}}\Biggr) \tag{9.14}\] As in Section 3.4, this confidence interval includes all possible values \(\OR_0\) such that the Wald test in Equation 9.12 would fail to reject the null hypothesis at significance level \(\alpha\). The log transformation ensures that the confidence interval has appropriate bounds because \(\ln\OR \in (-\infty, \infty)\) if and only if \(\OR \in (0, \infty)\). Confidence intervals with better performance can be obtained by inverting score or likelihood ratio tests or by using Bayesian methods (Agresti and Min 2005).

oddsratio.R
## Odds ratio point and interval estimates

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)
?rats               # type q to exit
dim(rats)
names(rats)

# numbers of events and row sums
# Because follow-up of the rats was complete, risk calculations are valid.
a <- sum(rats$status[rats$rx == 1])
r1 <- sum(rats$rx == 1)
c <- with(subset(rats, rx == 0), sum(status))
r0 <- sum(rats$rx == 0)

# estimated risks of tumor onset in 104 weeks
p1hat <- a / r1
p0hat <- c / r0

# estimated odds ratio, log odds ratio, and variance of ln(ORhat)
b <- r1 - a
d <- r0 - c
odds <- function(p) p / (1 - p)
ORhat <- odds(p1hat) / odds(p0hat)
lnORhat <- log(ORhat)
lnORvar <- 1 / a + 1 / b + 1 / c + 1 / d

# Wald hypothesis test that ln(OR) = 0 in normal and chi-squared versions
lnORz <- lnORhat / sqrt(lnORvar)
lnORz
2 * pnorm(-abs(lnORz))    # two-tailed test
lnORchisq <- lnORz^2
lnORchisq
1 - pchisq(lnORchisq, df = 1)

# 95% confidence interval for log odds ratio
lnORci <- lnORhat + c(-1, 1) * qnorm(0.975) * sqrt(lnORvar)
lnORhat
lnORci

# point estimate and 95% confidence interval for the odds ratio
ORhat
exp(lnORci)

9.1.4 Incidence rate ratio

If there is delayed entry or loss to follow-up, we cannot calculate a risk ratio or odds ratio directly but we can still calculate the incidence rate in each group. Recall that the incidence rate is a maximum likelihood for an exponential rate parameter \(\lambda\). If times to disease onset in the each exposure groups have an exponential distribution, then the incidence rate ratio is \[ \IRR = \frac{\lambda_1}{\lambda_0} \] where \(\lambda_1\) is the rate in the exposed and \(\lambda_0\) is the rate in the unexposed. It is defined whenever \(\lambda_1 \geq 0\) and \(\lambda_0 > 0\), and it can take any value in \([0, \infty)\). When exposure and disease are independent, \(\IRR = 1\) because \(\lambda_1 = \lambda_0\). The incidence rate ratio is sometimes called the incidence density ratio (O. Miettinen 1976), and it equals the hazard ratio when the times to events in both exposure groups have exponential distributions.

Let \(T_1\) be the total person-time in the exposed group and \(T_0\) be the total person-time in the unexposed group. Based on the results from Section 5.3.2, the MLE of the incidence rate ratio is \[ \hat{\IRR} = \frac{\hat{\lambda}_1}{\hat{\lambda}_0} = \frac{a / T_1}{c / T_0}. \tag{9.15}\] As with the risk ratio and odds ratio, we use a log transformation to get a sum instead of a ratio for variance calculations: \[ \ln \hat{\IRR} = \ln \frac{a}{T_1} - \ln \frac{c}{T_0}. \] Because outcomes in the two groups are independent, \[ \Var\big(\ln \hat{\IRR}\big) = \Var\bigg(\ln \frac{a}{T_1}\bigg) + \Var\bigg(\ln \frac{c}{T_0}\bigg). \] By the delta method, the estimated variance of \(\ln \hat{IRR}\) is \[ \hat{\Var}\bigg(\ln \frac{m_i}{T_i}\bigg) = \bigg(\frac{T_i}{m_i}\bigg)^2 \Var\bigg(\frac{m_i}{T_i}\bigg) = \frac{T_i^2}{m_i^2} \times \frac{m_i}{T_i^2} = \frac{1}{m_i} \tag{9.16}\] where \(m_1 = a\) and \(m_0 = c\). The Wald test statistic for the null hypothesis \(H_0: \IRR = \IRR_0\) is calculated on the log scale: \[ Z_{\IRR} = \frac{\ln\hat{\IRR} - \ln\IRR_0}{\sqrt{\hat{\Var}(\ln\hat{\IRR})}} = \frac{\ln\hat{\IRR} - \ln\IRR_0}{\sqrt{\frac{1}{a} + \frac{1}{c}}}. \tag{9.17}\] In large samples under the null, \(Z_{\IRR}\) has a standard normal distribution and \(Z_{\IRR}^2\) has a chi-squared distribution with one degree of freedom.

The \(1 - \alpha\) Wald confidence limits for the \(\ln \IRR\) are \[ \ln \hat{\IRR} \pm z_{1 - \frac{\alpha}{2}} \sqrt{\frac{1}{a} + \frac{1}{c}}. \] The corresponding log-transformed \(1 - \alpha\) Wald confidence limits for the \(\IRR\) are \[ \hat{\IRR} \exp\Bigg(\pm z_{1 - \frac{\alpha}{2}} \sqrt{\frac{1}{a} + \frac{1}{c}}\Bigg). \tag{9.18}\] This confidence interval includes all possible values \(\IRR_0\) such that the Wald test in Equation 9.17 would fail to reject the null hypothesis at significance level \(\alpha\). The log transformation ensures that the confidence interval has appropriate bounds because \(\ln\IRR \in (-\infty, \infty)\) if and only if \(\IRR \in (0, \infty)\). Confidence intervals with better performance can be obtained by inverting score or likelihood ratio tests or by using Bayesian methods (Agresti 2013).

irratio.R
## Incidence rate ratio point and interval estimates

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)
?rats               # type q to exit
dim(rats)
names(rats)

# numbers of events and total rat-weeks
# The subset() function can be used as an alternative to vector indexing.
a <- sum(rats$status[rats$rx == 1])
T1 <- sum(rats$time[rats$rx == 1])
c <- with(subset(rats, rx == 0), sum(status))
T0 <- with(subset(rats, rx == 0), sum(time))

# estimated incidence rates
# The units are tumor onsets per rat-week.
ir1hat <- a / T1
ir0hat <- c / T0

# estimated incidence rate ratio, log IRR, and variance of ln(IRRhat)
IRRhat <- ir1hat / ir0hat
lnIRRhat <- log(IRRhat)
lnIRRvar <- 1 / a + 1 / c

# Wald hypothesis test that ln(IRR) = 0 in normal and chi-squared versions
lnIRRz <- lnIRRhat / sqrt(lnIRRvar)
lnIRRz
2 * pnorm(-abs(lnIRRz))    # two-tailed test
lnIRRchisq <- lnIRRz^2
lnIRRchisq
1 - pchisq(lnIRRchisq, df = 1)

# 95% confidence interval for log incidence rate ratio
lnIRRci <- lnIRRhat + c(-1, 1) * qnorm(0.975) * sqrt(lnIRRvar)
lnIRRhat
lnIRRci

# point estimate and 95% confidence interval for the incidence rate ratio
IRRhat
exp(lnIRRci)

9.2 Generalized linear models

The foundation for all regression models is linear regression. Let \(Y\) denote an outcome and let \(X_1, \ldots, X_k\) be a set of predictors or covariates that we wish to use to predict \(Y\). Then a linear regression model has the form \[ \E[Y \given{} X] = \beta_0 + \beta_1 X_1 + \ldots + \beta_k X_k, \] or equivalently \[ Y = \beta_0 + \beta_1 X_1 + \ldots + \beta_k X_k + \varepsilon, \] where \(\varepsilon\) is an error term with mean zero. The point estimates of the coefficients \(\beta_0, \beta_1, \ldots, \beta_k\) are obtained by ordinary least squares, which is equivalent to assuming a normal distribution for \(\varepsilon\) and using maximum likelihood estimation. The coefficient \(\beta_0\) is usually called the intercept, and it represents the mean outcome when all predictors equal zero. Each \(\beta_j\) can be interpreted as the change in the expected value of \(\E(Y \given{} X)\) associated with a one-unit increase in \(X_j\) when all other predictors are held constant.

Because probabilities are means of indicator variables (see Section 1.3.1), a linear regression model with binary disease outcome \(D\) with a binary exposure or treatment \(X\) can be used to estimate risks: \[ \Pr(D = 1 \given{} X = x) = \beta_0 + \beta_1 x. \] The intercept \(\beta_0\) is the risk of disease among the unexposed (\(X = 0\)), and the coefficient \(\beta_1\) is the risk difference \(\RD\): \[ \RD = (\beta_0 + \beta_1) - \beta_0 = \beta_1. \] However, the likelihood of this model is not quite correct for binary outcomes. The conditional distribution of \(D\) given \(X\) is a Bernoulli (see Section 1.3.5) distribution, not a normal distribution. Although the point estimates of \(\beta_0\) and \(\beta_1\) are unbiased, hypothesis tests and confidence intervals based on this model are distorted.

In a generalized linear model (GLM), we have \[ g\big(\E[Y \given{} X]\big) = \beta_0 + \beta_1 X_1 + \ldots + \beta_k X_k \tag{9.19}\] where \(g\) is called the link function and the likelihood is determined by the family of the model, which specifies the conditional distribution of \(Y\) given \(X\) (Nelder and Wedderburn 1972; McCullagh and Nelder 1989). The left-hand side of Equation 9.19 is called the linear predictor. Linear regression is a GLM from the Gaussian family with the identity link \(g(y) = y\). In practice, the family is usually determined by the outcome type (e.g., binomial family for binary outcomes, Gaussian family for continuous outcomes, and Poisson family for count outcomes) and the link is usually determined by the measure of association that we are trying to estimate.

GLMs from the binomial family can be used to estimate risk differences, risk ratios, odds ratios, and incidence rate ratios using binary outcome data. For some of these measures of association, there are alternative GLMs that can be used if a binomial GLM does not converge. For simplicity, we will focus on two-sample inference, so our models will contain a single binary predictor \(X\). The measure of association estimated by the model is determined by the link function. In models with a single binary covariate, the Wald confidence intervals for the measure of association match the traditional confidence intervals from Section 9.1 calculated using the delta method and the binomial variance. However, binomial GLMs allow the calculation of score and likelihood ratio confidence intervals, and they can be used in Bayesian inference. The resulting interval estimates often perform better than Wald confidence intervals in terms of coverage probability and width (Agresti and Min 2005; Agresti 2013).

9.2.1 Risk differences and the identity link

To estimate risk differences, a GLM from the binomial family with an identity link \(g(p) = p\) can be used. In this model \[ \Pr(D = 1 \given{} X = x) = \beta_0 + \beta_1 x, \] and a binomial likelihood is used to estimate the coefficients. The risk of disease in the unexposed is \[ p_0 = \Pr(D = 1 \given{} X = 0) = \beta_0, \] and the risk of disease in the exposed is \[ p_1 = \Pr(D = 1 \given{} X = 1) = \beta_0 + \beta_1. \] The risk difference is \[ \RD = p_1 - p_0 = (\beta_1 + \beta_0) - \beta_0 = \beta_1. \] Thus, \(\hat{\beta}_0\) is the estimated risk of disease in the unexposed and \(\hat{\beta}_1\) is the estimated risk difference. Their \(1 - \alpha\) confidence intervals can be interpreted as confidence intervals for the risk in the exposed and the risk difference, respectively. When the confidence interval for \(\beta_1\) is a Wald confidence interval, it will match Equation 9.4. However, the Gaussian GLM can be used to calculate score or likelihood ratio confidence limits or calculate a Bayesian posterior distribution.

The estimated risk of disease in the exposed is \(\hat{\beta}_0 + \hat{\beta}_1\), and its estimated variance is \[ \hat{\Var}\bigl(\hat{\beta}_0 + \hat{\beta}_1\bigr) = \hat{\Var}\bigl(\hat{\beta}_0\bigr) + \hat{\Var}\bigl(\hat{\beta}_1\bigr) + 2 \Cov\bigl(\hat{\beta}_0, \hat{\beta}_1\bigr) \tag{9.20}\] by equation Equation 1.12. Each of the variances and covariances on the right can be obtained from the covariance matrix for the regression coefficients. The corresponding \(1 - \alpha\) Wald confidence interval is \[ \big(\hat{\beta}_0 + \hat{\beta}_1\big) \pm z_{1 - \frac{\alpha}{2}} \sqrt{\hat{\Var}\bigl({\hat{\beta}_0 + \hat{\beta}_1}}\bigr), \tag{9.21}\] which is accurate in large samples.

Because probabilities must live in the interval \([0, 1]\), the set of possible combinations of \(\beta_0\) and \(\beta_1\) is constrained. We need both \(\beta_0 \in [0, 1]\) and \(\beta_0 + \beta_1 X \in [0, 1]\) for all values of \(X\) in our data. Figure 9.1 shows the possible combinations of \(\beta_0\) and \(\beta_1\) in a binomial GLM with the identity link and a binary \(X\) that is an indicator variable for exposure or treatment as in Table 2.1. In this case, the model will fail to converge if \(a = 0\) (which implies \(\beta_0 + \beta_1 = 0\)), \(b = 0\) (which implies \(\beta_0 + \beta_1 = 1)\), \(c = 0\) (which implies \(\beta_0 = 0\)), or \(d = 0\) (which implies \(\beta_1 = 1\)).

Code
glm-RD-bounds.R
## Bounds on beta0 and beta1 in a binomial GLM for the risk difference
# This uses the identity link. We assume a single binary covariate coded 0/1.

# plot
plot(c(0, 0, 1, 1), c(0, 1, 0, -1), type = "n",
     xlim = c(-0.75, 1.75), ylim = c(-1.25, 1.25),
     xlab = expression(paste("Intercept ", (beta[0]))),
     ylab = expression(paste("Slope ", (beta[1]))))
grid()
polygon(c(0, 0, 1, 1), c(0, 1, 0, -1), border = "darkgray", col = "gray")
grid()
abline(h = 0)  # x-axis (y = 0)
abline(v = 0)  # y-axis (x = 0)

# labels
text(-0.1, 0.5, expression(beta[0] == 0), srt = 90)
text(1.1, -0.5, expression(beta[0] == 1), srt = 90)
text(0.4, -0.5, expression(beta[0] + beta[1] == 0), srt = -45)
text(0.6, 0.5, expression(beta[0] + beta[1] == 1), srt = -45)
Figure 9.1: The gray triangle shows possible combinations of the intercept \(\beta_0\) and the slope \(\beta_1\) in a binomial GLM with the identity link and a single binary predictor coded 0/1.

9.2.1.1 Gaussian GLM with robust variance for risk differences

When a linear binomial GLM fails to converge, a common workaround is to use a Gaussian GLM with an identity link and a robust (sandwich) variance estimator. A normal(\(p\), \(\sigma^2\)) distribution has mean \(p\), so the regression produces unbiased point estimates of the coefficients. However, it estimates a single variance \(\sigma^2\). The Bernoulli variance changes with \(p\), so groups with different risks should have different variances. The \(\sigma^2\) from the linear regression typically produces Wald confidence intervals that are slightly too narrow. The robust variance estimator corrects for this, producing valid Wald confidence intervals. Score and likelihood ratio confidence intervals are not available because the likelihood is not quite correct.

riskdiff-GLM.R
## Risk difference estimation with GLMs

# to get help on GLMs in R (type q to exit)
?glm
?family

# load packages
# The rats data is from:
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)     # rats data
library(sandwich)     # sandwich() for robust variance
library(lmtest)       # coefci() for Wald confidence intervals

# traditional RD point estimate and Wald 95% confidence interval
# Because follow-up of the rats was complete, risk calculations are valid.
r1 <- sum(rats$rx == 1)
a <- with(rats, sum(status[rx == 1]))
r0 <- sum(rats$rx == 0)
c <- with(rats, sum(status[rx == 0]))
risk1 <- a / r1
risk0 <- c / r0
RDhat <- risk1 - risk0
RDvar <- risk1 * (1 - risk1) / r1 + risk0 * (1 - risk0) / r0

# point and interval estimates of the RD
RDhat
RDhat + c(-1, 1) * qnorm(0.975) * sqrt(RDvar)

# Binomial GLM with identity link for the RD
# Default binomial link = "logit", so we must specify link = "identity".
RDglm <- glm(status ~ rx, family = binomial(link = "identity"), data = rats)
summary(RDglm)                  # point estimates, p-values, CIs, global tests
names(RDglm)                    # parts of the fitted model
coef(RDglm)                     # estimated risk (x = 0) and RD
confint(RDglm)                  # likelihood ratio CIs (better)
coefci(RDglm)                   # Wald CI for RD matches calculation above

# Gaussian (normal) GLM with identity link and robust variance for the RD
RDglm2 <- glm(status ~ rx, data = rats)
coef(RDglm2)                    # point estimates match binomial GLM above
confint(RDglm2)                 # likelihood ratio CI too narrow
coefci(RDglm2)                  # Wald CI also too narrow
coefci(RDglm2, vcov = sandwich) # robust Wald CIs match binomial GLM above

# point and interval estimates for risk in the exposed
# The vector c(1, 1) represents 1 * beta0 + 1 * beta1,
# and as.numeric() is used to return a number instead of a matrix.
p1hat <- sum(coef(RDglm))
p1var <- as.numeric(c(1, 1) %*% vcov(RDglm) %*% c(1, 1))
p1hat
p1hat + c(-1, 1) * qnorm(0.975) * sqrt(p1var)

# Gaussian GLM with robust variance
sum(coef(RDglm2))                         # matches p1hat above
c(1, 1) %*% sandwich(RDglm2) %*% c(1, 1)  # matches p1var above

9.2.2 Risk ratios and the log link

A binomial GLM with a log link \(g(p) = \ln p\) is called a log-binomial regression model. In this model \[ \ln\bigl(\Pr(D = 1 \given{} X = x)\bigr) = \beta_0 + \beta_1 x. \] The risk of disease in the unexposed is \[ p_0 = \exp(\beta_0), \] and the risk of diseased in the exposed is \[ p_1 = \exp(\beta_0 + \beta_1). \] The risk ratio comparing the exposed to the unexposed is \[ \RR = \frac{e^{\beta_0 + \beta_1}}{e^{\beta_0}} = e^{\beta_1}. \] Thus, \(\exp(\hat{\beta}_0)\) is the estimated risk of disease in the unexposed and \(\exp(\hat{\beta}_1)\) is the estimated risk ratio comparing the exposed to the unexposed. If the \(1 - \alpha\) confidence interval for \(\beta_i\) is \((\ell_i, u_i)\), then \((e^{\ell_i}, e^{u_i})\) is the corresponding confidence interval for the risk of disease in the unexposed (\(i = 0\)) or the risk ratio (\(i = 1\)). When the confidence interval for \(\beta_1\) is a Wald confidence interval, it will match the confidence interval for \(\ln \RR\) in Equation 9.8 and the corresponding confidence interval for the \(\RR\) in Equation 9.9. However, the log-binomial GLM can be used to calculate score or likelihood ratio confidence limits or a Bayesian posterior distribution.

The estimated risk of disease in the exposed is \(\exp\bigl(\hat{\beta}_0 + \hat{\beta}\bigr)\). The estimated variance of \(\hat{\beta}_0 + \hat{\beta}_1\) is given in Equation 9.20, and \(1 - \alpha\) confidence limits for the sum are given in Equation 9.21. The corresponding confidence limits for the risk in the exposed are \[ e^{\big(\hat{\beta}_0 + \hat{\beta}_1\big) \pm z_{1 - \frac{\alpha}{2}} \sqrt{\hat{\Var}\bigl({\hat{\beta}_0 + \hat{\beta}_1}}\bigr)} \tag{9.22}\] which is accurate in large samples. It is not possible to get score or likelihood ratio confidence intervals for the risk in the exposed without reparameterizing the model, but Bayesian methods can be used to calculate credible intervals.

As in the binomial GLM for risk differences, not all combinations of \(\beta_0\) and \(\beta_1\) produce probabilities in \([0, 1]\). the parameter space for log-binomial regression is bounded in the sense that not all combinations of \(\beta_0\) and \(\beta_1\) are possible. We get a probability greater than one whenever \(\beta_0 + \beta_1 X > 0\). When the maximum likelihood estimate \((\hat{\beta}_0, \hat{\beta}_1)\) is close to this boundary for some values of \(X\) in the data, the model can fail to converge. In some cases, this problem can be solved by reparameterizing the model to put the maximum farther away from the boundary of the new parameter space or by using more sophisticated numerical methods to maximize the likelihood (Williamson, Eliasziw, and Fick 2013). Figure 9.2 shows the possible combinations of \(\beta_0\) and \(\beta_1\) in a binomial GLM with the identity link and a binary predictor \(X\) that is an indicator variable for exposure or treatment as in Table 2.1. In this case, the model will not converge if \(a = 0\) (which implies \(\beta_0 + \beta_1 = -\infty\)), \(b = 0\) (which implies \(\beta_0 + \beta_1 = 0\)), \(c = 0\) (which implies \(\beta_0 = -\infty\)) or \(d = 0\) (which implies \(\beta_0 = 0\)).

Code
glm-RR-bounds.R
## Bounds on beta0 and beta1 in a binomial GLM for the risk ratio
# This uses the log link, and we assume a single binary covariate coded 0/1.

# plot
plot(c(0, 0, -2, -2), c(0, -2, -2, 2), type = "n",
     xlim = c(-1.5, 1), ylim = c(-1.5, 1),
     xlab = expression(paste("Intercept ", (beta[0]))),
     ylab = expression(paste("Slope ", (beta[1]))))
grid()
polygon(c(0, 0, -2, -2), c(0, -2, -2, 2),
        border = "darkgray", col = "gray")
grid()
abline(h = 0)  # x-axis (y = 0)
abline(v = 0)  # y-axis (x = 0)

# labels
text(0.1, -0.75, expression(beta[0] == 0), srt = 90)
text(-0.5, 0.6, expression(beta[0] + beta[1] == 0), srt = -45)
arrows(-1.2, 0.2, -1.5, 0.2, code = 2, length = 0.1)
text(-0.95, 0.2, expression(beta[0] %->% -infinity))
arrows(-1.3, -1.3, -1.5, -1.5, code = 2, length = 0.1)
text(-1.1, -1.2, expression(beta[0] + beta[1] %->% -infinity))
arrows(-0.2, -1.2, -0.2, -1.5, code = 2, length = 0.1)
text(-0.2, -1.1, expression(beta[1] %->% -infinity))
Figure 9.2: The gray area shows the possible combinations of the intercept \(\beta_0\) and the slope \(\beta_1\) in a binomial GLM with the log link and a single binary predictor coded 0/1.

9.2.2.1 Poisson GLM with robust variance for risk ratios

When a log-binomial GLM fails to converge, a common workaround is to use a Poisson GLM with a log link and a robust (sandwich) variance (Zou 2004; Naimi and Whitcomb 2020). The Poisson GLM with a log link has no constraints on \(\beta_0\) and \(\beta_1\) because a Poisson mean can be any positive number. Because the mean of both the Poisson(\(p\)) and Bernoulli(\(p\)) distributions equal \(p\), the Poisson GLM produces unbiased point estimates of the coefficients. However, the variance of a Poisson(\(p\)) distribution is \(p\), which is larger than the Bernoulli(\(p\)) variance of \(p (1 - p)\). Zou (2004) showed that, in a Poisson GLM with a log link and a single binary covariate, the robust (sandwich) variance equals the delta method variance of \(\ln \RR\). Point estimates and Wald confidence limits for the coefficients, the risk in the unexposed and the exposed, and the risk ratio can be obtained in the same way as for the log-binomial model.

riskratio-GLM.R
## Risk ratio estimation with GLMs

# to get help on GLMs in R (type q to exit)
?glm
?family

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)     # rats data
library(sandwich)     # sandwich() for robust variance
library(lmtest)       # coefci() for Wald confidence intervals

# traditional RR point estimate and Wald 95% confidence interval
# Because follow-up of the rats was complete, risk calculations are valid.
r1 <- sum(rats$rx == 1)
a <- with(rats, sum(status[rx == 1]))
r0 <- sum(rats$rx == 0)
c <- with(rats, sum(status[rx == 0]))
risk1 <- a / r1
risk0 <- c / r0
RRhat <- (a / r1) / (c / r0)
lnRRvar <- 1 / a - 1 / r1 + 1 / c - 1 / r0
lnRRci <- log(RRhat) + c(-1, 1) * qnorm(.975) * sqrt(lnRRvar)

# point and interval estimates of the RR
RRhat
exp(lnRRci)

# binomial GLM with log link (log-binomial model) for the RR
# Default binomial link = "logit", so we must specify link = "log".
RRglm <- glm(status ~ rx, family = binomial(link = "log"), data = rats)
summary(RRglm)                  # point estimates, p-values, CIs, global tests
names(RRglm)                    # parts of the fitted model
exp(coef(RRglm))                # estimated risk (x = 0) and RR
exp(confint(RRglm))             # likelihood ratio CIs (better)
exp(coefci(RRglm))              # log-transformed Wald CI for RD matches above

# Poisson GLM with log link and sandwich variance for the RR
# The log link is the default for the Poisson family.
RRglm2 <- glm(status ~ rx, family = poisson(link = "log"), data = rats)
exp(coef(RRglm2))               # point estimates match binomial GLM above
exp(confint(RRglm2))            # likelihood ratio CI too wide
exp(coefci(RRglm2))             # Wald CI also too wide
exp(coefci(RRglm2, vcov = sandwich))  # robust Wald CI matches log binomial

# point and interval estimates for risk in the exposed
# The vector c(1, 1) represents 1 * beta0 + 1 * beta1,
# and as.numeric() is used to return a number instead of a matrix.
p1hat <- exp(sum(coef(RRglm)))
lnp1var <- as.numeric(c(1, 1) %*% vcov(RRglm) %*% c(1, 1))
p1hat
p1hat * exp(c(-1, 1) * qnorm(0.975) * sqrt(lnp1var))

# Poisson GLM with robust variance
exp(sum(coef(RRglm2)))                    # matches p1hat above
c(1, 1) %*% sandwich(RRglm2) %*% c(1, 1)  # matches lnp1var above

9.2.3 Odds ratios and the logit link

A binomial GLM with a logit link \(g(p) = \logit(p)\) is called a logistic regression model, which was originally developed by Berkson (1944) and later refined by Cox (1958). In this model, \[ \logit\bigl(\Pr(D = 1 \given{} X = x)\bigr) = \beta_0 + \beta_1 x. \tag{9.23}\] The odds of disease in the unexposed is \[ \odds(p_0) = e^{\beta_0}, \] and the odds of diseased in the exposed is \[ \odds(p_1) = e^{\beta_0 + \beta_1}. \] The odds ratio comparing the exposed to the unexposed is \[ \OR = \frac{e^{\beta_0 + \beta_1}}{e^{\beta_0}} = e^{\beta_1}. \] Thus, \(\exp(\hat{\beta}_0)\) is the estimated odds of disease in the unexposed and \(\exp(\hat{\beta}_1)\) is the estimated odds ratio comparing the exposed to the unexposed. If the \(1 - \alpha\) confidence interval for \(\beta_i\) is \((\ell_i, u_i)\), then \((e^{\ell_i}, e^{u_i})\) is the corresponding confidence interval for the odds of disease in the unexposed (\(i = 0\)) or the odds ratio (\(i = 1\)). When the confidence interval for \(\beta_1\) is a Wald confidence interval, it will match the confidence interval for \(\ln \OR\) in Equation 9.13 and the corresponding confidence interval for the \(\OR\) in Equation 9.14. However, the logistic GLM can be used to calculate score or likelihood ratio confidence limits or a Bayesian posterior distribution.

The estimated odds of disease in the exposed is \(\exp\bigl(\hat{\beta}_0 + \hat{\beta}\bigr)\). The estimated variance of \(\hat{\beta}_0 + \hat{\beta}_1\) is given in Equation 9.20, and \(1 - \alpha\) confidence limits for the sum are given in Equation 9.21. The corresponding confidence limits for the odds ratio in the exposed are given in Equation 9.22, which is accurate in large samples. It is not possible to get score or likelihood ratio confidence intervals for the odds in the exposed without reparameterizing the model, but Bayesian methods can be used to calculate credible intervals.

Unlike the GLMs for the risk difference and risk ratio, there are no restrictions on \(\beta_0\) and \(\beta_1\) in a logistic regression model. Thus, it is the most numerically stable of the three regression models. However, with a single predictor \(X\) that is an indicator of treatment or exposure as in Table 2.1, it will fail to converge if \(a = 0\) (which implies \(\beta_0 + \beta_1 = -\infty\)), \(b = 0\) (which implies \(\beta_0 + \beta_1 = \infty\)), \(c = 0\) (which implies \(\beta_0 = \infty\)), or \(d = 0\) (which implies \(\beta_0 = -\infty\)).

Any estimate of the odds of disease can be used to obtain an estimate of the risk of disease using the inverse function for the logit transformation, which is the expit or logistic function from Equation 3.19. The name logistic regression comes from the fact that the logistic function is used to get a probability from the corresponding odds(Berkson 1944). In the model from Equation 9.23, the risk of disease in the unexposed is \[ \expit\bigl(e^{\beta_0}\bigr) = \frac{1}{1 + e^{-(e^\beta_0)}}, \] and the risk of disease in the exposed is \[ \expit\bigl(e^{\beta_0 + \beta_1}\bigr) = \frac{1}{1 + e^{-(e^{\beta_0 + \beta_1})}}. \] Point estimates of these risks can be obtained by replacing the unknown \(\beta_0\) and \(\beta_1\) with their maximum likelihood estimates \(\hat{\beta}_0\) and \(\hat{\beta}_1\), and these estimated risks can be used to obtain point estimates of the risk ratio and risk difference. Confidence limits for the risks in the exposed and unexposed can be obtained by applying the logistic function to the confidence limits for the corresponding odds. Because the same odds ratio can occur with many different values of the risk difference or risk ratio, confidence limits for the \(\RD\) or \(\RR\) cannot be obtained directly from the confidence limits for the \(\OR\).

Because the risks of disease in the exposed and unexposed can be calculated using the logistic regression model, we can also get point estimates of the risk difference and risk ratio. Logit-transformed Wald confidence limits for the risk difference or risk ratio can be obtained using a multivariable version of the delta method from Section 3.4.1 and the covariance matrix from the fitted logistic regression model. Similarly, the binomial GLM for the risk difference in Section 9.2.1 could be used to obtain point and interval estimates of the risk ratio or odds ratio, and the log-binomial for the risk ratio in Section 9.2.2 could be used to obtain point and interval estimates of the risk difference or odds ratio. Although it is more convenient to use a regression model that expresses your preferred measure of association in terms of a single coefficient, the measure of association does not dictate the choice of regression model or vice versa.

oddsratio-GLM.R
## Odds ratio estimation with GLMs

# to get help on GLMs in R (type q to exit)
?glm
?family

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)     # rats data
library(sandwich)     # sandwich() for robust variance
library(lmtest)       # coefci() for Wald confidence intervals

# traditional OR point estimate and Wald 95% confidence interval
# Because follow-up of the rats was complete, risk calculations are valid.
r1 <- sum(rats$rx == 1)
a <- with(rats, sum(status[rx == 1]))
b <- r1 - a
r0 <- sum(rats$rx == 0)
c <- with(rats, sum(status[rx == 0]))
d <- r0 - c
odds1 <- a / b
odds0 <- c / d
ORhat <- odds1 / odds0
lnORvar <- 1 / a + 1 / b + 1 / c + 1 / d
lnORci <- log(ORhat) + c(-1, 1) * qnorm(.975) * sqrt(lnORvar)

# point and interval estimates of the OR
ORhat
exp(lnORci)

# binomial GLM with logit link for the OR
# Default binomial link is "logit", so it does not need to be specified.
ORglm <- glm(status ~ rx, family =  binomial(), data = rats)
summary(ORglm)                  # point estimates, p-values, CIs, global tests
names(ORglm)                    # parts of the fitted model
exp(coef(ORglm))                # estimated odds (x = 0) and OR
exp(confint(ORglm))             # likelihood ratio CIs (better)
exp(coefci(ORglm))              # log-transformed Wald CI matches above

# point and interval estimates for risk in the exposed
# The vector c(1, 1) represents 1 * beta0 + 1 * beta1,
# and as.numeric() is used to return a number instead of a matrix.
odds1hat <- exp(sum(coef(ORglm)))
lnodds1var <- as.numeric(c(1, 1) %*% vcov(ORglm) %*% c(1, 1))
odds1hat
odds1hat * exp(c(-1, 1) * qnorm(0.975) * sqrt(lnodds1var))

# estimates of risks, risk difference, and risk ratio based on odds
expit <- function(v) 1 / (1 + exp(-v))    # logistic function
beta0 <- coef(ORglm)["(Intercept)"]
beta1 <- coef(ORglm)["rx"]
# risk in exposed
risk1 <- a / r1
risk1
expit(beta0 + beta1)
# risk in unexposed
risk0 <- c / r0
risk0
expit(beta0)
# risk difference
RDhat <- risk1 - risk0
RDhat
expit(beta0 + beta1) - expit(beta0)
# risk ratio
RRhat <- risk1 / risk0
RRhat
expit(beta0 + beta1) / expit(beta0)

9.2.4 Cumulative hazard ratio and the complementary log-log link*

If \(H_1(t)\) is the cumulative hazard function in the exposed and \(H_0(t)\) is the cumulative hazard function in the unexposed (see Section 5.2.3), then \[ H_1(t) = -\ln(1 - p_1) \] and \[ H_0(t) = -\ln(1 - p_0). \] The cumulative hazard ratio is \[ \cHR(t) = \frac{H_1(t)}{H_0(t)} = \frac{-\ln(1 - p_1)}{-\ln(1 - p_0)}. \tag{9.24}\] If the instantaneous hazard ratio \(h_1(t) / h_0(t)\) is constant in time, then this is equal to the cumulative hazard ratio. If the unexposed have exponential times to events, then \(h_0(t) = \lambda_0\) and the cumulative hazard ratio equals \[ \frac{H_1(t)}{H_0(t)} = \frac{\int_0^t h_1(u) \,\dif u}{\lambda_0 t} = \frac{1}{t} \int_0^t \frac{h_1(u)}{\lambda_0} \,\dif u, \] which is the average instantaneous hazard ratio over \((0, t]\).

If we take logarithms on both sides of Equation 9.24, we get \[ \ln\bigl(-\ln(1 - p_1)\bigr) = \ln(\cHR(t)) + \ln\bigl(-\ln(1 - p_0)\bigr). \] The function of \(p_1\) and \(p_0\) in this equation is the complementary log-log function \[ \cloglog(p) = \ln(-\ln (1 - p)), \] which has the inverse function \[ \cloglog^{-1}(v) = 1 - e^{-(e^v)}. \] If we have data with no delayed entry or loss to follow-up, the complementary log-log link function allows us to estimate the cumulative hazard ratio using a binomial GLM.

In a binomial GLM with the complementary log-log link, \[ \cloglog\bigl(\Pr(D = 1 \given{} X = x)\bigr) = \beta_0 + \beta_1 x. \tag{9.25}\] The cumulative hazard of disease in the unexposed (\(x = 0\)) is \(e^{\beta_0}\), so their risk of disease is \[ \cloglog^{-1}(\beta_0) = 1 - e^{-(e^{\beta_0})}. \] The cumulative hazard in the exposed (\(x = 1\)) is \(e^{\beta_0 + \beta_1}\), so their risk of disease is \[ \cloglog^{-1}(\beta_0 + \beta_1) = 1 - e^{-(e^{\beta_0 + \beta_1})}. \] The cumulative hazard ratio comparing the exposed to the unexposed is \[ \frac{e^{\beta_0 + \beta_1}}{e^{\beta_0}} = e^{\beta_1} \] Point estimates of these quantities can be obtained by replacing the unknown \(\beta_0\) and \(\beta_1\) with their maximum likelihood estimates \(\hat{\beta}_0\) and \(\hat{\beta}_1\). The \(1 - \alpha\) confidence limits for the cumulative hazard in the unexposed can be obtained by exponentiating the confidence limits for \(\beta_0\), and confidence limits for their risk of disease can be obtained by applying \(\cloglog^{-1}\) to the confidence limits for \(\beta_0\). Confidence limits for the cumulative hazard ratio can be obtained by applying \(\cloglog^{-1}\) to the \(1 - \alpha\) confidence limits for \(\beta_1\).

Because risks can be estimated for both exposure groups, we can also calculate point estimates of the risk difference, risk ratio, and odds ratio. Complementary log-log-transformed Wald confidence limits for each of these measures of association can be calculated using the multivariable version of the delta method from Section 3.4.1 and the covariance matrix from the fitted model.

The binomial GLM for the cumulative hazard ratio in Equation 9.25 assumes complete follow-up of all participants in the interval \((0, t]\) over which the risks \(p_1\) and \(p_0\) are defined, so it cannot be used if there is delayed entry or loss to follow-up. When there is delayed entry or loss to follow-up, methods from survival analysis are needed to estimate the hazard ratio.

cumhazratio-GLM.R
## Cumulative hazard ratio estimation with a GLM

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)     # rats data
library(lmtest)       # coefci() for Wald confidence intervals

# numbers of events and total rat-weeks
# The subset() function can be used as an alternative to vector indexing.
a <- sum(rats$status[rats$rx == 1])
T1 <- sum(rats$time[rats$rx == 1])
c <- with(subset(rats, rx == 0), sum(status))
T0 <- with(subset(rats, rx == 0), sum(time))
ir1hat <- a / T1
ir0hat <- c / T0
IRRhat <- ir1hat / ir0hat
lnIRRvar <- 1 / a + 1 / c
lnIRRci <- log(IRRhat) + c(-1, 1) * qnorm(0.975) * sqrt(lnIRRvar)

# point and interval estimate of the IRR
IRRhat
exp(lnIRRci)

# binomial GLM with complementary log-log link
# The cumulative hazard ratio equals the hazard ratio if the HR is constant.
HRglm <- glm(status ~ rx, family = binomial(link = "cloglog"), data = rats)
summary(HRglm)                  # point estimates, p-values, CIs, global tests
names(HRglm)                    # parts of the fitted model
exp(coef(HRglm))                # cumulative hazard (x = 0) and HR
exp(confint(HRglm))             # likelihood ratio CIs (better)
exp(coefci(HRglm))              # log-transformed Wald CI for RD matches above

# estimates of risks, RR, and RD based on log cumulative hazard
invcloglog <- function(v) 1 - exp(-exp(v))  # inverse of complementary log-log
beta0 <- coef(HRglm)["(Intercept)"]
beta1 <- coef(HRglm)["rx"]
# risk in exposed
risk1 <- a / sum(rats$rx == 1)
risk1
invcloglog(beta0 + beta1)
# risk in unexposed
risk0 <- c / sum(rats$rx == 0)
risk0
invcloglog(beta0)
# risk difference
risk1 - risk0
invcloglog(beta0 + beta1) - invcloglog(beta0)
# risk ratio
risk1 / risk0
invcloglog(beta0 + beta1) / invcloglog(beta0)
# odds ratio
odds <- function(p) p / (1 - p)
odds(risk1) / odds(risk0)
odds(invcloglog(beta0 + beta1)) / odds(invcloglog(beta0))

9.2.5 Poisson GLMs for incidence rate ratios

When times to events have an exponential(\(\lambda\)) distribution, then the number of events in a total person-time of \(T\) has a Poisson(\(\lambda T\)) distribution (see Section 5.4). In a Poisson GLM with a log link for incidence data, we have \[ \ln\big(\E[\text{count} \given{} X, T_X]\big) = \ln \lambda(X) + \ln T_X \] where \(T_X\) is the total person time in the group with exposure \(X\). Let \(\mu(x) = \lambda(x) T_x\) be expected count in the group with \(X = x\). The Poisson GLM is \[ \ln \mu(x) = \ln \lambda(x) + \ln T_x = \beta_0 + \beta_1 x + \ln T_x. \] The term \(\ln T_x\) is an offset because it has a fixed coefficient, which equals one in this case. Thus, \[ \ln \lambda(x) = \beta_0 + \beta_1 x. \] The incidence rate in the unexposed is \[ \lambda_0 = e^{\beta_0}, \] the incidence rate in the exposed is \[ \lambda_1 = e^{\beta_0 + \beta_1}, \] and the incidence rate ratio is \[ \IRR = \frac{e^{\beta_0 + \beta_1}}{e^{\beta_0}} = e^{\beta_1}. \] The point estimates and \(1 - \alpha\) confidence limits for \(\beta_0\) and \(\beta_1\), for the incidence rate in the unexposed and the IRR, and for the risk in the exposed can be obtained in the same way as in a log-binomial GLM. Because the sum of Poisson random variables is also a Poisson random variable, this models can be fit with either individual or grouped person-time data. This model does not directly assume rare events, and a robust variance is not necessary. However, if an event can occur only once per participant, the rare event assumption ensures that the count of events has a low probability of being limited by the numbers of exposed and unexposed participants in the study.

irratio-GLM.R
## Incidence rate ratio estimation with a Poisson GLM

# to get help on GLMs in R (type q to exit)
?glm
?family

# rats data is in the survival package
# Mantel, Bohidar, and Ciminera (1977). Cancer Research 37: 3863-3868.
library(survival)     # rats data
library(lmtest)       # coefci() for Wald confidence intervals

# numbers of events and total rat-weeks
# The subset() function can be used as an alternative to vector indexing.
a <- sum(rats$status[rats$rx == 1])
T1 <- sum(rats$time[rats$rx == 1])
c <- with(subset(rats, rx == 0), sum(status))
T0 <- with(subset(rats, rx == 0), sum(time))
ir1hat <- a / T1
ir0hat <- c / T0
IRRhat <- ir1hat / ir0hat
lnIRRvar <- 1 / a + 1 / c
lnIRRci <- log(IRRhat) + c(-1, 1) * qnorm(0.975) * sqrt(lnIRRvar)

# point and interval estimate of the IRR
IRRhat
exp(lnIRRci)

# Poisson GLM with log(rat-weeks) offset to get incidence rate ratio
# The default link = "log".
IRRglm <- glm(status ~ rx  + offset(log(time)), family = poisson(), data = rats)
summary(IRRglm)                 # point estimates, p-values, CIs, global tests
names(IRRglm)                   # parts of the fitted model
exp(coef(IRRglm))               # estimated incidence rate (x = 0) and IRR
exp(confint(IRRglm))            # likelihood ratio CIs (better)
exp(coefci(IRRglm))             # log-transformed Wald CI for IRR matches above

# point and interval estimates for incidence rate in the exposed
# The vector c(1, 1) represents 1 * beta0 + 1 * beta1,
# and as.numeric() is used to return a number instead of a matrix.
rate1hat <- exp(sum(coef(IRRglm)))
lnrate1var <- as.numeric(c(1, 1) %*% vcov(IRRglm) %*% c(1, 1))
rate1hat
rate1hat * exp(c(-1, 1) * qnorm(0.975) * sqrt(lnrate1var))

# Poisson regression using counts in each exposure group
# Make data frame with counts and total rat-time in each treatment group.
countdat <- data.frame(rx = c(0, 1),
                       count = as.vector(by(rats$status, rats$rx, sum)),
                       time = as.vector(by(rats$time, rats$rx, sum)))
IRRcount <- glm(count ~ rx + offset(log(time)),
                family = poisson(), data = countdat)
exp(coef(IRRcount))       # point estimates identical to IRRglm
exp(confint(IRRcount))    # likelihood ratio CIs identical to IRRglm
exp(coefci(IRRcount))     # Wald CIs also identical to IRRglm

9.2.6 Poisson GLMs for risks

For rare events (i.e., events with probabilities close to zero), the Poisson likelihood is almost the same as the binomial likelihood. If \(X \sim \text{Poisson}(p)\) and \(p\) is close to zero, then \[ \begin{aligned} \Pr(X = 0) &= e^{-p} \approx 1 - p, \\ \Pr(X = 1) &= p e^{-p} \approx p (1 - p) \approx p. \end{aligned} \] Because \((1 + p) (1 - p) = 1 - p^2\), we have \[ \Pr(X > 1) = 1 - (1 + p) e^{-p} \approx 1 - (1 + p) (1 - p) = p^2, \] which is much smaller than both \(p\) and \(1 - p\). Because \(1 - p \approx 1\), the Poisson variance \(p\) and the Bernoulli variance \(p (1 - p)\) are nearly identical for rare events.

A Poisson GLM with a log link can also be used to estimate risk ratios using counts of rare events in populations with known sizes. The expected count in each exposure group \(X = x\) is \[ \ln\big(\E[\text{count} \,\big|\, X = x, N_x]\big) = \ln p(x) + \ln N_x \] where \(p(x)\) is the risk of the event and \(N_X\) is the total population with exposure \(X\). Let \(\mu(x) = p(x) N_x\) be the expected count in the group with \(X = x\). The Poisson GLM for the risk is \[ \ln \mu(x) = \ln p(x) + \ln N_x = \beta_0 + \beta_1 x + \ln N_x. \] The term \(\ln N_x\) on the right-hand side is an offset because it has a fixed coefficient equal to one. Thus, \[ \ln p(x) = \beta_0 + \beta_1 x. \] The risk in the unexposed is \[ p_0 = e^{\beta_0}, \] the risk in the exposed is \[ p_1 = e^{\beta_0 + \beta_1}, \] and the risk ratio is \[ \RR = \frac{e^{\beta_0 + \beta_1}}{e^{\beta_0}} = e^{\beta_1}. \] The point estimates and \(1 - \alpha\) confidence limits for \(\beta_0\) and \(\beta_1\), the risk in the unexposed, the risk ratio, and the risk in the exposed can be obtained in the same way as in a log-binomial GLM. When the event is not rare, a robust variance should be used. However, this adjustment will underestimate the variance when the number of groups is small.

The primary drawback of using Poisson GLMs to estimate risks and risk ratios is that the likelihood is not quite correct—especially for events that are not rare. This limits their use in Bayesian methods and forces the use of Wald instead of score or likelihood ratio confidence intervals. However, a Poisson GLM with a log link and a robust variance is an alternative to a log-binomial GLM when the latter fails to converge.

9.3 Rothman diagrams

The unit square is the set of all ordered pairs \((x, y) \in \mathbb{R}^2\) where both \(x\) and \(y\) are in the interval \([0, 1]\). To represent a point \((x, y)\) in the unit square, we can plot \(x\) on a horizontal axis (the x-axis) and \(y\) on a vertical axis (the y-axis). Rothman (1975) introduced a very useful geometric perspective where we let \(x\) represent the risk of disease in the unexposed or untreated and \(y\) represent the risk of disease in the exposed or treated. We call these Rothman diagrams (Richardson, Robins, and Wang 2017; Kenah 2024), and they are similar to the L’Abbé plots used in meta-analysis (L’Abbé, Detsky, and O’Rourke 1987).

9.3.1 Contour lines

On a Rothman diagram, every point in the unit square represents a risk in the exposed and a risk in the unexposed. We can use these risks to calculate measures of association such as the risk difference, risk ratio, odds ratio, or (cumulative) hazard ratio. For a function \(f(x, y)\), the set of points with \(f(x, y) = m\) for any given \(m\) is called a contour line or contour of \(f\). If we think of the risk difference as a function \[ \RD(p_0, p_1) = p_1 - p_0, \] then the contour lines of \(\RD\) link the points \((p_0, p_1)\) in the unit square that have the same risk difference. Similarly, we can consider the contour lines of the risk ratio \[ \RR(p_0, p_1) = \frac{p_1}{p_0}, \] the odds ratio \[ \OR(p_0, p_1) = \frac{\odds(p_1)}{\odds(p_0)}, \] and the (cumulative) hazard ratio \[ \HR(p_0, p_1) = \frac{-\ln(1 - p_1)}{-\ln(1 - p_0)}. \] Figure 9.3 shows the contour lines for the risk difference, risk ratio, odds ratio, and hazard ratio. The null line \(p_1 = p_0\) is a contour line for all four measures of association. All other contours of the risk difference and risk ratio are straight, and all other contours of the odds ratio and hazard ratio are curved.

Code
contours.R
## Contour lines for measures of association
require(plotrix, quietly = TRUE)

# odds, logistic, and cumulative hazard functions
odds <- function(p) p / (1 - p)
invodds <- function(odds) odds / (1 + odds)
cumhaz <- function(p) -log(1 - p)

# risk difference contours
riskdiff_contours <- function() {
  plot(x, x, type = "l", main = "Risk difference contours",
       xlab = "", ylab = "Risk in the exposed")
  grid()
  boxed.labels(.5, .5, "0", xpad = 1.5, ypad = 1.5, border = FALSE)
  for (riskdiff in c(-0.5, -0.2, 0, 0.2, 0.5)) {
    y <- x + riskdiff
    yrange <- y >= 0 & y <= 1
    lines(x[yrange], y[yrange], lty = "dashed")
    boxed.labels(0.5 - riskdiff / 2, 0.5 + riskdiff / 2,
                 as.character(riskdiff),
                 xpad = 1.5, ypad = 1.5, border = FALSE)
  }
}

# risk ratio contours
riskratio_contours <- function() {
  plot(x, x, type = "l", main = "Risk ratio contours",
       xlab = "", ylab = "")
  grid()
  boxed.labels(.5, .5, "1", xpad = 1.5, ypad = 1.5, border = FALSE)
  for (riskratio in c(0.2, 0.5, 2, 5)) {
    y <- riskratio * x
    yrange <- (y <= 1)
    lines(x[yrange], y[yrange], lty = "dashed")
    boxed.labels(1 / (riskratio + 1), riskratio / (riskratio + 1),
                 as.character(riskratio),
                 xpad = 1.5, ypad = 1.5, border = FALSE)
  }
}

# odds ratio contours
oddsratio_contours <- function() {
  plot(x, x, type = "l", main = "Odds ratio contours",
       xlab = "Risk in the unexposed",
       ylab = "Risk in the exposed")
  grid()
  boxed.labels(.5, .5, "1", xpad = 1.5, ypad = 1.5, border = FALSE)
  for (oddsratio in c(0.2, 0.5, 2, 5)) {
    lines(x, invodds(oddsratio * odds(x)), lty = "dashed")
    boxed.labels((sqrt(oddsratio) - 1) / (oddsratio - 1),
                 (oddsratio - sqrt(oddsratio)) / (oddsratio - 1),
                 as.character(oddsratio),
                 xpad = 1.5, ypad = 1.5, border = FALSE)
  }
}

# hazard ratios
hazratio_contours <- function() {
  plot(x, x, type = "l", main = "Hazard ratio contours",
       xlab = "Risk in the unexposed", ylab = "")
  grid()
  boxed.labels(.5, .5, "1", xpad = 1.5, ypad = 1.5, border = FALSE)
  for (hazratio in c(0.2, 0.5, 2, 5)) {
    lines(c(x, 1), c(1 - (1 - x)^hazratio, 1), lty = "dashed")
    labelx <- uniroot(function(x) x - (1 - x)^hazratio, c(0, 1))$root
    labely <- 1 - labelx
    boxed.labels(labelx, labely, as.character(hazratio),
                 xpad = 1.5, ypad = 1.5, border = FALSE)
  }
}

# save old graphical parameters and set new ones
oldmar <- par("mar")
oldmgp <- par("mgp")
par(mfrow = c(2, 2), mar = 0.6 * (c(5, 5, 4, 1) + 0.1), mgp = c(2, 1, 0))

# grid of plots
x <- seq(0.001, 0.999, by = 0.001)
riskdiff_contours()
riskratio_contours()
oddsratio_contours()
hazratio_contours()
# dev.copy2pdf(file = "contours.pdf")

# reset graphical parameters
par(mfrow = c(1, 1), mar = oldmar, mgp = oldmgp)
Figure 9.3: Contour lines for the odds ratio, risk ratio, risk difference, and hazard ratio. The null line is solid. All other contours lines are dashed. Each contour line is labeled with the corresponding value of the measure of association.

9.3.2 Relationships among the RR, OR, and HR

The odds ratio is always farther from the null than the risk ratio because \[ \OR = \RR \frac{1 - p_0}{1 - p_1} \implies \begin{cases} \OR > \RR &\text{if } p_1 > p_0, \\ \OR = \RR &\text{if } p_1 = p_0, \\ \OR < \RR &\text{if } p_1 < p_0. \end{cases} \] Because \(\Var(\ln \hat{\OR}) > \Var(\ln \hat{\RR})\), this does not imply that a hypothesis test based on the odds ratio is more powerful than a test based on the risk ratio.

9.3.3 Relationships between changes in the RD, RR, and OR*

It is surprising but true that the odds ratio, risk ratio, and risk difference can change in different directions relative to ther null values when the risks of disease in the exposed or the unexposed change. Even if we accept this possiblity, it can seem pathological and the algebra can be complicated (Brumback and Berg 2008). The problem becomes simpler if we focus on local changes where we start at a point on a Rothman diagram and keep track of the changes in the risk difference, risk ratio, and odds ratio as we move away from it.

There are no surprises if we start on the null line where \(p_1 = p_0\), so \(\RD = 0\), \(\RR = 1\), and \(\OR = 1\). If we move along the null line, all measures stay the same. If we move to a point where \(p_1 > p_0\), then all three measures increase so \(\RD > 0\), \(\RR > 1\), and \(\OR > 1\). If we move to a point where \(p_1 < p_0\), then all three measures decrease so \(\RD < 0\), \(\RR < 1\), and \(\OR < 1\). Thus, all three measures agree about which direction we are moving relative to the null.

If we start at any point off the null line, these measures of association can change in different directions—some toward the null and others away from the null. If we allow the risk difference, risk ratio, and odds ratio to move independently toward or away from their null values, there are \(2^3 = 8\) possible combinations. It turns out that six of these combinations are possible around any point off the null line. This is hard to see algebraically, but it is easy to see on a Rothman diagram. Figure 9.4 shows the contours of the risk difference, risk ratio, and odds ratio passing through two points: (0.2, 0.6) above the null line and (0.8, 0.4) below the null line. Figure 9.5 shows the gray square around (0.2, 0.6), where the contour line for the \(\OR\) is between the contours for the \(\RD\) and \(\RR\). If the \(\RD\) and \(\RR\) both move in the same direction, the \(\OR\) must follow them—precluding two of the eight possible combinations of changes toward and away from the null. Figure 9.6 shows the gray square around (0.8, 0.4), where the contour line for the \(\RD\) is between the contours for the \(\RR\) and \(\OR\). If the \(\RR\) and \(\OR\) both move in the same direction, the \(\RD\) must follow them—which prevents two of the eight possible combinations of changes toward and away from the null. At both points, six of the eight possible combations of movements toward or away from the null are possible, one in each of the six angles defined by the contour lines through the point. However, the regions where all three measures of associaton agree about whether we are moving toward or away from the null occupy much larger angles than the regions where they disagree.

Code
changes.R
## Contours for the RD, RR, and OR at (0.2, 0.6) and (0.8, 0.4)

# required packages
require(ggplot2, quietly = TRUE)
require(geomtextpath, quietly = TRUE)

# odds and logistic functions
odds <- function(p) p / (1 - p)
invodds <- function(odds) odds / (1 + odds)

# Point A at (0.2, 0.6) with OR = 6, RR = 3, and RD = 0.4
# and point B at (0.6, 0.2) with OR = 1/6, RR = 1/3, and RD = -0.4
x <- seq(0.001, 0.999, by = 0.001)
dat <- data.frame(x = x, yORa = invodds(6 * odds(x)),
                  yRRa = 3 * x, yRDa = x + 0.4,
                  yORb = invodds(odds(x) / 6), yRRb = x / 2,
                  yRDb = x - 0.4)

# with points 1A and 1B
(ggplot(dat, aes(x, yORa))
  + theme_bw()
  + scale_x_continuous(limits = c(0, 1), expand = expansion(mult = 0.02),
                       breaks = seq(0, 1, by = 0.2))
  + scale_y_continuous(limits = c(0, 1), expand = expansion(mult = 0.02),
                       breaks = seq(0, 1, by = 0.2))
  + xlab("Risk in the unexposed")
  + ylab("Risk in the exposed")
  # point A
  + annotate("point", x = 0.2, y = 0.6, size = 3)
  + annotate("text", x = 0.2, y = 0.58, hjust = 0, vjust = 1,
             label = "(0.2, 0.6)")
  + geom_textline(label = "OR = 6", hjust = 0.8)
  + geom_textline(aes(x, yRRa), label = "RR = 3", hjust = 0.9,
                  linetype = "dashed")
  + geom_textline(aes(x, yRDa), label = "RD = 0.4", hjust = 0.9,
                  linetype = "dotted")
  + geom_textline(aes(x, x), col = "darkgray", label = "Null line")
  + annotate("rect", xmin = 0.09, xmax = 0.31, ymin = 0.49, ymax = 0.71,
             alpha = 0.2)
  + annotate("text", x = 0.11, y = 0.69, hjust = 0, vjust = 1,
             label = "Fig. 9.5")
  # point B
  + annotate("point", x = 0.8, y = 0.4, size = 3)
  + annotate("text", x = 0.8, y = 0.38, hjust = 0, vjust = 1,
             label = "(0.8, 0.4)")
  + geom_textline(aes(x, yORb), hjust = 0.8, label = "OR = 1/6")
  + geom_textline(aes(x, yRRb), hjust = 0.5, linetype = "dashed",
                  label = "RR = 1/2")
  + geom_textline(aes(x, yRDb), hjust = 0.05, linetype = "dotted",
                  label = "RD = -0.4")
  + annotate("rect", xmin = 0.69, xmax = 0.91, ymin = 0.29, ymax = 0.51,
             alpha = 0.2)
  + annotate("text", x = 0.71, y = 0.49, hjust = 0, vjust = 1,
             label = "Fig. 9.6")
)
Figure 9.4: Rothman diagram showing the contour lines for the odds ratio (solid), risk ratio (dashed), and risk difference (dotted) that pass through the point \((0.2, 0.6)\) above the null line and the point \((0.8, 0.4)\) below the null line. The gray squares are the areas shown in Figure 9.5 and Figure 9.6.
Code
changesA.R
## Local changes in the RD, RR, and OR near (0.2, 0.6)

# required packages
require(ggplot2, quietly = TRUE)
require(geomtextpath, quietly = TRUE)

# odds and logistic functions, conversion from degrees to radians
odds <- function(p) p / (1 - p)
invodds <- function(odds) odds / (1 + odds)
degtorad <- function(degrees) pi * (degrees / 180)

# Point A at (0.2, 0.6) with OR = 6, RR = 3, and RD = 0.4
# and point B at (0.6, 0.2) with OR = 1/6, RR = 1/3, and RD = -0.4
x <- seq(0.001, 0.999, by = 0.001)
datA <- data.frame(x = x, yORa = invodds(6 * odds(x)),
                   yRRa = 3 * x, yRDa = x + 0.4)

# plot of contours near point A
(ggplot(datA, aes(x, yORa))
  + coord_cartesian(xlim = c(0.1, 0.3), ylim = c(0.5, 0.7))
  + xlab("Risk in the unexposed")
  + ylab("Risk in the exposed")
  + annotate("point", x = 0.2, y = 0.6, size = 3)
  + annotate("text", 0.202, 0.598, hjust = 0, vjust = 1, label = "(0.2, 0.6)")
  + geom_textline(label = "OR = 6", hjust = 0.385)
  + geom_textline(aes(x, yRDa), label = "RD = 0.40", hjust = 0.22,
                  linetype = "dotted")
  + geom_textline(aes(x, yRRa), label = "RR = 3", hjust = 0.208,
                  linetype = "dashed")
  + annotate("text", 0.25, 0.55,
             label = "All toward the null\n OR < 6, RR < 3, RD < 0.4")
  + annotate("text", 0.15, 0.65,
             label = "All away from the null\n OR > 6, RR > 3, RD > 0.4")
  + annotate("text", angle = 49,
             x = 0.2 + 0.09 * cos(degtorad(49)),
             y = 0.6 + 0.09 * sin(degtorad(49)),
             label = "OR < 6, RR < 3, RD > 0.4")
  + annotate("text", angle = 63,
             x = 0.2 + 0.09 * cos(degtorad(63)),
             y = 0.6 + 0.09 * sin(degtorad(63)),
             label = "OR > 6, RR < 3, RD > 0.4")
  + annotate("text", angle = 52,
             x = 0.2 + 0.09 * cos(degtorad(180 + 52)),
             y = 0.6 + 0.09 * sin(degtorad(180 + 52)),
             label = "OR > 6, RR > 3, RD < 0.4")
  + annotate("text", angle = 66,
             x = 0.2 + 0.087 * cos(degtorad(180 + 66)),
             y = 0.6 + 0.087 * sin(degtorad(180 + 66)),
             label = "OR < 6, RR > 3, RD < 0.4")
)
Figure 9.5: The odds ratio, risk ratio, and risk difference near the point \((0.2, 0.6)\). The contour line for the odds ratio (solid) is between the contours for the risk difference (dotted) and risk ratio (dashed). Six combinations of changes toward and away from the null are possible when starting from this point, but the odds ratio must follow the risk difference and risk ratio if they move in the same direction.
Code
changesB.R
## Local changes in the RD, RR, and OR near (0.8, 0.4)

# required packages
require(ggplot2, quietly = TRUE)
require(geomtextpath, quietly = TRUE)

# odds and logistic functions, conversion from degrees to radians
odds <- function(p) p / (1 - p)
invodds <- function(odds) odds / (1 + odds)
degtorad <- function(degrees) pi * (degrees / 180)

# Point A at (0.2, 0.6) with OR = 6, RR = 3, and RD = 0.4
# and point B at (0.6, 0.2) with OR = 1/6, RR = 1/3, and RD = -0.4
x <- seq(0.001, 0.999, by = 0.001)
datB <- data.frame(x = x, yORb = invodds(odds(x) / 6), yRRb = x / 2,
                   yRDb = x - 0.4)

(ggplot(datB, aes(x, yORb))
  + coord_cartesian(xlim = c(0.7, 0.9), ylim = c(0.3, 0.5))
  + xlab("Risk in the unexposed")
  + ylab("Risk in the exposed")
  + annotate("point", x = 0.8, y = 0.4, size = 3)
  + annotate("text", 0.802, 0.398, hjust = 0, vjust = 1, label = "(0.8, 0.4)")
  + geom_textline(label = "OR = 1/6", hjust = 0.615)
  + geom_textline(aes(x, yRDb), label = "RD = -0.4", hjust = 0.78,
                  linetype = "dotted")
  + geom_textline(aes(x, yRRb), label = "RR = 1/2", hjust = 0.84,
                  linetype = "dashed")
  + annotate("text", 0.75, 0.45,
             label = "All toward the null\n OR > 1/6, RR > 1/2, RD > -0.4")
  + annotate("text", 0.85, 0.35,
             label = "All away from the null\n OR < 1/6, RR < 1/2, RD < -0.4")
  + annotate("text", angle = 36,
             x = 0.8 + 0.09 * cos(degtorad(36)),
             y = 0.4 + 0.09 * sin(degtorad(36)),
             label = "OR < 1/6, RR > 1/2, RD < -0.4")
  + annotate("text", angle = 52,
             x = 0.8 + 0.09 * cos(degtorad(52)),
             y = 0.4 + 0.09 * sin(degtorad(52)),
             label = "OR < 1/6, RR > 1/2, RD > -0.4")
  + annotate("text", angle = 36,
             x = 0.8 + 0.09 * cos(degtorad(180 + 36)),
             y = 0.4 + 0.09 * sin(degtorad(180 + 36)),
             label = "OR > 1/6, RR < 1/2, RD > -0.4")
  + annotate("text", angle = 47,
             x = 0.8 + 0.095 * cos(degtorad(180 + 49)),
             y = 0.4 + 0.095 * sin(degtorad(180 + 49)),
             label = "OR > 1/6, RR < 1/2, RD < -0.4")
)
Figure 9.6: The odds ratio, risk ratio, and risk difference near the point \((0.8, 0.4)\). The contour line for the risk difference (dotted) is between the contours for the risk ratio (dashed) and the odds ratio (solid). Six combinations of changes toward and away from the null are possible in any neighborhood of the point, but the risk difference must follow the risk ratio and odds ratio if they move in the same direction.