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)
After the intercept, β₁ is close to the 0.3 the counts were built around, and the noise coefficient is exactly 0.0. 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 (vector-ref (poisson-result-coefficients fit) 0)) 1.3458572276715626
1.6.9.3 Predicting
poisson-predict-mean applies the log link and returns the fitted mean for each row; it is predict with #:type 'response. Next to the observed counts:
> (for/list ([mu (in-list (poisson-predict-mean fit X))] [count (in-list y)]) (list count mu))
'((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:
> (poisson-result-coefficients (poisson-fit X '(0.5 1.0 1.2 1.5 2.0 3.1 4.0 5.6) #:lambda 0.1)) '#(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.