Node consistent with parents error

450 views
Skip to first unread message

Tom

unread,
Jul 29, 2022, 8:54:28 AM7/29/22
to hmecology: Hierarchical Modeling in Ecology
Hello all,

With apologies for posting regarding an often repeated question. I am getting the "node inconsistent with parents" error for a fairly basic multi-species occupancy model. I've created initial values, and set all site x species combinations to 1 (i.e., occupied) as per AHM1. The inconsistent node varies between attempted runs, but it is always a 0 in the data. Code is below, happy to share data if that would be useful.

Any idea what I could try to resolve this? Many thanks,
Tom

# Bundle data
test.mod.data <- list(y = species.data,
                     nsite = dim(species.data)[1],    # 124 sites
                     nrep = dim(species.data)[2],     # 2 visits
                     nspec = dim(species.data)[3],   # 71 species
                     Area = Site.area,
                     Observer = Observer.ID,
                     Jul.day = Jul.day)

# JAGS model
sink("Test_model_v1.txt")
cat("
        model {
       
        # Priors for species-specific effects in occupancy and detection
        for(k in 1:nspec){
          lpsi[k] ~ dnorm(mu.lpsi, tau.lpsi)
          betalpsi1[k] ~ dnorm(mu.betalpsi1, tau.betalpsi1)
         
          lp[k] ~ dnorm(mu.lp, tau.lp)
          alphalp1[k] ~ dnorm(mu.alphalp1, tau.alphalp1)
          alphalp2[k] ~ dnorm(mu.alphalp2, tau.alphalp2)
         
        } # / nspec
       
        # Hyperpriors for occupancy
        mu.lpsi ~ dnorm(0,0.01)
        tau.lpsi <- pow(sd.lpsi, -2)
        sd.lpsi ~ dunif(0,8)
       
        mu.betalpsi1 ~ dnorm(0,0.1)
        tau.betalpsi1 <- pow(sd.betalpsi1, -2)
        sd.betalpsi1 ~ dunif(0, 4)

       
        # Hyperpriors for detection
        mu.lp ~ dnorm(0,0.1)
        tau.lp <- pow(sd.lp, -2)
        sd.lp ~ dunif(0, 2)
       
        mu.alphalp1 ~ dnorm(0,0.1)
        tau.alphalp1 <- pow(sd.alphalp1, -2)
        sd.alphalp1 ~ dunif(0,1)
       
        mu.alphalp2 ~ dnorm(0,0.1)
        tau.alphalp2 <- pow(sd.alphalp2, -2)
        sd.alphalp2 ~ dunif(0,1)
       
       
       
        # Ecological model for true occurrence (process model)
        for(k in 1:nspec){
          for (i in 1:nsite) {
                logit(psi[i,k]) <- lpsi[k] +
                                   betalpsi1[k] * Area[i]
       
                          z[i,k] ~ dbern(psi[i,k])
          } # / nspec
        } # / nsite
       
        # Observation model for replicated detection/nondetection observations
        for(k in 1:nspec){
          for (i in 1:nsite){
            for(j in 1:nrep){
                      logit(p[i,j,k]) <- lp[k] +
                                alphalp1[k] * Observer[i,j] +
                                alphalp2[k] * Jul.day[i,j]
                     
                      mu.p[i,j,k] <- z[i,k] * p[i,j,k]
       
                      y[i,j,k] ~ dbern(mu.p[i,j,k])
            } # / nrep
          } # / nsite
        } # / nspec
       
        } # / model
    ", fill = TRUE)

sink()


# Initial values, set all species at occurring
zst <- array(1, dim = c(nsite, nspec))

inits <- function() list(z = zst,
                         lpsi = rnorm(n = nspec),
                         betalpsi1 = rnorm(n = nspec),
                         #betalpsi2 = rnorm(n = nspec),
                         #betalpsi3 = rnorm(n = nspec),
                         lp = rnorm(n = nspec),
                         alphalp1 = rnorm(n = nspec),
                         alphalp2 = rnorm(n = nspec))

# Parameters to monitor
params <- c("mu.lpsi", "sd.lpsi", "mu.betalpsi1", "sd.betalpsi1", "mu.lp", "sd.lp", "mu.alphalp1", "sd.alphalp1", "mu.alphalp2", "sd.alphalp2")

# MCMC settings
ni <- 1500
nt <- 10
nb <- 500
nc <- 3

# Run JAGS
Mod.Out <- jagsUI::jags.basic(test.mod.data, inits, params1, "Test_model_v1.txt", n.chains = nc, n.thin = nt, n.iter = ni, n.burnin = nb, parallel = TRUE)

Marc Kery

unread,
Jul 29, 2022, 1:49:33 PM7/29/22
to Tom, hmecology: Hierarchical Modeling in Ecology
Dear Tom,

that's strange, since this dreaded JAGS error usually happens in occupancy models when there is a discrepancy between the z state at initialization and the observed y data. However, in your case it seems that in addition some species have too low psi and/or too low p for the inits which JAGS chooses randomly (I believe) from the priors specified in the model. So, perhaps if you make the the uniform priors for the species heterogeneity parameters quite a bit wider this will work ? That is, for sd.betalpsi1, sd.alphalp1 and sd.alphalp2. And perhaps also for the SDs of the intercepts, especially for p.

Best regards  ---- Marc    



From: hmec...@googlegroups.com <hmec...@googlegroups.com> on behalf of Tom <tom.bradfe...@gmail.com>
Sent: Friday, July 29, 2022 14:54
To: hmecology: Hierarchical Modeling in Ecology <hmec...@googlegroups.com>
Subject: Node consistent with parents error
 
--
*** Three hierarchical modeling email lists ***
(1) unmarked: for questions specific to the R package unmarked
(2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
(3) HMecology (this list): for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2021) and Schaub & Kéry (2022)
---
You received this message because you are subscribed to the Google Groups "hmecology: Hierarchical Modeling in Ecology" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hmecology+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hmecology/ea8ea293-e6ec-444e-8e36-b3ec6aad62f2n%40googlegroups.com.

Tom

unread,
Jul 29, 2022, 2:24:44 PM7/29/22
to hmecology: Hierarchical Modeling in Ecology
Dear Marc,

Thanks for that. I pushed all the SD hyperpriors up to dunif(0,20). Is that what you meant? Unfortunately, I'm still getting the same error.

Thanks,
Tom

Fergus Chadwick

unread,
Jul 30, 2022, 2:58:04 AM7/30/22
to Marc Kery, Tom, hmecology: Hierarchical Modeling in Ecology
Hey,

JAGS actually doesn’t randomly choose initial values (but this is a common misconception). From page 16 of the manual:

“ If initial values are not supplied by the user, then each parameter chooses its own initial value based on the values of its parents. The initial value is chosen to be a “typical value” from the prior distribution. The exact meaning of “typical value” depends on the distribution of the stochastic node, but is usually the mean, median, or mode.
If you rely on automatic initial value generation and are running multiple parallel chains, then the initial values will be the same in all chains.1 You are advised to set the starting values manually.
1This is undesirable behaviour and it will be changed in a future release of JAGS.”

Best wishes,

Fergus

On 29 Jul 2022, at 18:49, Marc Kery <marc...@vogelwarte.ch> wrote:



Marc Kery

unread,
Jul 30, 2022, 4:38:21 AM7/30/22
to Fergus Chadwick, Tom, hmecology: Hierarchical Modeling in Ecology
Tom: yes, you did what I meant. Sorry it didn't help.

Fergus: thanks for reminding me of the manual.

One more idea: when I have challenging optimisation problems with maximum likelihood (e.g., fitting a dynocc model with covariates using colext() in unmarked) I often adopt a step-up strategy where I fit a simple model first and then incrementally add complexity to the model and use solutions from the last model as inits for the current model. Tom: perhaps you could try that in your case ?

Best regards  --- Marc


From: Fergus Chadwick <fergusj...@gmail.com>
Sent: Saturday, July 30, 2022 08:58
To: Marc Kery <marc...@vogelwarte.ch>
Cc: Tom <tom.bradfe...@gmail.com>; hmecology: Hierarchical Modeling in Ecology <hmec...@googlegroups.com>
Subject: Re: Node consistent with parents error
 

Tom

unread,
Aug 10, 2022, 5:48:20 AM8/10/22
to hmecology: Hierarchical Modeling in Ecology
Hi Marc, all,

Just thought I should report back. I eventually got it working by limiting the 'inits' to just:
inits <- function() list(z = zst)

Thanks again,
Tom

Reply all
Reply to author
Forward
0 new messages