Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Poisson Regression?

There are 2 types of Generalized Linear Models:
1. Log-Linear Regression, also known as Poisson Regression
2. Logistic Regression

How to implement the Poisson Regression in Python for Price Elasticity prediction?

like image 988
User456898 Avatar asked Jun 21 '16 10:06

User456898


People also ask

How do you find Poisson regression?

P ( Y i = y i | X i , β ) = e − exp ⁡ { X i β } exp ⁡ That is, for a given set of predictors, the categorical outcome follows a Poisson distribution with rate ⁡ . For a sample of size n, the likelihood for a Poisson regression is given by: L ( β ; y , X ) = ∏ i = 1 n e − exp ⁡ { X i β } exp ⁡

When can I use Poisson regression?

Poisson Regression models are best used for modeling events where the outcomes are counts. Or, more specifically, count data: discrete data with non-negative integer values that count something, like the number of times an event occurs during a given timeframe or the number of people in line at the grocery store.


1 Answers

Have a look at the statmodels package in python.

Here is an example

A bit more of input to avoid the link only answer

Assumming you know python here is an extract of the example I mentioned earlier.

import numpy as np
import pandas as pd
from statsmodels.genmod.generalized_estimating_equations import GEE
from statsmodels.genmod.cov_struct import (Exchangeable,
    Independence,Autoregressive)
from statsmodels.genmod.families import Poisson

pandas will hold the data frame with the data you want to use to feed your poisson model. statsmodels package contains large family of statistical models such as Linear, probit, poisson etc. from here you will import the Poisson family model (hint: see last import)

The way you fit your model is as follow (assuming your dependent variable is called y and your IV are age, trt and base):

fam = Poisson()
ind = Independence()
model1 = GEE.from_formula("y ~ age + trt + base", "subject", data, cov_struct=ind, family=fam)
result1 = model1.fit()
print(result1.summary())

As I am not familiar with the nature of your problem I would suggest to have a look at negative binomial regression if you need to count data is well overdispersed. with High overdispersion your poisson assumptions may not hold.

Plethora of info for poisson regression in R - just google it.

Hope now this answer helps.

like image 195
Altons Avatar answered Sep 19 '22 12:09

Altons