Poisson regression for defect counts, with an example
Poisson regression models a count, such as the number of defects on a roll, the number of failures per month or the number of calls per shift, as a function of one or more predictors. It fits the logarithm of the expected count as a straight line in the predictors, so predicted counts are never negative and each coefficient becomes a rate ratio: the factor by which the defect rate multiplies when the predictor rises by one unit.
When to use it
- The response is a count of events: pinholes, voids, scratches, breakdowns, complaints.
- The amount of opportunity differs from row to row (square meters inspected, hours run, units built), and you want rates, not raw counts.
- You want to know which process settings change the rate, and by how much.
- Counts are small enough that ordinary regression on the raw numbers would misbehave (many zeros, spread growing with the mean).
To monitor a defect rate over time, use a u chart or a c chart. To compare the rate of two groups, a 2-sample Poisson rate test is enough. For pass/fail per unit, use binary logistic regression.
How it works
The count yᵢ is assumed to follow a Poisson distribution with mean μᵢ, linked to the predictors through the log:
ln(μᵢ) = ln(tᵢ) + β₀ + β₁x₁ᵢ + … + βₖxₖᵢThe term ln(tᵢ) is the offset: the log of the exposure (area, time or units) for row i, entered with a fixed coefficient of 1. With it, the model describes the rate per unit of exposure, μᵢ/tᵢ. Without an exposure that varies, leave it out.
The coefficients are estimated by maximum likelihood with iteratively reweighted least squares: at each step, the weights are the current fitted means and the working response is zᵢ = ηᵢ − ln(tᵢ) + (yᵢ − μᵢ)/μᵢ, until the coefficients stop changing. Then:
- Rate ratio = e^(β·Δx): how much the rate multiplies for a change Δx.
- Deviance compares the model with a perfect fit. The drop in deviance from the constant-only model gives a likelihood-ratio test of all predictors.
- Goodness of fit: the deviance and the Pearson chi-square, each compared with chi-square on n − p degrees of freedom. Their ratio to the degrees of freedom should be near 1. A ratio well above 1 signals overdispersion: more spread than the Poisson allows, which makes the standard errors too small.
Example
A coating line inspects rolls of coated film for pinholes. The engineer suspects line speed (m/min) and dryer temperature (°C). Over two weeks, 16 rolls are run at planned combinations, and an automatic camera inspects a stretch of each roll, of varying area:
| Roll | Speed | Dryer (°C) | Area (m²) | Pinholes | Roll | Speed | Dryer (°C) | Area (m²) | Pinholes |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 40 | 110 | 50 | 9 | 9 | 40 | 120 | 60 | 7 |
| 2 | 40 | 130 | 60 | 9 | 10 | 40 | 140 | 50 | 1 |
| 3 | 50 | 120 | 55 | 10 | 11 | 50 | 110 | 45 | 10 |
| 4 | 50 | 140 | 45 | 7 | 12 | 50 | 130 | 55 | 2 |
| 5 | 60 | 110 | 50 | 9 | 13 | 60 | 120 | 50 | 10 |
| 6 | 60 | 130 | 60 | 10 | 14 | 60 | 140 | 60 | 8 |
| 7 | 70 | 120 | 40 | 16 | 15 | 70 | 110 | 45 | 14 |
| 8 | 70 | 140 | 55 | 12 | 16 | 70 | 130 | 50 | 12 |
With ln(area) as the offset, IRLS converges in five iterations:
| Term | Coef | SE Coef | Z | P | Rate ratio per 10 units | 95% CI |
|---|---|---|---|---|---|---|
| Constant | −0.997 | 1.019 | −0.98 | 0.328 | ||
| Speed | 0.03016 | 0.00768 | 3.93 | < 0.001 | 1.352 | 1.163 to 1.572 |
| Dryer temperature | −0.01963 | 0.00751 | −2.61 | 0.009 | 0.822 | 0.709 to 0.952 |
Pinholes per m² = exp(−0.997 + 0.03016·Speed − 0.01963·Dryer)| Test | Chi-square | DF | P |
|---|---|---|---|
| Likelihood ratio (both terms) | 22.10 | 2 | < 0.001 |
| Deviance goodness of fit | 15.01 | 13 | 0.307 |
| Pearson goodness of fit | 13.05 | 13 | 0.444 |
How to read the results
- Rate ratios are the headline. Each extra 10 m/min multiplies the pinhole rate by 1.35 (35% more), and each extra 10 °C in the dryer multiplies it by 0.82 (18% fewer).
- Effects multiply. The model predicts about 7.9 pinholes per 100 m² at 40 m/min and 140 °C, and about 35.2 at 70 m/min and 110 °C, a factor of 4.5 between the best and worst corners tested.
- Check dispersion first. Pearson chi-square divided by its degrees of freedom is 13.05 / 13 = 1.00, so the Poisson spread fits and the standard errors can be trusted. Had it been 2 or 3, the intervals would be too narrow; a quasi-Poisson or negative binomial model would then be safer.
- Each term's own test. Dropping speed from the model raises the deviance by 15.93 (p < 0.001); dropping dryer temperature raises it by 6.89 (p = 0.009). These likelihood-ratio tests agree with the Z tests in the table and are more reliable with small counts.
- Weigh the trade-off. Running faster costs pinholes; a hotter dryer wins some back. A follow-up experiment can find whether 150 °C is safe for the film.
Common mistakes
- Leaving out the offset. Rolls inspected over more area show more pinholes for no other reason. Without ln(area), the model confuses inspection length with process effects.
- Modeling the rate as the response. Dividing counts by area and running ordinary regression ignores that a rate from 40 m² is noisier than one from 60 m².
- Ignoring overdispersion. Defects often cluster (one bad splice causes ten pinholes). Check the Pearson ratio; if it is well above 1, widen the intervals.
- Reading coefficients as counts. A coefficient is a change in the log of the rate. Convert to rate ratios.
- Using it for proportions. If each unit either has the defect or not, the count of defective units out of n is binomial. Use logistic regression.
Frequently asked questions
What is an offset in Poisson regression?
A term with its coefficient fixed at 1, usually the log of the exposure. It turns the model for counts into a model for rates, so rows with more area, time or units are expected to have proportionally more events.
How do I know if my data are overdispersed?
Divide the Pearson chi-square (or the deviance) by its degrees of freedom. Values near 1 are fine. Values of 1.5 or more, especially with large samples, point to overdispersion, often from clustering or a missing predictor.
What is the difference between Poisson regression and a u chart?
A u chart tracks the defect rate over time and flags unusual periods. Poisson regression explains the rate with predictors such as speed and temperature. Use the chart to find when something changed, and the regression to find what drives the rate.
Can I use Poisson regression with zero counts?
Yes. Zeros are ordinary Poisson outcomes. If there are far more zeros than the model predicts, a zero-inflated model may be needed.