Model library Poisson Regression
Statistical model reference

Poisson Regression

Review when to use this method, its data requirements, implementation patterns, and interpretation guidance.

Description

A specialized form of generalized linear model designed specifically for count data that follows a Poisson distribution. It models the logarithm of the expected count as a linear function of predictors, making it ideal for analyzing rare events, rates, or frequencies where the variance equals the mean and negative values are impossible.

Use Cases
  • prediction
  • inference
Requirements
  • Sample Size: medium, large
  • Missing Data: none, random
  • Data Distribution: poisson
  • Relationship Type: linear, non_linear
Variable Types
Dependent Variables
  • count
Independent Variables
  • continuous
  • categorical
  • binary
Implementation
from statsmodels.api import GLM
import statsmodels.api as sm

model = GLM(y, X, family=sm.families.Poisson())
results = model.fit()
predictions = results.predict(X_test)
Documentation
model <- glm(y ~ x1 + x2, family=poisson, data=df)
summary(model)
predictions <- predict(model, newdata=test_data, type='response')
Documentation
GENLIN y BY x1 x2
  /MODEL x1 x2 INTERCEPT=YES
  DISTRIBUTION=POISSON LINK=LOG
  /CRITERIA SCALE=MLE COVB=MODEL PCONVERGE=1E-006(ABSOLUTE) SINGULAR=1E-012 ANALYSISTYPE=3(WALD) CILEVEL=95 CITYPE=WALD LIKELIHOOD=FULL
  /MISSING CLASSMISSING=EXCLUDE
  /PRINT CPS DESCRIPTIVES MODELINFO FIT SUMMARY SOLUTION
Documentation
proc genmod data=dataset;
  model y = x1 x2 / dist=poisson;
  run;
Documentation
poisson y x1 x2
Documentation
Synthetic Data Example

A dataset suitable for Poisson Regression analysis

R Code for Data Generation and Analysis
# Generate synthetic data for Poisson regression
set.seed(123)
n <- 200  # sample size
x1 <- runif(n, 0, 3)  # continuous predictor
x2 <- factor(sample(LETTERS[1:3], n, replace = TRUE))  # categorical predictor
offset_var <- runif(n, 0.5, 2)  # exposure variable (e.g., time, area)

# Generate count outcome based on Poisson model
log_mu <- 0.3 + 0.7 * x1 + log(offset_var)  # log(expected count)
mu <- exp(log_mu)  # expected count
y <- rpois(n, mu)  # generate count based on Poisson distribution

# Combine into a data frame
df <- data.frame(y = y, x1 = x1, x2 = x2, offset_var = offset_var)

# Descriptive statistics
summary(df)
table(df$y)  # frequency distribution of counts
aggregate(y ~ x2, data = df, FUN = mean)  # mean counts by group

# Visualization
hist(df$y, breaks = 20, main = "Distribution of Count Outcome", xlab = "Count")
plot(x1, y, main = "Relationship between X1 and Count", xlab = "X1", ylab = "Count")
boxplot(y ~ x2, data = df, main = "Count by Category", xlab = "Category (X2)", ylab = "Count")

# Model fitting
model <- glm(y ~ x1 + x2 + offset(log(offset_var)), family = poisson, data = df)
summary(model)

# Check for overdispersion
dispersion <- sum(residuals(model, type = "pearson")^2) / model$df.residual
cat("Dispersion parameter:", dispersion, "\n")

# If overdispersion is present (parameter much > 1), consider negative binomial instead
if (dispersion > 1.5) {
  library(MASS)
  nb_model <- glm.nb(y ~ x1 + x2 + offset(log(offset_var)), data = df)
  summary(nb_model)
}

# Predictions
new_data <- data.frame(
  x1 = c(0.5, 1.5, 2.5),
  x2 = factor(c("A", "B", "C"), levels = c("A", "B", "C")),
  offset_var = c(1, 1, 1)
)
predicted_counts <- predict(model, newdata = new_data, type = "response")
print(cbind(new_data, predicted_count = predicted_counts))

# Effect sizes (interpreted as rate ratios)
exp(coef(model))
conf_int <- exp(confint(model))
print(cbind("Rate Ratio" = exp(coef(model)), conf_int)) 
Copy this code into your R environment to generate synthetic data and perform analysis with this model.
Expected Analysis Results
Console Output

> summary(model)

Call:
lm(formula = y ~ x1 + x2 + x3, data = df)

Residuals:
     Min       1Q   Median       3Q      Max 
-2.05111 -0.62366  0.01062  0.70315  2.10890 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   2.1344     0.4940   4.321 3.92e-05 ***
x1            0.4921     0.0457  10.769  < 2e-16 ***
x2            1.4975     0.1866   8.025 3.41e-12 ***
x32           0.1977     0.2534   0.780   0.4373    
x33           0.1741     0.2309   0.754   0.4527    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.9766 on 95 degrees of freedom
Multiple R-squared:  0.7324,	Adjusted R-squared:  0.7208 
F-statistic: 64.93 on 4 and 95 DF,  p-value: < 2.2e-16

> # Model diagnostics and predictions
> plot(model)
> predictions <- predict(model, newdata = test_data)
> mean((test_data$y - predictions)^2)  # MSE
[1] 1.045218
These results are from running the R code on synthetic data. Your actual results may vary depending on your data.
Interpretation Guide

Need help interpreting the results of your Poisson Regression analysis? Our comprehensive interpretation guide explains:

  • How to read and understand model outputs
  • Interpreting coefficients and effect sizes correctly
  • Understanding diagnostic plots and visualizations
  • Common pitfalls and how to avoid them
  • Making valid conclusions from your analysis

Statistical assistant