When your counts are too variable for Poisson

Today let's understand overdispersion: what happens when a Poisson model's central assumption, that a count's variance equals its mean, turns out to be false, and the three repairs that put its reported intervals back on solid ground.

Here is the example for the whole lesson. Twenty five urgent care clinics each report one number a week: how many patients walked in. Twelve of them run standard hours, open 9 to 5. The other thirteen run extended hours, open until midnight. Tracked for 4 weeks each, that gives 100 weekly counts in total.

Standard-hours clinics average 8.44 visits a week. Extended-hours clinics average 12.96, close to half again as many, which fits with being open more hours.

Here is a sample of those weekly counts, five from each kind of clinic, nudged apart a little so the dots do not stack on top of each other.

Standard-hours clinics, on the left, stay close together, from 6 to 11 visits. Extended-hours clinics, on the right, spread far wider, from 4 up to 26.

Checking whether this data's variance really equals its mean

A Poisson model carries one defining assumption: for a true Poisson count, the variance equals the mean, exactly. If a clinic's weekly visits really followed a Poisson distribution, that clinic group's week-to-week variance should land close to its own average.

Build the 100 weekly counts first, then check that assumption on each group.

RInteractive R
# Build the 25 clinics' weekly visit counts: 12 standard-hours, 13 extended-hours, 4 weeks each set.seed(34) clinic_group <- rep(c(0, 1), c(12, 13)) clinic_effect <- rnorm(25, 0, 0.35) clinic_rate <- exp(log(8) + log(1.5) * clinic_group + clinic_effect) visits <- rpois(100, rep(clinic_rate, each = 4)) extended <- rep(clinic_group, each = 4) clinic_id <- rep(1:25, each = 4) # Compare each group's mean weekly count to its own variance tapply(visits, extended, mean) tapply(visits, extended, var) #> 0 1 #> 8.43750 12.96154 #> 0 1 #> 12.54920 61.92006

  

Each of the 25 clinics also got its own small random bump or dip in its typical rate, since real clinics are not perfectly identical even within the same hours group.

Standard-hours clinics (extended equal to 0) average 8.44 visits with a variance of 12.55. Divide one by the other and you get 1.49, close enough to the Poisson assumption of 1.

Extended-hours clinics average 12.96 visits, but their variance is 61.92, nearly five times their own mean. Divide and you get 4.78, nowhere near 1. This group's counts spread out far more than a Poisson distribution allows. That is called overdispersion: the variance running past what the chosen distribution permits.

That informal check, variance divided by mean, is worth running on any count data before fitting anything. But glm() carries a formal version of the same check, computed from the fitted model rather than the raw groups.

RInteractive R
# Fit the Poisson model and check how overdispersed the fit really is fit <- glm(visits ~ extended, family = poisson) round(summary(fit)$coef, 4) #> Estimate Std. Error z value Pr(>|z|) #> (Intercept) 2.1327 0.0497 42.9195 0 #> extended 0.4293 0.0629 6.8282 0 deviance_ratio <- fit$deviance / fit$df.residual pearson_ratio <- sum(residuals(fit, type = "pearson")^2) / fit$df.residual round(c(deviance_ratio = deviance_ratio, pearson_ratio = pearson_ratio), 2) #> deviance_ratio pearson_ratio #> 2.93 3.20

  

Both numbers measure the same thing in slightly different ways: how much bigger the fitted model's actual spread is than a Poisson fit assumes. The Pearson version is

$$\hat\phi = \frac{1}{n-p}\sum_i \frac{(y_i-\hat\mu_i)^2}{\hat\mu_i}$$

the sum of each row's squared miss divided by its own fitted rate, averaged over the 98 degrees of freedom left after estimating the intercept and the extended coefficient. A well-behaved Poisson fit keeps this ratio near 1. Here it comes out to 2.93 by one measure and 3.20 by the other, both saying the fit is roughly three times as variable as a Poisson model expects.

Exponentiate the extended coefficient and the fit still looks perfectly usable.

RInteractive R
# Read the coefficient as a rate ratio, with its reported 95% interval beta_extended <- coef(fit)[["extended"]] naive_se <- summary(fit)$coefficients["extended", "Std. Error"] rate_ratio <- exp(beta_extended) naive_ci <- exp(beta_extended + c(-1, 1) * 1.96 * naive_se) round(rate_ratio, 2) #> [1] 1.54 round(naive_se, 4) #> [1] 0.0629 round(naive_ci, 2) #> [1] 1.36 1.74

  

Extended-hours clinics see 1.54 times the visits of standard-hours ones, and the reported 95% interval, 1.36 to 1.74, looks narrow and confident. But that confidence was computed by a model that had just failed its own dispersion check by a factor of three. Call this one the naive standard error, naive because it assumes variance equals mean, the very assumption the data just broke.