| x = 70°F | x = 60°F | x = 50°F | x = 31°F | |
|---|---|---|---|---|
| Probability \hat{\pi}(x) | 0.047 | 0.136 | 0.333 | 0.818 |
| Odds \widehat{\text{odds}}(x) | 0.049 | 0.157 | 0.499 | 4.488 |
Statistics III - CdL SSE
Università degli Studi di Milano-Bicocca
GLMs for binary data and binomial data are very common, whenever the response variable is dichotomous (e.g., success/failure, yes/no, dead/alive, diseased/healthy, etc.).
This unit will cover a few additional topics related to binary and binomial regression, including:
The most important aspects have already been covered in Unit B.
In a binomial regression model, we observe S_i successes out of m_i trials S_i \overset{\text{ind}}{\sim} \text{Binomial}(m_i, \pi_i), \qquad g(\pi_i) = \eta_i = \bm{x}_i^T \beta, \qquad i=1,\dots,n. We model the proportions Y_i = S_i / m_i, whose mean is indeed \pi_i and Y_i \overset{\text{ind}}{\sim} \text{ED}(\mu_i, \mu_i(1-\mu_i)/m_i).
In a binary regression model, we observe Y_i \in \{0,1\}, which is a special case of the model above with number of trials m_i = 1 for all i. Thus, we have Y_i \overset{\text{ind}}{\sim} \text{Bernoulli}(\pi_i), \qquad g(\pi_i) = \eta_i = \bm{x}_i^T \beta, \qquad i=1,\dots,n.
In this unit, we distinguish between two sample size measures:
If Y_{ij} \in \{0,1\} are independent Bernoulli random variables with success probability \pi_i, for j=1,\dots, m_i and i=1,\dots, n, then S_i = \sum_{j=1}^{m_i} Y_{ij} \sim \text{Binomial}(m_i, \pi_i).
Thus, any binomial regression model can be ungrouped into a binary regression model with N = \sum_{i=1}^n m_i observations, by replicating the covariate vector \bm{x}_i m_i times, with S_i of the corresponding binary responses equal to 1 and the remaining m_i - S_i equal to 0.
On the other hand, a binary regression model can be grouped only if multiple subjects share the same values for explanatory variables, which is common if they are all categorical.
The likelihood function of these two representations coincide up to a proportionality constant, which means that the maximum likelihood \hat{\beta} and the standard errors are identical.
However, the deviance and the residuals are different, which has implications for goodness-of-fit tests and model diagnostics. The diagnostics for binary data are typically uninformative.
As discussed, the link function is usually set to g(\cdot) = F^{-1}(\cdot) for some continuous cumulative distribution function F(\cdot) : \mathbb{R} \to (0,1). In other words, g(\pi_i) = F^{-1}(\pi_i) = \bm{x}_i^T\beta, that is \mu_i = \pi_i = F(\bm{x}_i^T\beta). The function F(\cdot) is strictly increasing, differentiable, and maps the real line to the unit interval.
Logit link. The canonical link is the logistic link (or logit link), that is g(\pi_i) = \log\left(\frac{\pi_i}{1-\pi_i}\right) = \bm{x}_i^T\beta, \qquad \text{ with inverse} \qquad \pi_i = \frac{\exp(\bm{x}_i^T\beta)}{1 + \exp(\bm{x}_i^T\beta)}. Indeed, the function F(z) = \exp(z)/(1+\exp(z)) with z \in \mathbb{R} is the cdf of a logistic distribution with mean 0 and variance \pi^2/3.
Probit link. The probit link is based on the standard normal cdf \Phi(\cdot), i.e. g(\pi_i) = \Phi^{-1}(\pi_i) = \bm{x}_i^T\beta, \qquad \text{with inverse} \qquad \pi_i = \Phi(\bm{x}_i^T\beta). The function \Phi(z) with z \in \mathbb{R} is usually computed numerically and equals \Phi(z) = \int_{-\infty}^z \frac{1}{\sqrt{2\pi}} \exp\left(-\frac{u^2}{2}\right) du.
Complementary log-log link. The complementary log-log (cloglog) link is g(\pi_i) = \log(-\log(1-\pi_i)) = \bm{x}_i^T\beta, \qquad \text{with inverse} \qquad \pi_i = 1 - \exp(-\exp(\bm{x}_i^T\beta)). The distribution function F(z) = 1 - \exp(-\exp(z)) with z \in \mathbb{R} is the cdf of a Gumbel distribution (for minima). This link function is asymmetric.
Cauchy link. The Cauchy link is g(\pi_i) = \tan(\pi(\pi_i - 1/2)), \qquad \text{with inverse} \qquad \pi_i = \frac{1}{2} + \frac{\text{arctan}(\bm{x}_i^T\beta)}{\pi}. F(z) = 1/2 + \text{arctan}(z)/\pi with z \in \mathbb{R} is the cdf of a standard Cauchy distribution.
A latent variable threshold model is a useful way to interpret binary regression models and to choose their link function g(\cdot). Let Y_i^* be a latent and continuous random variable such that Y_i^* = \bm{x}_i^T\beta + \epsilon_i, \qquad \epsilon_i \overset{\text{iid}}{\sim} F.
A variable is called latent because we do not observe it directly. Instead, we observe only a binary variable encoding whether it exceeds a certain threshold, i.e. Y_i = \mathbb{I}(Y_i^* > \tau), where \mathbb{I}(\cdot) is the indicator function and \tau is a threshold.
By construction, we have Y_i \sim \text{Bernoulli}(\pi_i), with \begin{aligned} \pi_i &= \mathbb{P}(Y_i = 1) = \mathbb{P}(Y_i^* > \tau) = \mathbb{P}(\bm{x}_i^T\beta + \epsilon_i > \tau) = 1 - \mathbb{P}(\epsilon_i \le \tau - \bm{x}_i^T\beta)= 1 - F(\tau - \bm{x}_i^T\beta). \end{aligned}
The data contain no information about \tau, so we can set \tau = 0 without loss of generality. Equivalently, the value of \tau is absorbed into the intercept term.
Likewise, an equivalent model results if we multiply all parameters by any positive constant, so we can take F to have a standard form with fixed variance, such as the standard normal cdf.
This dichotomization often corresponds to a real process — for instance, in medical diagnosis, preterm birth can be seen as a dichotomization of gestational age at delivery.
However, there are cases where the existence of a latent quantity is more questionable, such as Y_i^* corresponding to a notion of “ability” and Y_i to “passing an exam”.
The likelihood equations of a binomial regression model are fairly simple: \sum_{i=1}^n \frac{m_i (y_i - \pi_i)}{\pi_i(1 - \pi_i)} x_{ir} f(\eta_i) = 0, \qquad r=1,\dots, p, where f(z) is the density associated with F(z), i.e. its derivative, and the link is g(\cdot) = F^{-1}(\cdot).
In logistic regression f(\eta_i) = F(\eta_i)(1 - F(\eta_i)) = \pi_i(1 - \pi_i), therefore \sum_{i=1}^n m_i (y_i - \pi_i) x_{ir} = 0, \qquad r=1,\dots, p. The solution has a nice interpretation as a method of moments estimator, in that \sum_{i=1}^n s_i x_{ir} = \sum_{i=1}^n \mathbb{E}(S_i) x_{ir}, \qquad r=1,\dots, p. Moreover, the estimated covariance matrix of \hat{\beta} has a simple form: \widehat{\text{var}}(\hat{\beta}) = (\bm{X}^T \hat{\bm{W}} \bm{X})^{-1} = (\bm{X}^T \text{diag}[m_1 \hat{\pi}_1 (1-\hat{\pi}_1),\dots,m_n \hat{\pi}_n (1-\hat{\pi}_n)] \bm{X})^{-1}.
We wish to compare two estimated probabilities, corresponding to two different covariate vectors \bm{x} = (x_1,\dots,x_p) and \bm{x}' = (x_1',\dots,x_p'), namely \pi(\bm{x}) = F(\bm{x}^T\beta)\qquad \text{and} \qquad \pi(\bm{x}') = F((\bm{x}')^T\beta). This is useful to understand the effect of changing covariates on the response probability.
There are several ways to compare them, listed below, each with its advantages and disadvantages:
The risk difference, namely the difference (\text{risk difference}) = \pi(\bm{x}') - \pi(\bm{x}).
The relative risk is the fraction (\text{relative risk}) = \frac{\pi(\bm{x}')}{\pi(\bm{x})}.
Both these indicators are quite interpretable but depend on the specific values of \bm{x} and \bm{x}', which makes it difficult to summarize the effect of a given covariate in a single number.
The odds is another way of summarizing probabilities, familiar to those who gamble: \text{odds}(\bm{x}) = \frac{\pi(\bm{x})}{1-\pi(\bm{x})}. The odds are non-negative, with \text{odds}(\bm{x}) > 1 when a success is more likely than a failure.
When \pi(\bm{x}) = 0.75 then \text{odds}(\bm{x}) = 0.75/0.25 = 3; a success is three times as likely as a failure. That is, we bet 3 to get 1 if we win. If instead \text{odds}(\bm{x}) = 1 / 3, we bet 1 to get 3 if we win.
The odds ratio is another popular risk measure for comparing the two probabilities: (\text{odds ratio}) = \frac{\text{odds}(\bm{x}') }{\text{odds}(\bm{x}) }= \frac{\pi(\bm{x}')}{\pi(\bm{x})} \cdot \frac{1-\pi(\bm{x})}{1-\pi(\bm{x}')}.
Let \bm{x} = (x_1,\dots, x_j, \dots, x_p) and \bm{x}' = (x_1, \dots, x_j + c, \dots, x_p), i.e. we compare two situations in which the jth covariate is increased by a fixed amount c, then in logistic regression: (\text{odds ratio}) = \exp(c \beta_j), which is a constant number that does not depend on \bm{x}. This is not true e.g. in probit.
Let \bm{x} be a generic covariate vector and consider its odds under a logistic regression model: \text{odds}(\bm{x}) = \frac{\pi(\bm{x})}{1-\pi(\bm{x})} = \frac{\exp(\bm{x}^T\beta)}{1 + \exp(\bm{x}^T\beta)} \cdot \left(\frac{1}{1 + \exp(\bm{x}^T\beta)}\right)^{-1} = \exp(\bm{x}^T\beta). Thus, the odds at any covariate value are simply the exponential of the linear predictor \bm{x}^T\beta.
Consequently, in general the odds ratio is (\text{odds ratio}) = \frac{\text{odds}(\bm{x}') }{\text{odds}(\bm{x}) } = \exp\{(\bm{x}'- \bm{x})^T\beta \}.
If the only change is in the jth covariate, from x_j to x_j + c, then the odds ratio becomes (\text{odds ratio}) = \exp\{(\bm{x}'- \bm{x})^T\beta \} = \exp(c \beta_j). In particular, \exp(\beta_j) represents the odds ratio after a unit increase of the jth covariate.
In presence of binary data, namely when m_i = 1 and Y_i \sim \text{Bernoulli}(\pi_i), many of the diagnostic tools are degenerate and uninformative.
For example, the fitted vs residuals plot, namely the scatter plot of the points (\hat{\pi}_i, y_i - \hat{\pi}_i), simply shows two parallel lines with slope -1, which is uninformative.
As an extreme case, consider the null model in which \pi_1 = \dots = \pi_n, then the X^2 statistic is X^2 = \sum_{i=1}^n \frac{(y_i - \hat{\pi})^2}{\hat{\pi}(1 - \hat{\pi})} = n, whatever the observed data, since \hat{\pi} = \bar{y} and therefore \sum_{i=1}^n(y_i - \bar{y})^2 = n\bar{y}(1-\bar{y}).
A common solution is to group the data according to some criterion, although this introduces approximations and some arbitrariness (e.g. the Hosmer–Lemeshow test).
In terms of prediction, there exist various indices and techniques that you will cover in Data Mining. The simplest index is the accuracy, i.e. the fraction of correct predictions.
In binomial regression the main assumption is that S_i \sim \text{Binomial}(m_i, \pi_i), implying that \text{var}(Y_i) = \frac{\pi_i(1-\pi_i)}{m_i}, where implicitly we have set \phi = 1.
However, from the analysis of the residuals or by computing the X^2 statistic we may realize that the data present overdispersion, namely a more appropriate model is such that \text{var}(Y_i) = \textcolor{red}{\phi} \frac{\pi_i(1-\pi_i)}{m_i}, with \phi > 1. This implies that the binomial regression model is misspecified.
Overdispersion can only occur with grouped data: when m_i = 1, any distribution on \{0, 1\} has variance \pi_i(1-\pi_i), so necessarily \phi = 1.
shuttle data
The space shuttle Challenger broke apart 73 seconds after its launch on 28 January 1986. All seven crew members died.
The Presidential Commission found that the cause was a gas leak through a joint of the right solid rocket motor.
The joint was sealed by rubber O-rings, which do not seal properly at low temperatures.
The forecast for the launch was 31°F (about -0.5°C).
Netflix docuseries: Challenger: The Final Flight (2020)
Dalal et al. (1989), Risk analysis of the space shuttle: pre-Challenger prediction of failure, JASA.

The two solid rocket motors have six field joints in total. Each joint is sealed by a primary and a secondary O-ring.
A primary O-ring experiences thermal distress if:
Bench tests had shown that O-rings lose their resilience at low temperatures.
During a public hearing, Richard Feynman showed this by dipping a piece of O-ring in a glass of ice water.

On 27 January 1986, engineers of Morton Thiokol, the manufacturer of the motors, and NASA discussed the launch in a teleconference.
The discussion focused on the plot on the left:
Some engineers asked to postpone the launch, but Thiokol concluded that “temperature data [are] not conclusive”.
The launch was approved.
shuttle datasetThe shuttle dataset of the SMPracticals library contains the data of the 23 flights before the accident.
r: number of primary field-joint O-rings with thermal distress, out of m = 6;temperature: calculated joint temperature at launch (°F);pressure: pressure of the leak-check test performed before each launch (psi). m r temperature pressure
1 6 0 66 50
2 6 1 70 50
3 6 0 69 50
4 6 0 68 50
5 6 0 67 50
6 6 0 72 50
There were 24 launches before the accident, but the motors of one flight were lost at sea.
The leak-check pressure was increased over time: 50 psi in the first six flights, 100 psi in the next two, then 200 psi.
As temperature decreases, the proportion of distressed O-rings increases. There is less pattern for pressure.
All the 16 flights left out the night before were launched at 66°F or above.
The dotted line is the 31°F forecast, 22°F below the coldest previous launch (53°F).
shuttle dataLet S_i be the number of distressed O-rings in the ith flight. If, within each flight, the six O-rings fail independently and with the same probability \pi_i, then S_i \overset{\text{ind}}{\sim} \text{Binomial}(6, \pi_i), \qquad i = 1,\dots,23.
We consider a logistic regression model, with x_{i1} the temperature and x_{i2} the pressure: \text{logit}(\pi_i) = \log\left(\frac{\pi_i}{1 - \pi_i}\right) = \beta_1 + \beta_2 x_{i1} + \beta_3 x_{i2}.
Our main goal is the probability of thermal distress at 31°F which, if pressure has no effect (\beta_3 = 0), is \psi = \frac{\exp(\beta_1 + 31 \beta_2)}{1 + \exp(\beta_1 + 31 \beta_2)}.
Call:
glm(formula = cbind(r, m - r) ~ temperature + pressure, family = binomial,
data = shuttle)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.520195 3.486784 0.723 0.4698
temperature -0.098297 0.044890 -2.190 0.0285 *
pressure 0.008484 0.007677 1.105 0.2691
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 24.230 on 22 degrees of freedom
Residual deviance: 16.546 on 20 degrees of freedom
AIC: 36.106
Number of Fisher Scoring iterations: 5
Call:
glm(formula = cbind(r, m - r) ~ temperature, family = binomial,
data = shuttle)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 5.08498 3.05247 1.666 0.0957 .
temperature -0.11560 0.04702 -2.458 0.0140 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 24.230 on 22 degrees of freedom
Residual deviance: 18.086 on 21 degrees of freedom
AIC: 35.647
Number of Fisher Scoring iterations: 5
The intercept \hat{\beta}_1 is not of interest:
An increase of 1°F multiplies the odds of distress by \exp(\hat{\beta}_2) = 0.891, i.e. the odds decrease by 10.9%, whatever the starting temperature.
A decrease of 10°F, from x to x - 10, gives the odds ratio \frac{\widehat{\text{odds}}(x - 10)}{\widehat{\text{odds}}(x)} = \frac{\exp\{\hat{\beta}_1 + \hat{\beta}_2 (x - 10)\}}{\exp(\hat{\beta}_1 + \hat{\beta}_2 x)} = \exp(-10 \hat{\beta}_2) = 3.177, that is, the odds increase by 100 \times (3.177 - 1) = 217.7%, whatever the starting temperature.
| x = 70°F | x = 60°F | x = 50°F | x = 31°F | |
|---|---|---|---|---|
| Probability \hat{\pi}(x) | 0.047 | 0.136 | 0.333 | 0.818 |
| Odds \widehat{\text{odds}}(x) | 0.049 | 0.157 | 0.499 | 4.488 |
| Temperature (°F) | Risk difference | Relative risk | Odds ratio |
|---|---|---|---|
| 70 → 60 | 0.089 | 2.882 | 3.177 |
| 60 → 50 | 0.197 | 2.452 | 3.177 |
The odds ratio is a variation of the odds, not of the probabilities. For instance, from 60°F to 50°F the probability of distress is multiplied by 2.452, not by 3.177.
| Lower | Upper | |
|---|---|---|
| Wald, delta method | 0.346 | 1.289 |
| Wald, logit scale | 0.160 | 0.991 |
The Wald interval for \psi based on the delta method contains values greater than one, so it is inappropriate.
The Wald interval computed on the logit scale and then transformed, as in Unit B, always lies in (0, 1).
Estimated probability of distress, with pointwise 95% confidence intervals computed on the logit scale.
The prediction at 31°F is an extrapolation far outside the data, but there would have been little alternative.
The deviances are 18.09 (logit), 18.31 (probit) and 18.01 (cloglog): the three fits are almost identical in the range of the data.
However, the estimated probabilities at 31°F are different: 0.82, 0.70 and 0.97, respectively.
Goodness of fit: the deviance is 18.09 on 21 degrees of freedom and X^2 = 29.98.
The temperature effect is robust: logit, probit and cloglog links fit the data equally well and agree on its sign.
At 31°F we are extrapolating, 22°F below any previous launch: the 95% confidence interval for \psi is (0.16, 0.99).
Yet all models point to a high probability of distress at 31°F, and no data supported the safety of such a launch.
The prediction is uncertain, but given the catastrophic consequences of a failure, caution would have required to postpone the launch.

The crew of the Challenger. Source: NASA.
The Rogers Commission: “a careful analysis of the flight history of O-ring performance would have revealed the correlation of O-ring damage in low temperature”.
Building on this model, Dalal et al. (1989) estimated a probability of catastrophic failure of at least 0.13 at 31°F, against 0.02 at 60°F.
After the accident, NASA started to perform probabilistic risk assessments. Crewed flights resumed only in September 1988.
The lesson: never discard the zeros. The flights with no incidents are the ones showing that warm launches were safe.