PS 818 - Data Analysis with Statistical Models
September 28, 2026
\[ \DeclareMathOperator*{\argmin}{arg\,min} \DeclareMathOperator*{\argmax}{arg\,max} \]
Generalized linear models: a link function \(g()\) relating the CEF to the linear predictor
\[g(\mathbb{E}[Y_i|X_i]) = X_i^{\prime}\beta\]
Binary outcome models: the logit and probit, estimated by maximum likelihood
Inference on transformations: invariance gives us the point estimate, the delta method gives us the standard error.
We used all of this to estimate propensity scores and construct an IPTW estimator.
Another common way of formulating discrete outcome regressions is in terms of an unobserved continuous “latent” variable and an observation mechanism.
For the logistic regression
\[Y_i = \mathbb{1}(Y_i^* \ge 0)\] \[Y_i^* = X_i^{\prime}\beta + \epsilon_i\] \[\epsilon_i \sim \text{Logistic}(0, 1)\]
The Logistic distribution is parameterized in terms of a “location” (mean) \(\mu\) and a “scale” parameter \(s>0\).
\[\Pr(\epsilon_i \le x) = \frac{1}{1 + \exp(-x)}\]
So what’s \(\mathbb{E}[Y_i|X_i] = \Pr(Y_i = 1|X_i)\)?
\[\Pr(Y_i = 1|X_i) = \Pr(Y_i^* \ge 0 | X_i) = \Pr(\epsilon_i \ge -X_i^{\prime}\beta) = \Pr(\epsilon_i \le X_i^{\prime}\beta) = \frac{1}{1 + \exp(-X_i^{\prime}\beta)}\]
We can write the probit similarly, defining the error distribution as
\[\epsilon_i \sim \text{Normal}(0, 1)\]
And by extension, the probability \(\Pr(Y_i = 1|X_i)\)
\[\Pr(Y_i = 1|X_i) = \Pr(Y_i^* \ge 0|X_i) = \Pr(\epsilon_i \le X_i^{\prime}\beta) = \Phi(X_i^{\prime}\beta)\]
Note the scale of \(\epsilon_i\) is fixed by assumption, not estimated
In an ordered logit model, an ordinal outcome \(Y\) with \(L\) unique, ordered values \(Y \in \{1, 2, 3, \dotsc L\}\) is a function of a latent variable and a set of \(L-1\) cutpoints \(\kappa\)
\[Y_i = \begin{cases}1 &\text{if } Y_i^* \le \kappa_1 \\ 2 &\text{if } \kappa_1 < Y_i^* \le \kappa_2\\ 3 &\text{if } \kappa_2 < Y_i^* \le \kappa_3\\ \vdots &\\ L &\text{if } Y_i^* > \kappa_{L-1}\end{cases}\]
We still assume \(Y_i^*\) has a logistic distribution
\[Y_i^* = X_i^{\prime}\beta + \epsilon_i, \qquad \epsilon_i \sim \text{Logistic}(0, 1)\]
To estimate the model, we now have to estimate both the \(\beta\) parameters and the \(\kappa\) parameters
How does the model map changes in the latent variable to changes in probability? Work with the cumulative probabilities:
\[\Pr(Y_i \le l \,|\, X_i) = \Pr(Y_i^* \le \kappa_l \,|\, X_i) = \Pr(\epsilon_i \le \kappa_l - X_i^{\prime}\beta)\]
And then difference adjacent cumulatives to get each cell probability
\[\Pr(Y_i = l \,|\, X_i) = \Pr(Y_i \le l \,|\, X_i) - \Pr(Y_i \le l-1 \,|\, X_i)\]
with the conventions \(\Pr(Y_i \le 0) = 0\) and \(\Pr(Y_i \le L) = 1\).
This structural mapping from \(Y^*\) to \(\Pr(Y_i = l)\) encodes a particular assumption about how these probabilities relate to one another.
Referred to as the proportional odds assumption
\[\log\left(\frac{\Pr(Y_i \le l)}{1 - \Pr(Y_i \le l)}\right) = \kappa_l - X_i^{\prime}\beta\]
Intuitively: the \(\beta\) parameters are shared across all the possible outcome levels. Information about whether someone responds “strongly agree” also tells us something about how likely they would be to respond “agree”, “neutral”, “disagree”, or “strongly disagree”.
In a setting with multiple unordered outcomes, the natural extension of the logit regression is the multinomial logit
Suppose we have an outcome with \(K\) unordered levels (e.g. “choices”). Define a latent “utility” \(Y_{ik}^*\) for each of the \(K\) categories
\[\begin{align*}Y_{i1}^* &= X_i^{\prime}\beta_1 + \epsilon_{i1} = \epsilon_{i1}\\ Y_{i2}^* &= X_i^{\prime}\beta_2 + \epsilon_{i2}\\ &\vdots \\ Y_{iK}^* &= X_i^{\prime}\beta_K + \epsilon_{iK}\end{align*}\]
The probability of observing choice \(Y_{i} = k\) is the probability that the \(k\)th latent variable is greater than all of the others
\[\Pr(Y_i = k \,|\, X_i) = \Pr\big(Y^*_{ik} = \max\{Y^*_{i1}, Y^*_{i2}, \dotsc Y^*_{iK}\}\big)\]
It turns out that if the error terms \(\epsilon_{ik}\) have i.i.d. “Type I extreme value” distributions, we can write the choice probabilities in closed form
\[\Pr(Y_i = k \,|\, X_i) = \frac{\exp(X_i^{\prime}\beta_{k})}{\sum_{l=1}^K \exp(X_i^{\prime}\beta_{l})}\]
This is sometimes referred to as the “softmax” function in machine learning.
Note: with the normalized baseline category \(\beta_1 = 0\), we can write this equivalently as
\[\Pr(Y_i = k \,|\, X_i) = \frac{\exp(X_i^{\prime}\beta_{k})}{1 + \sum_{l=2}^K \exp(X_i^{\prime}\beta_{l})}\]
The i.i.d. error assumption implies independence of irrelevant alternatives (IIA).
-99 is the survey platform’s missing-value codestudy1 <- study1 %>%
mutate(isReimbursementFolded_Factor = case_when(
isReimbursementFolded == 1 ~ "Winner pays all",
isReimbursementFolded == 2 ~ "Winner pays some",
isReimbursementFolded == 3 ~ "Split costs",
isReimbursementFolded == 4 ~ "Loser pays some",
isReimbursementFolded == 5 ~ "Loser pays all"))
study1$isReimbursementFolded_Factor <- factor(
study1$isReimbursementFolded_Factor,
levels = c("Winner pays all", "Winner pays some", "Split costs",
"Loser pays some", "Loser pays all"), ordered = TRUE)
Winner pays all Winner pays some Split costs Loser pays some
0 0 76 59
Loser pays all
109
ordinal packageformula: isReimbursementFolded_Factor ~ isAppointerSide
data:
study1_complete %>% filter(isAppointerSide == "Appointed by Winner" | isAppointerSide == "Appointed by Loser")
link threshold nobs logLik AIC niter max.grad cond.H
logit flexible 123 -128.28 262.57 5(0) 2.98e-13 1.5e+01
Coefficients:
Estimate Std. Error z value Pr(>|z|)
isAppointerSideAppointed by Winner 0.411 0.340 1.21 0.23
Threshold coefficients:
Estimate Std. Error z value
Split costs|Loser pays some -0.672 0.262 -2.56
Loser pays some|Loser pays all 0.302 0.256 1.18
Group Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
Loser pays all 0.1022 0.0839 1.22 0.223 2.2 -0.0623 0.2667
Loser pays some -0.0170 0.0156 -1.09 0.275 1.9 -0.0476 0.0135
Split costs -0.0851 0.0706 -1.21 0.228 2.1 -0.2235 0.0532
Term: isAppointerSide
Type: prob
Comparison: Appointed by Winner - Appointed by Loser
Group Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
Loser pays all 0.180 0.0892 2.015 0.0439 4.5 0.00494 0.3546
Loser pays some -0.197 0.0773 -2.544 0.0110 6.5 -0.34834 -0.0452
Split costs 0.017 0.0826 0.205 0.8372 0.3 -0.14498 0.1789
Term: isAppointerSide
Type: probs
Comparison: Appointed by Winner - Appointed by Loser
The latent-variable story generalizes naturally: let \(U_{ij}\) be the utility individual \(i\) gets from alternative \(j\)
\[U_{ij} = V_{ij} + \epsilon_{ij} = X_{ij}^{\prime}\beta + \epsilon_{ij}\]
Individual \(i\) chooses the alternative with the highest utility
\[Y_i = \argmax_{j \in \{1, \dotsc, J\}} U_{ij}\]
The systematic component \(V_{ij}\) is what we model; \(\epsilon_{ij}\) is everything we don’t observe.
This is the random utility model (RUM) – the microeconomic foundation for discrete choice (McFadden 1974).
McFadden (1974) showed that if the \(\epsilon_{ij}\) are i.i.d. Type-I Extreme Value (Gumbel), the choice probabilities have a closed form
\[\Pr(Y_i = j \,|\, X_i) = \frac{\exp(X_{ij}^{\prime}\beta)}{\sum_{k=1}^J \exp(X_{ik}^{\prime}\beta)}\]
Compare this to the multinomial logit we just derived:
Conditional logit lets us model the attributes of the choices themselves – price, distance, ideological position – not just the attributes of the chooser.
The i.i.d. extreme value assumption buys us the closed form, but it also imposes IIA
\[\frac{\Pr(Y_i = j)}{\Pr(Y_i = k)} = \exp\big((X_{ij} - X_{ik})^{\prime}\beta\big)\]
The red bus/blue bus problem again, now with a name for the culprit: the errors are independent across alternatives.
Ways out:
Often we have outcome data that is measured as the “time-to-event”
Assume we observe N i.i.d. event times \(T_1, T_2, \dotsc, T_n\)
Define the “survival function”
\[S(t) = Pr(T > t) = 1 - F(t)\]
We’ll also often work with the “hazard” or the “instantaneous” probability of an event happening given that it has not yet occurred
\[h(t) = \underset{\Delta t \to 0}{\lim} \frac{P(t < T_i \le t + \Delta t | T_i > t)}{\Delta t} = \frac{f(t)}{S(t)} = \frac{f(t)}{1-F(t)}\]
Intuitively: Given that I know that an event has not occurred until \(t\), what is the probability that it will immediately occur next!
We’ll also define the cumulative hazard
\[H(t) = \int_{0}^{t} h(u)du = \int_0^{t} \frac{f(u)}{S(u)} du = -\log(S(t))\]
Start by arranging the possible event times from \(0 < t_{(1)} < t_{(2)} < t_{(3)} < t_{(4)}, \dotsc, < t_{(n)}\)
\[S(t) = Pr(T_i > t | T_i > t_{(j)}) \times Pr(T_i > t_{(j)} | T_i > t_{(j-1)}) \times \dotsc \times Pr(T_i > t_{(2)} | T_i > t_{(1)}) \times Pr(T_i > t_{(1)})\]
The Kaplan-Meier estimator \(\hat{S(t)}\) can be understood as a “plug-in” estimator for each of these probabilities.
\[\hat{S}(t) = \prod_{j: t_{(j)} \le t} \bigg(1 - \frac{d_j}{r_j} \bigg)\]
\(d_j\) denotes the number of units that experience an event at time \(t_{(j)}\)
\(r_j\) is the number of units that are still in the risk set up to time \(j\)
Intuition: Consider one of the terms in the product. Using the definition of conditional probability:
\[Pr(T_i > t_{(j)} | T_i > t_{(j-1)}) = 1 - Pr(T_i < t_{(j)}|T_i > t_{j-1}) = 1 - \frac{Pr(T_i \le t_{(j)}, T_i > t_{(j-1)})}{Pr(T_i > t_{(j-1)})}\]
In the numerator, our “plug-in” estimator is just the share of units that have events occurring at \(t_{(j)}\).
In the denominator we have the share of units that we know for sure are still “active” in the interval after \(t_{(j-1)}\)
Hence our plug-in estimator:
\[\widehat{Pr(T_i > t_{(j)} | T_i > t_{(j-1)})} = 1 - \frac{d_j}{r_j}\]
Taking the product across all of the \(j\) where \(t_{(j)} < t\) yields the Kaplan-Meier estimator.
survival R package on survival times for patients with advanced lung cancer.# A tibble: 228 × 10
inst time status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 3 306 2 74 1 1 90 100 1175 NA
2 3 455 2 68 1 0 90 90 1225 15
3 3 1010 1 56 1 0 90 90 NA 15
4 5 210 2 57 1 1 90 60 1150 11
5 1 883 2 60 1 0 100 90 NA 0
6 12 1022 1 74 1 1 50 80 513 0
7 7 310 2 68 2 2 70 60 384 10
8 11 361 2 71 2 2 60 80 538 1
9 1 218 2 53 1 1 70 80 825 16
10 7 166 2 61 1 2 70 70 271 34
# ℹ 218 more rows
survival package, we need to define a “survival” outcome in terms of the event time and the censoring indicatorWhen we want to model the survival function using covariates, we run into a clear constraint using purely non-parametric methods – with continuous covariates, we may only have one observation that has a unique covariate value
We may want to assume a model for the event time. We can write that density in terms of the hazard and the survival function
\[f(t) = h(t)S(t)\]
Note that by the definition of the cumulative hazard \(H(t) = - \log(S(t))\) and \(S(t) = \exp(-H(t))\), so
\[f(t) = h(t)\exp(-H(t))\]
Depending on the assumptions we make about the nature of the hazard, we can obtain different distributions for \(f(t)\).
This yields the exponential distribution
\[f(t) = \lambda \exp(-\lambda t)\]
The mean of \(T_i \sim \text{Exponential}(\lambda)\) is \(E[T_i] = \frac{1}{\lambda}\). We’ll often reparameterize the mean as \(\theta\), yielding a density of
\[f(t) = \frac{1}{\theta} \exp\bigg(-\frac{1}{\theta} t\bigg)\]
\(\theta\) is strictly greater than \(0\), so we’ll use a log-link to incorporate the covariates:
\[\log(E[Y_i | X_i]) = \log(\theta_i) = X_i^{\prime}\beta\]
Alternatively, we can write
\[E[Y_i | X_i] = \exp(X_i^{\prime}\beta)\]
Note that the constant hazard assumption is a strong one – the exponential distribution is “memoryless” in that knowing that a unit has survived up until time \(t\) tells you nothing about its instantenous probability of failure.
\[h(t) = \frac{1}{\theta_i} = \frac{1}{\exp(X_i^{\prime}\beta)}\]
Increases in the linear predictor reduce the hazard.
This also lets us write down the survival function
\[S(t) = \exp\bigg(- \frac{1}{\exp(X_i^{\prime}\beta)}t \bigg)\]
\[h_i(t) = h_0(t)\exp(X_i^{\prime}\beta)\]
\(h_0(t)\) is the unknown baseline hazard function.
Note that while the baseline hazard is not explicitly identified, the ratio of the hazards of two observations \(i\) and \(j\) at time \(t\) does not depend on the baseline
\[\frac{h_i(t)}{h_j(t)} = \frac{\exp(X_i^{\prime}\beta)}{\exp(X_j^{\prime}\beta)}\]
The model is semi-parametric in that some components are left entirely unspecified…
The model is estimated by maximizing a partial likelihood
The individual partial likelihood is
\[L_i(\beta) = \frac{\exp(X_i^{\prime}\beta)}{\sum_{k; Y_k \ge Y_i} \exp(X_k^{\prime}\beta)}\]
Intuitively: The denominator contains the hazards of all observations in the risk set at the event time \(Y_i\)
Then the full likelihood is just the product over all the individual partial likelihoods
\[L(\beta) = \prod_{i: C_i = 0} \frac{\exp(X_i^{\prime}\beta)}{\sum_{k; Y_k \ge Y_i} \exp(X_k^{\prime}\beta)}\]
Look again at the individual partial likelihood – it has exactly the form of the conditional logit from earlier today
\[L_i(\beta) = \frac{\exp(X_i^{\prime}\beta)}{\sum_{k; Y_k \ge Y_i} \exp(X_k^{\prime}\beta)}\]
At each event time we are asking: given that one unit in the risk set failed, which one was it?
This isn’t an analogy – it’s the same likelihood. survival::clogit() rewrites its call and hands it to coxph().
Call:
coxph(formula = Surv(time, status) ~ I(sex == 2), data = lung)
coef exp(coef) se(coef) z p
I(sex == 2)TRUE -0.5 0.6 0.2 -3 0.001
Likelihood ratio test=11 on 1 df, p=0.001
n= 228, number of events= 165
PS 818 - University of Wisconsin-Madison