[R] package MASS - MLE of negative binomial distributions
Rik Verdonck
rik.verdonck at bio.kuleuven.be
Thu Dec 10 16:21:07 CET 2015
Dear list,
I have a question about the exact estimate of the maximum likelihood for a negative binomial fit. I'm trying to approach this in two different ways: the first one is a fit using the glm.nb method, and the second one is a fit using the fitdistr function for each condition separately, where I add up all log likelihoods. These two methods do not yield the same values for the log likelihood of the fit. They do yield the same log likelihood if all data are one group (no summation), so I assume I'm doing something wrong when I sum up log likelihoods. Am I not "allowed" to do this?
Example code:
library(MASS)
x<-c(601,619,637,609,594,499,494,507,477,450,400,367,428,359,400,276,260,262,304,342,216,189,152,231,200,104,85,85,85,112)
groups<-as.factor(c(rep("dist1",5),rep("dist2",5),rep("dist3",5),rep("dist4",5),rep("dist5",5),rep("dist6",5)))
glm.nb(x~groups)$twologlik
logliks<-NULL
for(group in levels(groups))
{
NBfit<-fitdistr(x[groups==group],"Negative Binomial")
logliks<-c(logliks,NBfit$loglik)
rm(NBfit)
}
sum(logliks)*2
Many thanks!
Rik
More information about the R-help
mailing list