Class 17 · Poisson Regression for Counts and Rates
STAT 517: Advanced Statistical Models · Fall 2026
This interactive companion follows Chapter 12 and the reviewed class17_poisson_regression.R. The student-awards example fits a Poisson regression to a count response; the lung-cancer example models rates with an exposure offset.
Press Run Code on each box in order. Later boxes reuse earlier objects, and you can edit a box and run it again. Both data files are included, and everything except the curve plots uses base R. Questions 12.1–12.2 match the handout; Question 12.1 is the in-class lab, whose group assignments and submission template are posted where the instructor hosts the lab threads.
Goals
- Recognize a count response and state the Poisson mean–variance restriction.
- Specify a Poisson log-linear model and count its parameters.
- Interpret \(e^{\beta_j}\) as an incidence rate ratio and \(100(e^{\beta_j}-1)\%\) as a change in the mean count.
- Predict a mean count and build its confidence interval on the log scale.
- Test the Poisson assumption with the deviance; check linearity and influence.
- Model rates with an offset and interpret rate ratios.
Part 1 · Counts
1. Student-awards data
There are 200 students. The response awards is a count with no fixed ceiling; math is a standardized score and prog the program of study, with Academic as the first level and so the reference.
Why a straight line fails
A least-squares line treats the counts as continuous. On these data it predicts a negative mean number of awards for low math scores and assumes the same spread everywhere, while the counts fan out as the score rises. A Poisson mean stays positive and curves upward. The right-hand panel compares the tally with a single Poisson distribution that gives every student the same mean, 0.63: it produces too few zeros and too few large counts, because students differ in math score and program. Poisson regression gives each student their own mean.
The Poisson distribution
A Poisson random variable with mean \(\lambda\) has probability mass function \(P(X = k) = \lambda^k e^{-\lambda}/k!\) on \(k = 0, 1, 2, \ldots\) and cumulative distribution function \(F(k) = P(X \le k)\), which jumps by \(P(X = k)\) at each whole number. dpois() and ppois() compute them. Change lambda and run the box again: small means pile the probability at 0, and larger means shift right and spread out, because the variance equals the mean.
2. Fit the Poisson regression model
With \(y_i \mid \mathbf{x}_i \sim \text{Poisson}(\lambda_i)\) and the log link,
\[ \log(\lambda_i) = \beta_0 + \beta_1 x_{i1} + \cdots + \beta_p x_{ip}, \qquad \lambda_i = e^{\beta_0 + \beta_1 x_{i1} + \cdots + \beta_p x_{ip}} . \]
A one-unit increase in \(x_j\) multiplies the mean count by \(e^{\beta_j}\), the incidence rate ratio, holding the other covariates fixed; \(100(e^{\beta_j} - 1)\%\) is the percent change. For a factor, “one unit” means moving from the reference level to the named level.
- Specify. From the model statement alone, write the Poisson regression model for
awards ~ math + prog, defining each \(x\). How many parameters does it have, and which group do the two program coefficients compare with? - Interpret. Interpret the incidence rate ratios for
mathand forprogGeneralas a times change and a percent change, with their 95% intervals, naming the quantity that changes, the comparison, and the covariate held fixed. - Predict. Student 1 has math score 40 and is in the general program. Calculate \(\log\widehat\lambda\) and \(\widehat\lambda\) from the coefficients, then build the 95% interval for the mean count on the log scale from the link-scale standard error and exponentiate it. Why the log scale?
Model sentence, for progVocational: after controlling for math score, we expect students in the vocational program to have, on average, 0.49 times as many awards as students in the academic program, a 51.0% lower mean number of awards; we are 95% confident that the mean is between 11.9% and 75.1% lower, and the interval excludes 0 (\(p = 0.0257\)).
3. Does the Poisson distribution fit?
The residual deviance \(D\) on \(n-(p+1)\) degrees of freedom tests \(H_0\): the Poisson distribution fits the data well. A large p-value means no evidence of lack of fit. This is not a test of whether the coefficients are zero. Here \(p\) counts slope coefficients, including factor indicators; the intercept adds one more parameter.
In the deviance formula, use \(0\log(0/\hat\lambda_i)=0\) by continuity. A zero count contributes \(2\hat\lambda_i\) to \(D\); R handles this convention.
Plot the deviance residuals against the fitted values, and look at Cook’s distance.
Pearson residuals divide observed-minus-fitted counts by the fitted Poisson standard deviation. Deviance residuals are signed square roots of individual contributions to the deviance. Residuals should be around zero, especially for larger fitted means. For this graphical linearity check, a plot without a clear pattern beyond natural count bands provides no clear evidence against linearity; it does not establish that the assumption holds. For a zero count, the same convention gives the deviance residual \(d_i=-\sqrt{2\hat\lambda_i}\).
The curved bands of points are the observed counts 0, 1, 2, …; they are a feature of small fitted means, not a linearity problem. Apart from these bands, the plot shows no clear evidence against the linearity assumption. Observations 181, 154, and 54 have the largest Cook’s distances and warrant closer inspection.
4. Predict mean counts for new students
type = "response" returns the predicted mean count. Its confidence interval is built on the log scale (type = "link", se.fit = TRUE) and then exponentiated, so both endpoints are positive.
The fitted mean is 2.606 awards. The 95% confidence interval (1.930, 3.519) estimates the mean number of awards among academic-program students with math score 73.
The nominal 95% plug-in prediction interval [0, 6] concerns the count for one new student with this profile. qpois() uses the 2.5th and 97.5th percentiles of the fitted Poisson distribution. This includes individual Poisson variation but ignores uncertainty in the estimated mean. Because counts are discrete, the fitted probability of 0 through 6 is 98.3%, rather than exactly 95%.
Complete Question 12.1, item 3, by hand first. The box below gives you the link-scale standard error; add a predict() line afterwards to check your mean.
5. Mean counts across math scores
Explore: add + ggplot2::scale_y_log10() to the box. On the log scale the three curves become parallel lines: that is what a common math slope means.
Part 2 · Rates and the offset
6. Lung-cancer rates in four Danish cities
The eba1977 data (from the ISwR package, saved here as a CSV) give lung-cancer cases and the number of sampled residents pop for each of four cities and six age groups. The groups differ in size, so we model the rate of cases per resident:
\[ \log(\lambda_i) = \log(m_i) + \beta_0 + \beta_1 x_{i1} + \cdots + \beta_p x_{ip}, \]
where \(\log(m_i)\) is an offset, a term whose coefficient is fixed at 1. In R this is offset = log(pop); do not forget the log.
After controlling for age group, Horsens (\(p = 0.069\)) and Vejle (\(p = 0.147\)) are not significantly associated with the rate, while every age group is significant after controlling for city. Are the two cities marginally associated with the rate?
The incidence rate ratios compare rates per resident at equal values of the other factor:
Model sentence: after controlling for city, we expect the 55–59 age group to have 3.007 times the lung-cancer rate of the 40–54 group; we are 95% confident that its rate is between 84.3% and 390% higher.
- Write the rate model that
cancer.modfits and explain why the coefficient of \(\log(m_i)\) is fixed at 1 rather than estimated. What would go wrong without the offset? - Interpret the incidence rate ratios for
cityKoldingand forage70-74and their 95% intervals, naming the comparison and the factor held fixed. - Row 24 is Vejle, age 75+, with 619 sampled residents and 7 observed cases. Calculate the fitted mean count from the coefficients and the offset, then its 95% interval from the link-scale standard error. Check against the table in the next box.
- Horsens is not conditionally significant. Is it marginally significant? What do the two answers together say?
7. Fitted mean counts with intervals
Every covariate is categorical, so we predict in-sample for each (city, age) combination. The predictions are mean numbers of cases among the sampled residents, with the offset built in.
For row 1, we are 95% confident that the mean number of cases among the sampled 40–54-year-olds in Fredericia is between 7.399 and 16.221. Use the box below for Question 12.2, item 3, after your calculation by hand.
Optional · Is the offset coefficient really 1?
An offset is a covariate whose coefficient is fixed at 1. Fitting \(\log(\texttt{pop})\) as an ordinary covariate instead estimates that coefficient; compare it with 1.
Optional · Pearson residuals and the dispersion ratio
Both residual types rescale \(y_i - \widehat\lambda_i\) by the Poisson spread; their sums of squares are the Pearson \(X^2\) statistic and the deviance \(D\). Dividing either by \(n-(p+1)\) gives a dispersion ratio that Chapter 13 will use.
Check your understanding
- A count response has no fixed ceiling; a count of successes out of \(n\) trials is binomial instead.
- The Poisson model ties the variance to the mean; the deviance test checks that assumption, not the coefficients.
- \(e^{\beta_j}\) multiplies the mean count; it is a rate ratio, not an odds ratio.
- Build intervals for a mean count on the log scale, then exponentiate.
- An offset enters with coefficient 1 and turns coefficients into rate ratios, while fitted values stay mean counts.