1. Poisson regression (without offset)

Data preparation:

Untitled

Fit the Poisson regression model:

Untitled

2. Poisson regression (with offset)

Data preparation: a dataset called eba1977 from the ISwR package. This data set contains counts of incident lung cancer cases and population size in four neighbouring Danish cities by age group.

Untitled

在本例中,字段pop就是一个明显的interval字段。因此我们用带有offset的泊松回归模型:

$$ y_i \sim \text{Poiss}(\lambda_it_i)\\

\ln(\lambda_it_i) = \beta^T\mathbf{x}_i + \ln(t_i) $$

有两步不同:第一,需要将interval字段取ln后变成新的一列;第二,在回归时用offset将该log_interval字段包起来:

Untitled