mindstair

Home / Courses / Statistics 2 / Unit 7

Statistics 2 Unit 7: Logistic Regression Basics

When the response is yes/no, logistic regression models the probability of 'yes' through the log-odds. You will move between probability, odds and log-odds, interpret coefficients as odds ratios, and test whether predictors matter.

Covers: Binary responses and why linear models fail, Probability, odds and log-odds, The logistic model and S-curve, Interpreting coefficients as odds ratios, Predicted probabilities, Wald tests, CIs and likelihood-ratio tests, Classification and multiple predictors

Study guide

Many outcomes are binary: a patient recovers or not, a customer buys or not, a loan defaults or not. Coding the response as 0 or 1 and fitting a straight line causes problems: predictions can fall below 0 or above 1, and the errors are neither normal nor constant in spread. Logistic regression solves this by modeling a transformed probability. Instead of p, it models the log-odds, log(p/(1 − p)), as a linear function of the predictors. Because the log-odds can be any real number, the line never produces impossible probabilities, and converting back gives an S-shaped curve bounded by 0 and 1.

Fluency with three scales is essential. Probability p runs from 0 to 1. Odds = p/(1 − p) run from 0 to infinity, with odds of 1 meaning a 50-50 chance; p = 0.8 gives odds 4. Log-odds run over all real numbers, with 0 meaning p = 0.5. To convert back, odds = e^(log-odds) and p = odds/(1 + odds). In the model log(p/(1 − p)) = β₀ + β₁x, the probability is p = e^(β₀ + β₁x)/(1 + e^(β₀ + β₁x)). The curve is steepest at p = 0.5, where x = −β₀/β₁, and its slope there is β₁/4.

Coefficients act on the log-odds scale. A one-unit increase in x adds β₁ to the log-odds, which multiplies the odds by e^(β₁), the odds ratio. A coefficient of 0.5 means each unit multiplies the odds by about 1.65, a 65% increase in odds. For a c-unit change, the odds ratio is e^(cβ₁). For an indicator variable, e^b compares the odds in the coded group with the baseline group. The change in probability is not constant: it is about β₁p(1 − p), large near p = 0.5 and small near 0 or 1. For rare outcomes, odds ratios approximate risk ratios; for common outcomes they exaggerate them.

Logistic models are fit by maximum likelihood, not least squares. Software reports each coefficient with a standard error and a Wald statistic z = b/SE, compared with the standard normal. A 95% CI for β is b ± 1.96·SE; exponentiate the endpoints to get a CI for the odds ratio, and check whether it contains 1. To test several predictors at once, compare nested models with a likelihood-ratio test: the drop in deviance follows approximately a χ² distribution with df equal to the number of added parameters. As in multiple linear regression, each coefficient is adjusted for the other predictors in the model.

Logistic models are often used to classify: predict 'yes' when p̂ exceeds a threshold such as 0.5. Sensitivity is the fraction of actual positives correctly flagged; specificity is the fraction of actual negatives correctly cleared. Raising the threshold trades sensitivity for specificity. Overall accuracy can be misleading when one outcome is rare, since always predicting the common outcome scores well. Watch for perfect separation, when a predictor splits the outcomes completely; maximum likelihood then fails to give finite estimates. And remember that observational data support associations, not causal claims, whatever the model.

Key ideas

Formulas and rules

Odds = p/(1 − p); p = odds/(1 + odds)
log(p/(1 − p)) = β₀ + β₁x₁ + … + β_kx_k
p = e^(η)/(1 + e^(η)), where η = β₀ + β₁x
Odds ratio per unit = e^(β₁); per c units = e^(cβ₁)
Wald z = b/SE; CI for OR: e^(b ± 1.96·SE)
LR test: χ² = deviance(reduced) − deviance(full), df = parameters added

Common mistakes

Before the test, make sure you can

Words to know

Binary response
A variable with two outcomes, usually coded 1 (success) and 0 (failure).
Odds
p/(1 − p), the ratio of the chance an event happens to the chance it does not.
Log-odds (logit)
The natural log of the odds; can take any real value.
Logistic regression
A model in which the log-odds of a binary outcome are linear in the predictors.
Logistic curve
The S-shaped curve of p against x, bounded by 0 and 1.
Odds ratio
The factor by which odds change; e^(β₁) per unit of x.
Maximum likelihood
Estimation that picks parameters making the observed data most probable.
Wald test
A z test of a single coefficient: z = b/SE.
Deviance
A measure of lack of fit for a likelihood-based model; smaller is better.
Likelihood-ratio test
Compares nested models using the drop in deviance, referred to a χ² distribution.
Sensitivity
The proportion of actual positives that a classifier correctly identifies.
Specificity
The proportion of actual negatives that a classifier correctly identifies.
Perfect separation
When a predictor completely separates the outcomes, so estimates do not converge.
Relative risk
The ratio of two probabilities; approximated by the odds ratio when events are rare.

Sample practice questions

30 more questions like these, from level 1 to 5, are in the practice set.

Question 1 (level 1)

Logistic regression is designed for a response variable that is:

  1. Quantitative and normally distributed
  2. A count of events with no fixed upper limit
  3. Binary, such as yes/no or success/failure
  4. Categorical with ordered numeric scores
Show the answer and steps

Answer: C) Binary, such as yes/no or success/failure

  1. Logistic regression models the probability of one of two outcomes.
  2. It links that probability to predictors through the log-odds.
  3. Normal quantitative responses use linear regression instead.
Question 2 (level 1)

If the probability of an event is p, its odds are:

  1. (1 − p)/p
  2. p/(1 + p)
  3. 1 − p
  4. p/(1 − p)
Show the answer and steps

Answer: D) p/(1 − p)

  1. Odds compare the chance an event happens with the chance it does not.
  2. Odds = p/(1 − p).
  3. For p = 0.5 the odds are 1, often stated as 'even odds'.
Question 3 (level 3)

A logistic regression coefficient is 0.42 with SE 0.15. What is the two-sided p-value for H₀: β = 0?

  1. 0.0026
  2. 0.0280
  3. 0.0051
  4. 0.0500
Show the answer and steps

Answer: C) 0.0051

  1. z = 0.42/0.15 = 2.80.
  2. Two-sided p = 2 × P(Z > 2.80) = 2 × 0.00256.
  3. = 0.0051; 0.0026 is the one-tail area.