You’re modeling the number of purchases per user on an e-commerce app. Why is ordinary least squares (OLS) the wrong tool, how do Poisson and negative-binomial regression work, and what is a link function?

The Problem: Purchases per user pile up at zero and stretch into a long right tail, and users in the same table have been observed for very different lengths of time. The model has to produce a sensible expected count for every one of them.
Answer
Purchase counts are non-negative integers with a pile of zeros, a long right tail, and a spread that grows with the mean, and OLS ignores all three facts. It can predict negative purchases for light users, and its constant-variance assumption lets a few heavy buyers dominate the fit while corrupting every standard error. A generalized linear model (GLM) replaces the Gaussian with an exponential-family distribution, keeps a linear predictor , and connects the mean to that predictor through a link function
. Poisson regression uses the log link, so
stays positive and features act multiplicatively, but it assumes the variance equals the mean. Purchase data usually breaks that through overdispersion, so negative binomial regression adds a dispersion parameter
with
. Both are fit by maximum likelihood and compared by deviance rather than
.
(1) Why OLS Fails: Gaussian errors put probability on negative and fractional purchases, and constant variance is false when variance scales with the mean. Regressing does not rescue it, because the back-transformed prediction is biased downward and the “+1” is arbitrary.
(2) Three GLM Components: A random component (Poisson or negative binomial for counts), a systematic component , and a link
that maps the positive mean onto the whole real line.
(3) Log Link and Rate Ratios: The log is the canonical link for the Poisson, so is a rate ratio. A coefficient of 0.405 means 1.5 times as many purchases, holding the other features fixed.
(4) Equidispersion Is the Weak Point: Poisson forces . With a Pearson dispersion of 4, Poisson standard errors are too small by a factor of 2, even though the coefficients themselves stay consistent.
(5) Negative Binomial: Mixing a gamma-distributed per-user rate into a Poisson gives . This absorbs unobserved heterogeneity between users and produces more zeros and a heavier tail at the same mean.
(6) Exposure Offset: Users observed for different windows enter through with a coefficient fixed at 1, so the model learns a purchase rate per day instead of a raw total.
(7) Zeros and Deviance: Zero-inflated or hurdle models handle a separate “never buys” process. Deviance, AIC, and predicted versus observed zero shares decide among Poisson, NB, and their zero-modified versions.

Figure 1: A count GLM as three components plus a diagnostic loop. Features and the exposure offset form the linear predictor, the log link maps it to a positive mean, and the fitted Pearson dispersion and zero counts decide whether the Poisson must be swapped for a negative binomial or a zero-modified model.
Mathematical Formulation:
Where:
is the exponential-family density of the response
, with natural parameter
, dispersion
, cumulant function
, and normalizer
. For the Poisson,
,
, and
.
is the mean and
the variance function. Because
for the Poisson, its variance equals its mean, and its canonical link
is the log.
is the expected purchase count of user
,
its feature vector,
the coefficients, and
the exposure in days;
is an offset whose coefficient is fixed at 1 rather than estimated.
is the Poisson probability of exactly
purchases, which puts zero mass on negative or fractional values.
is the negative binomial dispersion parameter; as
the NB collapses back to the Poisson.
is the Poisson deviance, twice the log-likelihood gap to a saturated model, with
the fitted means over
users and
taken as 0 when
. For a Gaussian GLM it reduces to the residual sum of squares.
Worked Example:
Suppose the fitted model is with
in days. The intercept gives a baseline rate of
purchases per day, so a non-subscriber observed for 30 days has
. Subscribing multiplies the rate by
, giving
over 30 days and
for a subscriber observed only 10 days. For the non-subscriber, Poisson predicts
. An NB with
and the same mean predicts
and a variance of
. Same mean, very different shape: if half of your 30-day users never buy, the Poisson is rejected before any formal test.
| Property | Poisson GLM | Negative Binomial GLM | OLS |
|---|---|---|---|
| Support | 0, 1, 2, … | 0, 1, 2, … | All real numbers, negatives included |
| Mean model | log mean = linear score (multiplicative effects) | Same log link, same rate-ratio reading | mean = linear score (additive effects) |
| Variance | Equal to the mean | mean + alpha x mean squared | Constant for every user |
| Typical failure on purchases | Overdispersion makes p-values far too optimistic | Misses a separate never-buyer process if one exists | Negative predictions, heavy buyers dominate the fit |
| Fit and check | MLE via IRLS, deviance, Pearson dispersion | MLE including alpha, LR test against Poisson, AIC | Least squares, R squared |
Leave a Reply