Ken Knoblauch
2004-Jun-15 12:01 UTC
[R] AIC in glm.nb and glm(...family=negative.binomial(.))
Can anyone explain to me why the AIC values are so different when using glm.nb and glm with a negative.binomial family, from the MASS library? I'm using R 1.8.1 with Mac 0S 10.3.4.>library(MASS) > dfr <- data.frame(c=rnbinom(100,size=2,mu=rep(c(10,20,100,1000),rep(25,4))),+ f=factor(rep(seq(1,4),rep(25,4))))> AIC(nb1 <- glm.nb(c~f, data=dfr))[1] 1047> AIC(glm(c~f, family=negative.binomial(nb1$theta), data=dfr))[1] -431804 Actually, the difference is already apparent with the function logLik, but I still would like to understand the difference in what is calculated in the two instances. Thank you, in advance. ____________________ Ken Knoblauch Inserm U 371 Cerveau et Vision 18 avenue du Doyen Lepine 69675 Bron cedex France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: 06 84 10 64 10
Prof Brian Ripley
2004-Jun-15 14:46 UTC
[R] AIC in glm.nb and glm(...family=negative.binomial(.))
You have the code, so take a look for youself. There's an error in the aic formula in negative.binomial (and neg.bin) On Tue, 15 Jun 2004, Ken Knoblauch wrote:> Can anyone explain to me why the AIC values are so different when > using glm.nb and glm with a negative.binomial family, from the MASS > library? I'm using R 1.8.1 with Mac 0S 10.3.4. > > >library(MASS) > > dfr <- data.frame(c=rnbinom(100,size=2,mu=rep(c(10,20,100,1000),rep(25,4))), > + f=factor(rep(seq(1,4),rep(25,4)))) > > AIC(nb1 <- glm.nb(c~f, data=dfr)) > [1] 1047 > > AIC(glm(c~f, family=negative.binomial(nb1$theta), data=dfr)) > [1] -431804 > > Actually, the difference is already apparent with the function logLik, > but I still would like to understand the difference in what is > calculated in the two instances.-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595