[R] generating overdispersed poisson & negative binomial data

Mike Lonergan mel at mcs.st-and.ac.uk
Fri Jun 14 19:31:24 CEST 2002


Thanks for your advice and suggestions,

 (summary: Pat - rnbinom(); Bill - rnegbin() in package MASS; Ben -
compounding distributions)

Which made me look again at what I actually need and realise it isn't all
that much, so I've adopted a very simplistic approach, using negative
binomials with shape parameters chosen to give the desired mean/variance
ratio at the required value of the mean:

# functions to generate random numbers following
# over-dispersed Poisson and negative binomial distributions
# based on simple cheat of using a standard negative binomial,
# but choosing the scale parameter to give the desired mean/variance
# ratio at the given value of the mean.

rpois.od<-function (n, lambda,d=1) {
    if (d==1)
       rpois(n, lambda)
    else
       rnbinom(n, size=(lambda/(d-1)), mu=lambda)
}

rnbinom.od<-function (n, size, prob, mu, d=1) {
    if (!missing(prob)) {
       if (!missing(mu))
          stop("prob and mu both specified")
       mu<-size*(1-prob)/prob
    }
    size2 <- mu/(d-1+(d*mu/size))
    prob2 <- size2/(size2 + mu)
    .Internal(rnbinom(n, size2, prob2))
}

This seems to work well enough for my present needs, and looks reasonably
self consistent. I know I've failed to understand all the subtleties that
could produce more efficient and general results, but am grateful for the
assistance that got me this far.

If anyone can instantly see that this is nonsense please contain your
laughter long enough to enlighten me!

Cheers,

Mike.


     > -----Original Message-----
     > From: owner-r-help at stat.math.ethz.ch
     > [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of Ben Bolker
     > Sent: 10 June 2002 02:47
     > To: Mike Lonergan
     > Cc: R help
     > Subject: Re: [R] generating overdispersed poisson & negative binomial
     > data
     >
     >
     >
     >   I think part of the reason that people use
     > quasi-likelihoods in the
     > first place is that they can't think of simple models that
     > give them the
     > desired scaling ... if you find definitions, e.g. of compounded
     > or generalized distributions that give var=c*mean, I'd be
     > interested.  In
     > the meantime can you do something with compounding distributions?
     > (Unfortunately the only thing that springs to mind is e.g.
     > Poisson with
     > gamma-distributed rate, which gives negative-binomial in any
     > case, not
     > constant var*mean; Poisson+log-normal rate would be slightly more
     > flexible but?  if my moment-generating-functions algebra was
     > less rusty I
     > might play around with it ...)  I also might look in Johnson
     > & Kotz, which
     > I don't have with me.
     >
     > On Thu, 6 Jun 2002, Mike Lonergan wrote:
     >
     > > I would like to try a simple parametric bootstrap, but
     > unfortunately
     > > (stupidly?) my models are "overdispersed" gams & glms.
     > >
     > > I'm hoping for a function that generates overdispersed
     > poisson or negative
     > > binomial data with a given mean, scale (& shape parameter).
     > >
     > > The loose definition I'm using is overdispersed poisson
     > produces integer
     > > values with variance=const*mean & "looks like" a poisson,
     > & simly for
     > > overdispersed negative binomial - I am aware that odnb is
     > a strange thing to
     > > desire.
     > >
     > > Maybe the "integer-valued" bit of my definition is
     > unnecessary, which would
     > > mean a simple scaling would suffice, but I don't know
     > enough to decide on
     > > this without testing.
     > >
     > > Thanks,
     > >
     > > Mike.
     > >
     > >
     > >
     > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
     > .-.-.-.-.-.-.-.-.-
     > > 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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 mailing list