Skip to content
Prev 2057 / 7420 Next

zero-truncated Poisson

Thanks Ben and Peter for your thoughtful replies.  This gives me quite a bit to chew on and digest but I think I can analyze these data.



-----Original Message-----
From: Ben Bolker [mailto:bbolker at gmail.com] 
Sent: Sunday, April 10, 2011 10:38 AM
To: Peter Solymos
Cc: Stratford, Jeffrey; r-sig-ecology at r-project.org
Subject: Re: [R-sig-eco] zero-truncated Poisson
On 11-04-09 03:07 AM, Peter Solymos wrote:
I agree.  I would just like to point out that, if you define the
truncated Poisson distribution function appropriately, you can then do
this very compactly via the mle2 function in the bbmle package.

dtruncpois <- function(x,lambda,log=FALSE) {
  r <- ifelse(x==0,-Inf,dpois(x,lambda,log=TRUE)-
              log(1-dpois(0,lambda,log=FALSE)))
  if (log) r else exp(r)
}

library(bbmle)
(m1 <- mle2(taken~dtruncpois(exp(logmu)),
           parameters=list(logmu~mass+year),
           data=blja,
           start=list(logmu=1)))
coef(m1)
summary(m1)  ## gives a table almost equivalent to Peter's
confint(m1)  ## profile confidence intervals

  After a bit of digging it seems that VGAM::vglm fails when it hits an
NaN -- I haven't figured out more than that it gets this on the *second*
step, not the first, of the optimization. When it works VGAM should be
faster than the sort of generalized ML estimation that Peter and I are
suggesting, but I have fairly often found it to be not very robust when
I try it.

 If you plot the data (with a regular Poisson GLM superimposed):

library(ggplot2)
ggplot(blja,aes(x=mass,y=taken,colour=year))+
  stat_sum(alpha=0.5)+geom_smooth(method="glm",family="poisson")+
  theme_bw()

  You see that there are two observations with very large masses.
It turns out that removing these two observations allows vglm() to work:

glm1 <- vglm(taken ~ mass + year,family=pospoisson,
             data=blja,subset=mass<10)


m2 <- mle2(taken~dtruncpois(exp(logmu)),
            parameters=list(logmu~mass+year),
            data=subset(blja,mass<10),
            start=list(logmu=1))

 It also changes the estimate of the mass effect considerably:

confint(m1)
confint(m2)

  Ben Bolker