On Fri, Mar 20, 2009 at 8:03 PM, t c <mudiver1200 at yahoo.com>
wrote:> Dear r list,
>
> I am using glm.nb in the MASS package to fit negative binomial models to
data on manta ray abundance, and AICctab in the bbmle package to compare model
IC.? However, I need to test for the goodness of fit of the full model, and have
not been able to find a Pearson's Chi Squared statistic in any of the
output.? Am I missing it somewhere?? Is there a way to run the test using either
chisq.test() or goodfit()?? I would appreciate any suggestions on how to test
for goodness of fit in negative binomial models.
>
> Thanks,
>
> Tim Clark
I found myself wondering if the Chi Square you get from anova() is the
Pearson one you want? (see ?anova.negbin).
Just an example:
> library(MASS)
> example(glm.nb)
> anova(quine.nb3)
Analysis of Deviance Table
Model: Negative Binomial(1.9284), link: log
Response: Days
Terms added sequentially (first to last)
Df Deviance Resid. Df Resid. Dev P(>|Chi|)
NULL 145 272.291
Sex 1 1.705 144 270.586 0.192
Sex:Age 6 30.202 138 240.384 3.599e-05
Sex:Eth 2 20.461 136 219.923 3.606e-05
Sex:Lrn 2 8.459 134 211.465 0.015
Sex:Eth:Lrn 2 18.287 132 193.178 1.069e-04
Sex:Age:Lrn 4 8.649 128 184.529 0.070
Sex:Age:Eth 6 9.503 122 175.025 0.147
Sex:Age:Eth:Lrn 4 7.572 118 167.453 0.109
Warning message:
In anova.negbin(quine.nb3) : tests made without re-estimating
'theta'>
That warning about re-estimating theta concerns me a bit.
If that's not the correct Pearson statistic, I bet you can get what
you need if you take the Pearson residuals and calculate whatever. I
am looking at
?residuals.glm
and I note you can get Pearson residuals. If you have a formula from
a dusty old stats book with the formula, I bet you can get it done.
pj
--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas