PS 818 - Data Analysis with Statistical Models
September 28, 2026
\[ \DeclareMathOperator*{\argmin}{arg\,min} \DeclareMathOperator*{\argmax}{arg\,max} \]
Generalized linear models
\[g(\mathbb{E}[Y_i|X_i]) = X_i^{\prime}\beta\]
Binary outcome models
Inference on transformations:
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.
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_{k^\prime=1}^K \exp(X_i^{\prime}\beta_{k^\prime})}\]
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_{k^\prime=2}^K \exp(X_i^{\prime}\beta_{k^\prime})}\]
The i.i.d. error assumption implies independence of irrelevant alternatives (IIA).
-99 is a 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
Same latent utility setup as the multinomial logit, but now the covariates are attribute-specific but their types are shared across alternatives
\(X_{ik}\) varies across categories, but all categories share a common \(\beta\) vector
\[Y_{ik}^* = X_{ik}^{\prime}\beta + \epsilon_{ik}\]
With the same i.i.d. Type I extreme value errors, we get the same “softmax” expression for the choice probability.
\[\Pr(Y_i = k \,|\, X_{i1}, \dotsc, X_{iK}) = \frac{\exp(X_{ik}^{\prime}\beta)}{\sum_{k^\prime=1}^K \exp(X_{ik^\prime}^{\prime}\beta)}\]
We still have the independence of irrelevant alternatives assumption: the relative odds of two choices only depend on those two choices’ attributes.
\[\frac{\Pr(Y_i = j)}{\Pr(Y_i = k)} = \exp\big((X_{ij} - X_{ik})^{\prime}\beta\big)\]
Extensions involve imposing additional hierarchical structure:
# A tibble: 4 × 7
rid task profile chosen governance income hours
<int> <dbl> <int> <int> <fct> <fct> <fct>
1 1 1 1 1 Workers are shareholders $200k 80
2 1 1 2 0 Private, one owner $260k 80
3 1 2 1 1 Private, one owner $90k 40
4 1 2 2 0 Workers on the board $200k 40
dfidx() tells mlogit which rows form a choice situation (task_id, nested in respondent rid) and which alternative each row is (profile)mlogit formula
| 0 drops the alternative-specific constant (a preference for whichever profile is listed second)[1] 73
estfun() has one row per task (one likelihood contribution each), so the cluster vector needs one entry per task| level | part_worth | se | odds_ratio | pr_vs_baseline |
|---|---|---|---|---|
| Private, one owner | 0.061 | 0.088 | 1.06 | 0.515 |
| Public, shareholders | 0.283 | 0.088 | 1.33 | 0.570 |
| Workers are shareholders | 0.420 | 0.091 | 1.52 | 0.604 |
| Workers on the board | 0.359 | 0.090 | 1.43 | 0.589 |
| Workers elect managers | 0.192 | 0.089 | 1.21 | 0.548 |
Conditional logit with all 19 attributes; hollow points are baselines. 95% CIs clustered by respondent. Data from Mazumder and Yan (2024).
Conditional logit with all 19 attributes; hollow points are baselines. 95% CIs clustered by respondent. Data from Mazumder and Yan (2024).
Red: salary dummies with 95% CIs. Blue: log-salary fit with 95% CI, centered on the dummies’ average level. Both clustered by respondent.
Conditional logit with salary as log(salary); respondent-clustered covariance. Data from Mazumder and Yan (2024). CIs: delta method on the log-odds scale.
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)\) is 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 just before \(t_{(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 \le 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 overall “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)} \le 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
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[T_i | X_i]) = \log(\theta_i) = X_i^{\prime}\beta\]
Alternatively, we can write
\[E[T_i | X_i] = \exp(X_i^{\prime}\beta)\]
Note that the constant hazard assumption is strong
\[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)\]
The fit seems to be off.
The Weibull adds a shape parameter \(k\) that lets the hazard change over time
\[h(t) = \frac{k}{\lambda}\left(\frac{t}{\lambda}\right)^{k-1}\qquad S(t) = \exp\left(-\left(\frac{t}{\lambda}\right)^{k}\right)\]
\[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)}\]
The individual partial likelihood should look familiar - it has exactly the form of the conditional logit
\[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?
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