When the response is not continuous
Will an order fill (yes/no)? How many trades arrive in a minute (0, 1, 2, ...)? Fitting OLS to these predicts probabilities below 0 or above 1 and negative counts, and the error variance depends on the mean (a Bernoulli has variance ), so OLS standard errors are wrong too. A generalised linear model keeps the convenient linear predictor but connects it to the mean through a link function and uses a likelihood suited to the response:
Objective: know the three standard GLMs, interpret logistic and Poisson coefficients fluently, and understand how they are fitted.
The exponential-family idea
A GLM's response comes from an exponential family:
The variance is a function of the mean, which is what makes each family distinct. The canonical link sets ; it gives the cleanest score equations and a concave log-likelihood.
| Response | Family | (canonical link) | Mean | Variance |
|---|---|---|---|---|
| continuous | Normal | (identity) | ||
| binary | Bernoulli | (logit) | ||
| count | Poisson | (log) |
OLS is the Normal GLM with identity link. Non-canonical links exist (probit, , for binary data; log link for positive continuous data with a Gamma family), but the canonical ones are the default.
Logistic regression
Interpretation. is the change in log-odds per unit of , holding the others fixed; is the odds ratio, the factor by which the odds are multiplied. The effect on the probability itself is not constant:
with the maximum at . The rule is a quick upper bound on a coefficient's probability effect. Odds ratios approximate risk ratios only when is small.
Likelihood. For independent with :
where . The Hessian is negative semi-definite, so is concave and any stationary point is the global maximum. Minus is the log loss (binary cross-entropy) used in machine learning. The score equations mirror OLS's ; with an intercept, the fitted probabilities average to the observed frequency.
Separation. If some combination of regressors perfectly separates the 0s from the 1s, the likelihood keeps rising as and no finite MLE exists: Newton's iterations march off, and software reports huge coefficients and standard errors. Fix with a penalty (ridge-type) or by rethinking the regressor.
Worked example
reading a logistic fit
A model for whether a passive order fills within a minute is , where is order-book imbalance in standardised units. Find the fill probability at and , the odds ratio per unit of , and the marginal effect of on at .
Show solutionHide solution
At : , so . At : , so .
Odds ratio: . Each unit of imbalance multiplies the odds of filling by 1.65. Check: odds at are , at they are .
Marginal effect at : , i.e. about 10 percentage points per unit. The bound gives , attained at where . Saying "a unit of imbalance raises fill probability by 0.5" would be wrong on two counts: 0.5 is on the log-odds scale, and the probability effect depends on where you start.
Fitting: Newton's method is IRLS
The Newton step for maximising is . Rearranged,
which is a weighted least-squares regression of a "working response" on with weights . Because and change every iteration, the algorithm is called iteratively reweighted least squares. Intuition: linearise the link around the current fit, then run WLS where each observation is weighted by the inverse of its variance on that linearised scale. Observations with near 0 or 1 carry little weight; points near are the informative ones.
Newton converges quadratically near the optimum and typically needs 5–10 iterations. At the optimum, is the inverse Fisher information: the estimated covariance of , giving the standard errors software reports. For very large data, the same gradient is used in (stochastic) gradient descent instead, which is the next lesson.
Worked example
Newton iterations by hand and in code
(a) An intercept-only logistic model is fitted to 10 observations with 8 ones. Run Newton's method from .
(b) Fit to with .
Show solutionHide solution
(a) The gradient is and the information is . At , : the step is . At , : gradient , information , step , so . One more step gives . The answer is ; the errors show quadratic convergence.
(b) The same Newton step with a information matrix:
import math
def logistic_newton(x, y, steps=8):
a, b = 0.0, 0.0 # intercept, slope
for k in range(steps):
p = [1 / (1 + math.exp(-(a + b * xi))) for xi in x]
w = [pi * (1 - pi) for pi in p]
# gradient X'(y - p) and information X'WX for columns (1, x)
g0 = sum(yi - pi for yi, pi in zip(y, p))
g1 = sum(xi * (yi - pi) for xi, yi, pi in zip(x, y, p))
h00 = sum(w)
h01 = sum(wi * xi for wi, xi in zip(w, x))
h11 = sum(wi * xi * xi for wi, xi in zip(w, x))
det = h00 * h11 - h01 * h01
a += (h11 * g0 - h01 * g1) / det # solve the 2x2 system
b += (h00 * g1 - h01 * g0) / det
print(k + 1, f"{a:.6f}", f"{b:.6f}")
return a, b
x = [0, 1, 2, 3, 4, 5, 6, 7]
y = [0, 0, 1, 0, 1, 0, 1, 1]
logistic_newton(x, y, steps=5)
1 -1.666667 0.476190
2 -2.038937 0.582554
3 -2.078860 0.593960
4 -2.079295 0.594084
5 -2.079295 0.594084
So (odds ratio per unit of ) and at , the midpoint, as the symmetric data suggest. statsmodels gives the same estimates with a slope standard error of 0.432, so : with 8 points the slope is not significant.
Poisson regression for counts
is a rate ratio: each unit of multiplies the expected count by (a coefficient of 0.2 means , since ; means , about ). The score is again and the weights in IRLS are .
Exposure. When counts are over windows of different length (trades per interval when intervals differ, defaults per number of loans), model the rate: , where is an offset, a regressor with its coefficient fixed at 1.
Overdispersion. Poisson forces variance = mean. Real counts (trade arrivals cluster) usually have variance well above the mean. The coefficient estimates remain consistent if the mean is right, but the standard errors are too small. Use quasi-Poisson (scale the variance by an estimated ), robust standard errors, or a negative binomial model. Many zeros beyond what Poisson predicts suggest a zero-inflated model.
Assumptions and failure modes
- The link is a modelling choice: a logistic fit assumes log-odds linear in . Check with binned calibration plots (predicted vs observed frequency by decile).
- Observations are assumed independent given ; clustered or time-dependent data need robust or clustered standard errors, exactly as in OLS.
- Coefficient interpretations are conditional on the other regressors, and omitted-variable problems carry over (in logistic regression, omitting even an uncorrelated regressor shrinks the others towards zero).
- Class imbalance (rare events) does not bias the slopes much, but the intercept reflects the sample's base rate; if you subsample the majority class, adjust the intercept before reading probabilities.
Interview angle
Typical questions: "interpret a logistic coefficient of 0.7" (log-odds up 0.7; odds ; probability effect at most per unit, largest near ), "why not OLS on a binary outcome", "what happens with perfect separation", and "derive the gradient of the log loss" (, using ).
Knowledge check
In a logistic regression, a regressor has coefficient 0.7. What does a one-unit increase in that regressor do, holding the others fixed?
Knowledge check
A logistic slope is . What is the largest possible change in the predicted probability per unit change in that regressor (as a derivative)?
Knowledge check
Fitting a logistic regression, Newton's method never settles: the slope estimate keeps growing each iteration and its standard error explodes. What is the most likely cause?
Knowledge check
You fit a Poisson regression to trade counts per minute and find the residual variance is about four times the fitted mean. What is the main consequence?
Key takeaways
- A GLM is with an exponential-family likelihood; the canonical links are identity (Normal), logit (Bernoulli) and log (Poisson).
- Logistic coefficients are log-odds; is an odds ratio; the probability effect is .
- Poisson coefficients are log rate ratios; use an offset for exposure and fix standard errors for overdispersion.
- The log-likelihood has gradient and, for canonical links, Hessian : concave, solved by Newton = IRLS in a handful of steps. Perfect separation means no finite MLE.
Finished reading?
Answer the 4 knowledge checks to complete this lesson (0 done).