3.8 Poisson regression (counts)
The Poisson family models count responses —
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)
(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.
(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 —
(poisson-predict-mean result X) ; => fitted means, increasing with x1