01 / 20

Logistic
Regression

Master the fundamentals of binary classification: from the sigmoid function and maximum likelihood to odds ratios and statistical inference.

Statistics

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.

Binary Outcomes
Pass/fail, disease/healthy, click/no-click: outcomes with exactly two categories.
Probabilities
We model \(P(Y=1 \mid \mathbf{x})\), ensuring predictions stay between 0 and 1.

The Sigmoid Function

The logistic (sigmoid) function transforms any real number into a probability:

1 0.5 0 0 -4 4 (0, 0.5)
\(\sigma(z)\)
z

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

Odds
The ratio \(\frac{p}{1-p}\). If \(p = 0.8\), the odds are \(4{:}1\) in favor of the event.
Log-Odds (Logit)
\(\ln\!\left(\frac{p}{1-p}\right)\) maps \((0,1) \to (-\infty,+\infty)\), making it suitable as a linear predictor.
Odds Ratio
\(e^{\beta_j}\) is the multiplicative change in odds for a one-unit increase in \(x_j\), holding others constant.

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

MLE
\(\beta\)
\(\ell(\beta)\)
\(\hat{\beta}_{MLE}\)

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

1
Log-odds scale: \(\beta_j\) is the change in \(\ln\!\frac{p}{1-p}\) per unit increase in \(x_j\).
2
Odds ratio: Exponentiate to get \(e^{\beta_j}\), the multiplicative factor on the odds.
3
Probability scale: The effect is nonlinear and depends on the current value of \(p\). The maximum marginal effect occurs at \(p = 0.5\).
4
Sign: Positive \(\beta_j\) increases probability of \(Y = 1\); negative decreases it.

How to Apply Logistic Regression

1
Identify the binary response and select candidate predictors \(x_1, \ldots, x_p\).
2
Fit via MLE: Use software to maximize \(\ell(\boldsymbol{\beta})\). Check convergence diagnostics.
3
Assess significance: Use Wald tests \(z = \hat{\beta}_j / \text{SE}(\hat{\beta}_j)\) or the likelihood ratio test.
4
Interpret coefficients as log-odds changes; report odds ratios \(e^{\hat{\beta}_j}\) with confidence intervals.
5
Evaluate model fit: Examine deviance, AIC, Hosmer-Lemeshow test, or ROC/AUC curves.

Inference: Wald and LRT

Wald Test
$$ z = \frac{\hat{\beta}_j}{\text{SE}(\hat{\beta}_j)} $$ Compare to standard normal. Quick but can be unreliable for large \(|\hat{\beta}|\).
Likelihood Ratio Test
$$ G^2 = -2\bigl[\ell(\text{reduced}) - \ell(\text{full})\bigr] $$ Compare to \(\chi^2\) with \(df =\) number of dropped parameters. More reliable.

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?

1
Compute log-odds: \(-4.08 + 1.50(4) =\) 1.92
2
Apply sigmoid: \(p = \frac{1}{1 + e^{-1.92}} = \frac{1}{1 + 0.1466} \approx\) 0.872
3
Interpret odds ratio: \(e^{1.50} \approx 4.48\). Each extra hour multiplies the odds of passing by about \(4.5\).

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:

Hours Studied
\(P(\text{Pass})\)
1.0 0.5 0 0 2 4 6 8 Boundary: 2.72h Pass Fail

Common Mistakes

✕ Interpreting on Probability Scale
Saying "\(\beta = 0.5\) means probability increases by \(0.5\)." Coefficients are on the log-odds scale, not probability.
✕ Using \(R^2\)
OLS \(R^2\) is not meaningful for logistic regression. Use pseudo-\(R^2\), deviance, AIC, or AUC instead.
✕ Ignoring Separation
When a predictor perfectly separates 0s and 1s, the MLE diverges to \(\pm\infty\). Check for quasi-complete separation.

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?