[R] Goodness of fit to Poisson / NegBinomial
ben at zoo.ufl.edu
Wed Feb 7 14:50:22 CET 2001
A couple of offhand comments (which may already have occurred to you):
1. lumping categories is relatively straightforward but a little bit hard
to automate well (and maybe not worth automating) -- it sometimes requires
a judgement call. For example, in this case I'd probably lump categories
5, 6, and 7, but if I had another category with 4 instances of 8 mites I'd
lump (5,6) and (7,8). It's probably just worth looking at the category
and doing things manually ...
> > tab <- table(mites)
> > NSU <- length(mites)
> > N <- sum(mites)
> > NSU.Mean <- N / NSU
> > exp <- dpois(as.numeric(dimnames(tab)[]), NSU.Mean) * NSU
Lump and truncate both the expected and observed distributions:
tab <- sum(tab[6:8])
tab <- tab[1:6]
exp <- sum(exp[6:8])
exp <- exp[1:6]
> > chi2 <- sum(((as.vector(tab) - exp)^2) / exp)
> > tab
> > exp
> > chi2
> > I have some small expected values and so need to collapse some
> > categories. If anyone has code to do that already ... but my
> > question is how would I do the same for a negative binomial
> > distribution?
> The negative binomial density function is available in my rmutil
> library. (www.luc.ac.be/~jlindsey/rcode.html)
Two more comments:
2. the negative binomial density is also available in the base R package
(dnbinom), although the parameterization is in terms of Bernoulli trials
(size/prob) rather than the mu/(k,theta) parameterization that most
ecologists are used to. [Incidentally, I noticed the other day that
"rnegbin" in the MASS package appears to duplicate functionality that is
(now) available in R, namely that it can generate variates for non-integer
k/theta parameters. In my own R libraries I've also extended the *nbinom
functions so that they can alternately take the mu/k parameters instead
3. estimating the parameters of the neg. bin. is harder than estimating
that for the Poisson; you may want to check out theta.md, theta.ml,
theta.mm in the MASS package.
Don't have time to do a more extended example at the moment.
Hope this helps.
> > Mark
> > --
> > Mark Myatt
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> > Send "info", "help", or "[un]subscribe"
> > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
318 Carr Hall bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
Box 118525 (ph) 352-392-5697
Gainesville, FL 32611-8525 (fax) 352-392-3704
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help