Logistic Regression — Definition, Formula & Example
Logistic regression is a method for predicting the probability of a yes-or-no outcome, such as pass/fail or sick/healthy, from one or more explanatory variables. Its predictions follow an S-shaped curve that always stays between 0 and 1.
For a binary response with , logistic regression assumes the log-odds (logit) of is a linear function of the predictors: . The coefficients are estimated by maximum likelihood, not by least squares.
Key Formula
Where:
- = Predicted probability that the outcome is a yes (Y = 1)
- = The odds of a yes
- = Intercept: the log-odds of a yes when x = 0
- = Slope: the change in log-odds for each 1-unit increase in x
- = Explanatory (predictor) variable
Worked Example
Problem: A professor tracks 200 students. Of the 100 who attended a review session (x = 1), 75 passed the final. Of the 100 who did not attend (x = 0), 25 passed. Fit a logistic regression for the probability of passing. (With a single yes/no predictor, the maximum-likelihood fit reproduces each group's observed log-odds exactly.)
Step 1: Find the observed odds of passing in each group. Odds are passes divided by fails.
Step 2: Set the log-odds equal to the model in each group. At x = 0 the model gives the intercept. At x = 1 it gives the intercept plus the slope, so subtract to get the slope.
Step 3: Check by converting back to a probability for attendees. Since b₀ + b₁ = ln 3, the exponential term is 1/3.
Answer: The fitted model is . It returns the observed pass rates of 0.25 and 0.75, and the odds ratio means attendees had 9 times the odds of passing.
Why It Matters
Logistic regression is the standard tool in biostatistics and epidemiology for estimating how risk factors change the odds of a disease. Banks use it to score loan-default risk, and a single neuron with a sigmoid output in a neural network computes exactly this model.
Common Mistakes
Mistake: Fitting ordinary linear regression to a 0/1 outcome.
Correction: A straight line can predict probabilities below 0 or above 1, and its errors cannot have constant spread. The logit link in logistic regression keeps every prediction strictly between 0 and 1.
