Solved – Goodness of Fit for Poisson Regression using R

chi-squared-testdeviancegoodness of fitpoisson-regression

I am trying to determine how well a Poisson model fits my data using Residual Null and Saturated Deviances. The Y col is the # of pennies that landed in a cup and the cup column represents the size. This is the R-code I have so far.

Y=c(4,7,2,5,4,5,10,6,8,2,9,9,9,7,10)
Cup=c(0,2,0,0,0,1,1,1,2,1,2,0,2,1,2)

sum(Y)
M1=glm(Y~Cup,family="poisson")
M1$deviance

SaturatedProbs=dpois(Y,Y)
SaturatedProbs
Ls=prod(SaturatedProbs)
Ds=-2*log(Ls)
Ds

#NullProbs
ln=sum(Y)/length(Y)
probsn=dpois(Y,ln)
Ln=prod(probsn)
Ln
Dn=-2*log(Ln)
Dn

Dn-Ds

Ultimately, I want to compare my model to a chi_square distribution. I am having some trouble determining the appropriate inputs. Is what I have so far enough to determine the goodness-of-fit?

Best Answer

You would need the deviances and the degrees of freedom to perform a deviance test. If the model fits the data well then $D_1 \sim \chi^2(n-p)$ and $D_2 \sim \chi^2(n-q)$. $D_1$ and $D_2$ are deviances for model 1 and model 2. $n$ is the number of parameters for saturated model. $p$ and $q$ are the number of parameters for given models ($q < p < n$)

Deviance test:

$$D_1 - D_2 \sim \chi^2(p-q)$$

If value is greater than expected from chi squared, reject model 1.