On this page:
<require>
<provide>
<data>
<fit>
<run-example>
<*>

3.8 Poisson regression (counts)🔗ℹ

The Poisson family models count responses — non-negative numbers like events per interval. It uses a log link, so the fitted mean is μ = exp(β₀ + x·β) and a positive coefficient multiplies the expected count. Poisson has an intercept (unlike Cox), and the elastic-net knobs (α, λ) are the same as every other family.

In the synthetic data below the expected count rises with x₁, while x₂ is noise. A lasso-penalized fit recovers a positive β₁ and drops x₂ to exactly 0.0.

(require glmnet)

(provide run-example)

<data> ::=
(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)))
; counts roughly following exp(0.3 * x1)
(define y '(1 2 2 3 4 6 8 11))

poisson-fit takes the predictor matrix and the count response. The x₁ coefficient comes back positive (the rate rises with x₁) and the noise β₂ is exactly 0.0; poisson-result-dev-ratio is the fraction of null deviance explained.

<fit> ::=

(define result (poisson-fit X y #:lambda 0.2))

poisson-predict-mean applies the log link to return the fitted rate exp(β₀ + x·β) for each row — here it tracks the observed counts:

(poisson-predict-mean result X)
; => fitted means, increasing with x1

(define (run-example)
  <data>
  <fit>
  result)

<*> ::=