Hi all,
I am dealing with missing values, and follow the instructions in the user manual, simple regressions can be done successfully. But when I do something more complex, I get some errors. For example, here's a Nimble code:
thinData <- list(y=slope,x1=forest,x2=herb,x3=method,SE2=SE2,n=n) # only "n" has missing values
thinConst <- list(N=N)
thinInits <- list(mu_y=1,var_tau=1,beta=c(1,1,1))
thinCode <- nimbleCode({
for (i in 1:N){
y[i] ~ dnorm(mu_y, var_y[i])
var_y[i] <- var_tau + var_epsilon[i]
a[i] <- (n[i]-1)/2
b[i] <- n[i]*(n[i]-1)/(2*var_epsilon[i])
SE2[i] ~ dgamma(a[i],b[i])
var_epsilon[i] ~ dinvgamma(0.001,0.001)
n[i] ~ dpois(lam[i])
log(lam[i]) <- beta[1]+beta[2]*x1[i]+beta[3]*x2[i]+beta[3]*x3[i]
}
mu_y ~ dnorm(0,0.001)
var_tau ~ dinvgamma(0.001,0.001)
beta[1:3] ~ dnorm(0,0.001)
})
When I run the code by:
mcmc.out <- nimbleMCMC(code=thinCode,constants=thinConst,data=thinData,inits=thinInits,nchains=2, niter=10000,summary=TRUE,WAIC=TRUE)
I get message:
"NAs were detected in model variables: var_epsilon, logProb_var_epsilon, var_y, lifted_d1_over_sqrt_oPvar_y_oBi_cB_cP_L2, n, logProb_n, logProb_y, b, a, lifted_d1_over_b_oBi_cB_L6, logProb_SE2.";
warnings like:
"warning: problem initializing stochastic node var_epsilon[1], logProb is NA or NaN";
and get an error message:
"Error in quantile.default(x, 0.025) :
missing values and NaN's not allowed if 'na.rm' is FALSE"
Could you please help me with that? How I can deal with the NA values and get rid of the error message?
Thank you so much!
Best,
Cindy