occupancy model with missing values in JAGS

1,125 views
Skip to first unread message

Sean Sultaire

unread,
Nov 20, 2015, 4:40:35 PM11/20/15
to unmarked
Hello Unmarked group,

I'm attempting to run a single season occupancy model in R2jags containing 1 occupancy covariate and 1 detection covariate. My model is as follows


sink("model.hare.mi")
cat("
    model {
   
    # Priors
    alpha.occ ~ dunif(-10, 10)
    beta.occ ~ dunif(-10, 10)
    alpha.p ~ dunif(-10, 10)
    beta.p ~ dunif(-10, 10)
   
    # Likelihood
    for (i in 1:R) {
    # True state model for the partially observed true state
    z[i] ~ dbern(psi[i])             # True occupancy z at site i
    logit(psi[i]) <- alpha.occ+beta.occ*forest[i,]
   
    for (j in 1:T) {
    # Observation model for the actual observations
    y[i,j] ~ dbern(p.eff[i,j])    # Detection-nondetection at i and j
    p.eff[i,j] <- z[i] * p[i,j]
    logit(p[i,j]) <- alpha.p +beta.p*density[i,j]
    } #j
    } #i
   
    # Derived quantities
    occ.fs <- sum(z[])       # Number of occupied sites among those studied
    }
    ",fill = TRUE)
sink()

win.data <- list(y = y,Density=Density,forest=forest,R = nrow(y), T = ncol(y))


zst <- rep(1, 195)      # Observed occurrence as starting values for z
inits <- function() {list(z = zst, alpha.occ = runif(1, -3, 3), beta.occ = runif(1, -3, 3), alpha.p = runif(1, -3, 3),beta.p=0)}

# Parameters monitored
params <- c("alpha.occ", "beta.occ", "alpha.p","beta.p", "occ.fs")

# MCMC settings
ni <- 15000
nt <- 8
nb <- 5000
nc <- 3

# Call JAGS from R (BRT < 1 min)
out.density <- jags(win.data, inits, params, "model.hare.wi", n.chains = nc, n.thin = nt, n.iter = ni, n.burnin = nb, working.directory = getwd())


I'm running into a problem and I think it is due to missing values in the detection covariate matrix, which correspond with missing value in the detection the matrix. The error is as follows

Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains,  : 
  RUNTIME ERROR:
Unable to resolve the following parameters:
Density[1,10] (line 20)
Density[1,11] (line 20)
Density[1,12] (line 20)
Density[1,13] (line 20)
Density[1,14] (line 20)
Density[1,15] (line 20)
Density[1,16] (line 20)
Density[1,17] (line 20)


and the list up the max error print. Density[1,10] is the first missing value in the matrix and if I put an arbitrary value here the error starts on Density[1,11], which is why I think the missing values are causing the problem. The data set does contain about 50% missing values but this does not seem like a convergence problem to me. I believe that JAGS should be able to handle these missing values. Am I wrong about this? Is putting values in place of missing values in this matrix a problem if I keep the missing values in the detection data?

Any insight is greatly appreciated.

Sean

Kery Marc

unread,
Nov 20, 2015, 4:43:42 PM11/20/15
to unma...@googlegroups.com
Dear Sean,

that's a question for the HMecology forum, see here: see groups.google.com/forum/?hl=en#!forum/hmecology

Regards  --- Marc

______________________________________________________________
 
Marc Kéry
Tel. ++41 41 462 97 93
marc...@vogelwarte.ch
www.vogelwarte.ch
Swiss Ornithological Institute | Seerose 1 | CH-6204 Sempach | Switzerland
______________________________________________________________

********* NEW Hierarchical modeling books (due November 2015 and in 2016) *********
*** Kéry & Royle (2016): Applied hierarchical models in ecology, Academic Press, Volume 1, Prelude and Static Models, see here: http://www.amazon.de/Applied-Hierarchical-Modeling-Ecology-Marc/dp/0128013788
Book web site: www.mbr-pwrc.usgs.gov/pubanalysis/keryroylebook/
*** Kéry & Royle (2016): AHM Volume 2,  Dynamic and advanced models, due late 2016

***   Published hierarchical modeling books   ***
(1) Kéry (2010): Introduction to WinBUGS for Ecologists, Academic Press; see www.mbr-pwrc.usgs.gov/pubanalysis/kerybook 
(2) Kéry & Schaub (2012): Bayesian Population Analysis using WinBUGS, Academic Press; see www.vogelwarte.ch/bpa

***   Hierarchical modeling workshops: www.phidot.org/forum/viewforum.php?f=8

***   Hierarchical modeling Google Group mailing lists   ***
(1) unmarked: for questions specific to the R package unmarked
(2) hmecology: for material covered in Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2015); see groups.google.com/forum/?hl=en#!forum/hmecology

From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Sean Sultaire [sult...@gmail.com]
Sent: 20 November 2015 22:40
To: unmarked
Subject: [unmarked] occupancy model with missing values in JAGS

--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mathias Tobler

unread,
Nov 20, 2015, 6:51:11 PM11/20/15
to unmarked

Sean,

three things.

1) in win.data your variable is Density and in your model the variable is density. The BUGS language is case sensitive so it does not recognize Density.

2) You can't have missing values in your independent variables (e.g. forest, density) unless you draw missing values from a distribution in your model. Missing values for y are not an issue. 50% missing values seems very high. You might want to first test your model without the missing values to make sure it runs well.

3) Use normal priors for your alpha and beta.

Hope that helps.

Mathias

Jeffrey Royle

unread,
Nov 20, 2015, 6:55:05 PM11/20/15
to unma...@googlegroups.com, hmec...@googlegroups.com
hi all,
 let's take this over the hmecology group so as to not clutter up the unmarked list (and also so that others may benefit). I see that list here.
regards
andy


--
Reply all
Reply to author
Forward
0 new messages