I am trying to model count data using python's statsmodels module (Beer's sold at a football stadium as function of visitors, "tilskuer", and weather data).

model1 = smf.GLM(Y,Xall,sm.families.Poisson(sm.families.links.log)).fit()

Y is a count response, and Xall is a 20 x 5 data matrix (20 observations, 5 variables, X is shown below).

enter image description here

I get the results shown in the table below.

enter image description here

My first instinct was that this was decent, and that all the variables were significant. I looked at the QQ-plot which looks decent (from what I understand about it, shown below).

enter image description here

However, when I read a bit more about these things I found that for a Poisson model to correctly model the data (Variance = Mean) the Deviance/DF resid. should be approx. 1.

Mine is approx. 100.

So does this mean this model is completely off? Even though the QQ plot looks decent? Or how should I interpret this?

I tried using a negative binomial dist. instead.

model3 = smf.GLM(Y,Xall,family=sm.families.NegativeBinomial(sm.families.links.log)).fit()

This gave the opposite "error". Now the deviance is VERY small compared to DF Resid.

enter image description here

Ps. I want to add the variable "Tilskuer" as an offset, but can't seem to get smf.GML() to accept it in anyway (It makes the SVD composition "not converge").


For modelling count data in regression settings, the negative binomial GLM is far preferable to the Poisson GLM. Indeed, I would go so far as to say that the latter is a bad model that should almost never be used (see discussion here). Generally speaking, the residual values from a Poisson model will not identify problems with overdispersion. What usually happens is that the overdispersion gets "absorbed" as best it can be (which is not well) into the explanatory variables, and so the residuals do not necessarily manifest any unusual pattern. This screws up the inferred relationships between the explanatory variables and the response, but it does not show up as a problem in the residual plots.

Many analysts start by fitting a Poisson GLM and then use an overdispersion test to determine whether they should generalise this model to the negative binomial GLM. If you decide to do this, it is preferable to use a formal hypothesis test for overdispersion (see e.g., here), rather than appealing to rough comparisons of the outputs of the regression model. In any case, for reasons explained at the linked post, my view is that this whole process is unnecessary, and is a bad statistical practice --- in my view, you should just skip the Poisson GLM and overdispersion testing altogether, and start with anegative binomial GLM or some other two-parameter family that can fit the dispersion properly.

In the present case it appears that you have overdispered data, and so the negative binomial GLM is appropriate. As I said, I would have started with this in the first place. As you can see, once you fit this latter model, the weather variables other than temperature no longer show evidence of a statistical relationship with the response variable. (I code all my models in R, so I am not sure how to add an offset when fitting a GLM in Python. I will leave it to others to answer that aspect of your question.)


Your approach would be correct, but in this case maybe not.

If there is overdispersion with a poisson, than you should use a negative binomial model or a quasipoisson, as you did.

To check overdispersion, maybe it is necessary that the ratio of residual deviance with residual DF is greater or equal 3. I am not sure about this number.

However I suggest to use tweedie distribution, since you have not a discrete variable, but continous. "Tweedie distributions with a parameter between 1 and 2 are useful for modelling continuous data with exact zeros." (see reference)

Reference : "Generalized linear models - with examples in R" - page: 463.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.