Modeling counts with Poisson regression

Today let's understand Poisson regression, the model built specifically for an outcome that counts how many times something happens.

A count like this can only land on 0, 1, 2 and so on. It can never go negative, and it can never land on a fraction like 2.5. That single fact rules out a lot of models you might otherwise reach for, as you will see in a moment.

Here is the example we will use for the whole lesson: a single bike-share station's daily rental count, recorded for 120 days. On 89 of those days it did not rain, and the station averaged 90.08 rentals a day. On the other 31 days it rained, and the average fell to 65.81.

Here is every one of those 120 days, plotted by whether it rained that day.

Each dot is one day's rental count. The dry days sit higher as a group and the rainy days sit lower, but within each group the count still jumps around from day to day, never settling on one fixed number. That is the shape of data Poisson regression is built for: a count, bounded at zero, that moves with a condition like the weather.

Why a plain linear model is the wrong tool for a count

So why not just fit an ordinary linear model here, with rain as a yes-or-no predictor and rentals as the outcome?

There are two problems, and the 120 days you just saw already carry both of them.

  • A count can never be negative or a fraction, but an ordinary linear model's prediction is not built to respect that. Nothing stops it from predicting a number like -4 rentals, which cannot exist.
  • An ordinary linear model also assumes the outcome spreads out by the same amount everywhere, no matter what the prediction is. Look at what actually happens in the rental data.
RInteractive R
# Compare the mean and spread of rentals on dry and rainy days set.seed(2026) rain <- rbinom(120, 1, 0.3) rentals <- rpois(120, ifelse(rain == 1, 65, 90)) dry_rentals <- rentals[rain == 0] rain_rentals <- rentals[rain == 1] mean(dry_rentals) var(dry_rentals) mean(rain_rentals) var(rain_rentals) #> [1] 90.07865 #> [1] 95.45965 #> [1] 65.80645 #> [1] 52.29462

  

The dry days average 90.08 rentals and spread out with a variance of 95.46. The rainy days average 65.81 rentals, a lower number, and their variance is also lower, at 52.29. The group with the bigger average also has the bigger spread.

That is not a coincidence, and it is not something an ordinary linear model can represent. It assumes one fixed spread for the whole dataset, but here the spread rises and falls right along with the mean. You need a model built around that connection, not one that ignores it.