Re: [R] Zero truncated Poisson distribution R2WinBUGS

2011-03-03 Thread Timothée
Hi,
I have a very similar problem...
In some sites, counts data0
In the other sites, counts = 0
I already applied zero inflated models with the zero-trick (Martin et al
2005 in Ecology letters), but I would like to use truncated distributions
(Poisson and negative binomial) to model my counts in order to estimate the
number of sites where no counts but presence.
The problem is that I can't manage to write the likelihood of such truncated
distributions.
Did you get any valuable answers to your post ?
Would you mind to share with me how you succeeded (if so) ?
Thank you very much
Timothée

--
View this message in context: 
http://r.789695.n4.nabble.com/Zero-truncated-Poisson-distribution-R2WinBUGS-tp3043121p406.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Zero truncated Poisson distribution R2WinBUGS

2011-03-03 Thread Achim Zeileis

On Thu, 3 Mar 2011, Timothée wrote:


Hi,
I have a very similar problem...
In some sites, counts data0
In the other sites, counts = 0
I already applied zero inflated models with the zero-trick (Martin et al
2005 in Ecology letters), but I would like to use truncated distributions
(Poisson and negative binomial) to model my counts in order to estimate the
number of sites where no counts but presence.
The problem is that I can't manage to write the likelihood of such truncated
distributions.


If you're looking for a maximum likelihood regression model (without 
random effects), then the countreg package on R-Forge may be helpful for 
you.


The package is not yet on CRAN because we are planning to add more 
functionality, but the code is well tested. It's the same code-base 
underlying zeroinfl() and hurdle() in pscl.


hth,
Z


Did you get any valuable answers to your post ?
Would you mind to share with me how you succeeded (if so) ?
Thank you very much
Timothée

--
View this message in context: 
http://r.789695.n4.nabble.com/Zero-truncated-Poisson-distribution-R2WinBUGS-tp3043121p406.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Zero truncated Poisson distribution R2WinBUGS

2010-11-15 Thread julien martin
I am using a binomial mixture model to estimate abundance (N) and
detection probability (p) using simulated count data:
-Each site has a simulated abundance that follow a Poisson
distribution with lambda = 5
-There are 200 simulated sampled sites
-3 repeated counts at each site
- only 50 percent of the animals are counted during each count (i.e,
detection probability p =0.5, see codes)
We removed sites in which animals were never counted (see matrix y, in
the script)
I would like to use a zero truncated version of the Poisson
distribution (I am aware of zero-inflated binomial mixture models, but
still want to solve the problem described above).
The codes below:
(1) generate a matrix of counts (y), rows correspond to sites and
column to repeat visits at each sites. The script also removes sites
when no animals were counted during the 3 consecutive visits
(2) The second part of the script calls WinBUGS and run the binomial
mixture models on the count data. In this case the count matrix y was
converted to a vector C1 before being passed over to BUGS
Any idea how to create a zero truncated Poisson for parameter lam1
(i.e., parameter lambda of the Poisson distribution)

Thank you for your help.

#R script
#Simulated abundance data
n.site - 200# 200 sites visited
lam - 5 #mean number of animals per site
R - n.site  # nubmer of sites
T - 3  # Number of replicate counts at each site
N=rpois(n = n.site, lambda = lam) #True abundance

# Simulate count data; only a fraction of N is counted which results in y
y - array(dim = c(R, T))
for(i in 1:T){
y[,i] - rbinom(n = n.site, size = N, prob = 0.5)
}
#truncate y matrix
y   # R-by-T matrix of counts
sumy=apply(y,1,sum)
cbindysumy=cbind(y,sumy)
subsetcbindysumy=subset(cbindysumy,sumy!=0)
y=subsetcbindysumy[,1:3]# sites where no animals ever counted are removed
C1-c(y) #vectorized matrix y
R=dim(y)[1]
site = 1:R
site.p - rep(site, T)  
#
#WinBUGS codes
#
library(R2WinBUGS)# Load R2WinBUGS package
sink(Model.txt)
cat(
model {
# Priors: new uniform priors
p0~dunif(0,1)
lam1~dgamma(.01,.01)
# Likelihood
# Biological model for true abundance
 for (i in 1:R) {   # Loops over R sites
   N1[i] ~ dpois(lambda1[i])
   lambda1[i] - lam1
  }
# Observation model for replicated counts
 for (i in 1:n) {   # Loops over all n observations
   C1[i] ~ dbin(p1[i], N1[site.p[i]])
   p1[i] -p0
 }
# Derived quantities
 totalN1 - sum(N1[])   # Estimate total population size across all sites
}
,fill=TRUE)
sink()
# Package data for WinBUGS
R = dim(y)[1]   # number of sites: 200
n = dim(y)[1] * dim(y)[2]#number of observations (sites*surveys)
win.data - list(R = R, n = n, C1 = C1, site.p = site.p)
# Inits
Nst - apply(y, 1, max) + 1
inits - function(){list(N1 = Nst,lam1=runif(1,1,8),  p0=runif(1))}
parameters - c( totalN1, p0, lam1)
# MCMC settings
nc - 3
nb - 400#need to push to 400 for convergence
ni - 1400   #need to push to 14000 for convergence
nt - 1
out - bugs (win.data, inits, parameters, Model.txt, n.chains=nc,
n.iter=ni, n.burn = nb, n.thin=nt, debug = T)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.