Poisson Regression In R

Hi there. Here is some experimental work that I have done with Poisson regression in R.


Sections

 

 

 

 


The Poisson Regression Model

In ordinary least squares regression, the errors/residuals are assumed to be normally distributed and the responses are continuous (real numbers).

    \[Y = \beta_{0} + \beta_{1}x_{1} + \beta_{2}x_{2} + ... + \beta_{n}x_{n} + \epsilon\]

In Poisson regression, the errors are not normally distributed and the responses are counts (discrete). The errors follow a Poisson distribution and we model the (natural) logarithm of the response variable. That is, we have ln(\mu) with \mu = \text{e}^{Y} instead of just Y for the response variable. A link function is used to achieve the linear form.

 


Poisson Regression Using R Example

In R, I work with a motor insurance dataset from the faraway library. I am interested to see the relationship of number of insurance claims based on the payments (in Swedish Kronas) through a plot.

Here is the code and plot. (Use ?motorins to find documentation about the dataset.)

 

Fitting A Poisson Model

The Poisson model belongs to a class of generalized linear models (GLMs). In R, the glm() function along with having family = poisson is used to fit a Poisson model to the data.

 

 

A ggplot2 Plot

 

 

 

 

 


References

  • http://www.theanalysisfactor.com/regression-models-for-count-data/
  • Book: Extending The Linear Model With R By Julian J Faraway
  • https://stackoverflow.com/questions/23725555/add-simulated-poisson-distributions-to-a-ggplot
  • https://www.stat.wisc.edu/courses/st572-larget/handouts11-2.pdf

Leave a Reply