On this page:
1.6.9.1 The data
1.6.9.2 Fitting
1.6.9.3 Predicting
1.6.9.4 The response
1.6.9.5 When to use it
9.4.0.2

1.6.9 Poisson regression (counts)🔗ℹ

Source: "glmnet/examples/07-poisson.rkt"

The Poisson family models counts: non-negative responses such as events per interval. It uses a log link, so the fitted mean is μ = exp(β₀ + xβ) and each predictor multiplies the expected count rather than adding to it. Unlike Cox, Poisson fits an intercept, and the penalty is the same as for every other family.

1.6.9.1 The data🔗ℹ

The counts grow roughly like exp(0.3 x₁); x₂ is noise:

> (define X '((1.0 2.0) (2.0 1.0) (3.0 2.0) (4.0 1.0)
              (5.0 2.0) (6.0 1.0) (7.0 2.0) (8.0 1.0)))
> (define y '(1 2 2 3 4 6 8 11))
1.6.9.2 Fitting🔗ℹ
> (define fit (poisson-fit X y #:lambda 0.2))
> fit

#<glmnet:poisson λ=0.2 dev=0.9859 nz=1/2>

> (coef fit)

'#(-0.026590920441019072 0.29703115403010283 0.0)

The noise coefficient is exactly 0.0. To three decimals, β₁ is close to the 0.3 the counts were built around:

> (match-define (vector _ β₁ _) (coef fit))
> (fmt β₁)

"0.297"

The coefficients are on the log scale; exponentiated, β₁ is a rate ratio, the factor by which one more unit of x₁ multiplies the expected count:

> (exp β₁)

1.3458572276715626

1.6.9.3 Predicting🔗ℹ

predict with #:type 'response applies the log link and returns the fitted mean for each row; poisson-predict-mean is the same call. Each observed count next to its fitted mean:

> (map list y (predict fit X #:type 'response))

'((1 1.3105412680428272)

  (2 1.7638014377572937)

  (2 2.3738249131831473)

  (3 3.1948294166343585)

  (4 4.299784261555074)

  (6 5.786895725842328)

  (8 7.788335438406571)

  (11 10.481987541310053))

1.6.9.4 The response🔗ℹ

The response must be non-negative, but it need not be an integer, so rates such as events per hour fit too:

> (define rates (poisson-fit X '(0.5 1.0 1.2 1.5 2.0 3.1 4.0 5.6) #:lambda 0.1))
> (coef rates)

'#(-0.6695950023099362 0.29217287530369 0.0)

When observations cover different exposures (different lengths of time, different population sizes), R’s glmnet takes an offset of log(exposure). The bindings do not support offsets yet (#12).

1.6.9.5 When to use it🔗ℹ

Use the Poisson family for counts: defects per batch, visits per day, claims per policy. The model assumes a count’s variance equals its mean; counts that vary much more than that (overdispersion) are a poor fit for it.