Menu

#36 Dump node values when "Invalid parent values" or "node inconsistent with parents at initialization"

v1.0_(example)
open
nobody
None
1
2015-02-26
2015-02-26
No

There are several cases of errors in JAGS model run where it would be very useful if JAGS dumped "parent values" to actually see where the problem is:

1)
"Error in node Y[107]
Invalid parent values"

Please dump those "invalid parent values"! See http://stackoverflow.com/q/27167416/684229 for more details

2)
"Error: The following error occured when compiling and adapting the model using rjags:
Error in rjags::jags.model(model, data = dataenv, inits = inits, n.chains = length(runjags.object$end.state), :
Error in node Y[34,10]
Observed node inconsistent with unobserved parents at initialization.
Try setting appropriate initial values."

Please dump those "unobserverd parents" as well! And the chain in which it did happen. This would help me tremendously. Otherwise, I had to create code like this to get the parents, which is quite complicated:

with(c(list.format(failedjags$inits[3]), win.data), { 
     i <- 34; k <- 5;
     phi <- c(); 
     twosigma2 <- exp(twosigma2_int + sum(b_det * detCov[i,])); 
     for (j in 1:6) { 
         phi[j] <- inv.logit(avail_int + sum(availCov[10,j,]*b_avail));          
     } 
     cat("twosigma2: ", twosigma2, "\n"); 
     cat("sigma: ", sqrt(twosigma2/2), "\n"); 
     print(log(twosigma2)); 
     print(twosigma2_int); 
     cat("vysl: ", phi[k] * (exp(-25*25/twosigma2) - 1) * (-twosigma2 /10000), "\n"); 
     cat("vysl: ", phi[k] * (exp(-10000/twosigma2) -exp(-25*25/twosigma2)) * (-twosigma2 / 10000), "\n");
})
twosigma2:  0.2667004

The original model in this case is this:

for (i in 1:sites) {
        log(lambda[i]) <- lambda_int + inprod(b_lambda[], envCov[i,])
        N[i] ~ dpois(lambda[i])

        log(twosigma2[i]) <- twosigma2_int + inprod(b_det[], detCov[i,])

        for (j in 1:visits) {
                logit(phi[i, j]) <- avail_int + inprod(b_avail[], availCov[i,j,])
                Y[i, 2*j - 1] ~ dbinom(phi[i, j] * (exp(-25*25/twosigma2[i]) - 1) * (-twosigma2[i] /10000), N[i])
                Y[i, 2*j] ~ dbinom(phi[i, j] * (exp(-10000/twosigma2[i]) - exp(-25*25/twosigma2[i])) * (-twosigma2[i] / 10000), N[i])
        }
}

Discussion

Anonymous
Anonymous

Add attachments
Cancel