Logistic
Regression
Master the fundamentals of binary classification: from the sigmoid function and maximum likelihood to odds ratios and statistical inference.
Why Logistic Regression?
When the response variable \(Y\) is binary (0 or 1), ordinary least squares breaks down: predicted values can fall outside \([0,1]\) and residuals violate normality. We need a model that maps any real-valued linear predictor to a valid probability.
The Sigmoid Function
The logistic (sigmoid) function transforms any real number into a probability:
The Logistic Model
We set \(z = \beta_0 + \beta_1 x_1 + \cdots + \beta_p x_p\) and apply the sigmoid. The full model is:
Equivalently, the log-odds (logit) is a linear function of the predictors:
Odds and Log-Odds
Maximum Likelihood Estimation
We cannot use least squares. Instead, we choose \(\boldsymbol{\beta}\) to maximize the likelihood of the observed data:
Taking the log gives the log-likelihood:
This is maximized numerically via iteratively reweighted least squares (IRLS) or gradient-based methods: there is no closed-form solution.
The Likelihood Surface
Linear vs Logistic
| Linear Regression | Logistic Regression | |
|---|---|---|
| Response \(Y\) | Continuous | Binary (0 / 1) |
| Link function | Identity: \(E[Y] = \mathbf{x}^T\boldsymbol{\beta}\) | Logit: \(\ln\!\frac{p}{1-p} = \mathbf{x}^T\boldsymbol{\beta}\) |
| Estimation | OLS (closed-form) | MLE (iterative) |
| Coefficient meaning | Change in \(E[Y]\) | Change in log-odds |
| Predictions | \((-\infty, +\infty)\) | \((0, 1)\) |
| Error distribution | Normal | Bernoulli |
Interpreting Coefficients
How to Apply Logistic Regression
Inference: Wald and LRT
Example 1: Simple Model
A study models the probability of passing an exam based on hours studied. The fitted model is:
Question: What is the predicted probability of passing for a student who studies 4 hours?
Example 2: Multiple Predictors
A hospital predicts 30-day readmission (\(Y = 1\)) using age and comorbidity score:
| Predictor | \(\hat{\beta}\) | SE | \(e^{\hat{\beta}}\) | p-value |
|---|---|---|---|---|
| Intercept | -3.20 | 0.58 | 0.041 | < 0.001 |
| Age | 0.04 | 0.01 | 1.04 | < 0.001 |
| Comorbidity | 0.85 | 0.22 | 2.34 | < 0.001 |
Example 3: Decision Boundary
With a threshold of \(p = 0.5\), the decision boundary occurs where the log-odds equal zero:
Common Mistakes
Question 1 of 5
In logistic regression, the logit function maps:
Question 2 of 5
If \(\hat{\beta}_1 = 0.693\), what is the odds ratio for a one-unit increase in \(x_1\)?
Question 3 of 5
The log-likelihood for logistic regression is globally concave. What does this guarantee?
Question 4 of 5
A fitted model gives \(\text{logit}(\hat{p}) = -2 + 0.5x\). What is the predicted probability when \(x = 4\)?
Question 5 of 5
Which test is generally preferred for comparing nested logistic regression models?