gen.inits error for non-linear hierarchical model using R2winBUGS

159 views Asked by At

I am relatively new to Bayesian statistics and am trying to apply a non-linear hierarchical model using R2winBUGS on some tree stocking density data. I am hoping someone may be able to help me find the reason why R2winBUGS is giving me the following error:

gen.inits cannot be executed (is greyed out)

Even though I get this error, the code still produces output. For parameters that converge, the model produces output that seem reasonable but there are two parameters (mean_N0 sigma_N0 in below code) that are not mixing well (not converging) when I use two chains. The chains seem to start around the initial value (i.e. mean_N0 starts at 4800.5 and 4799.5, whereas sigma_N0 starts at 800.5 and 799.5) but don’t move far from those values. The mean values for both parameters are about 0.5 off from the initial set values. I am not sure whether the above error is causing this convergence problem.
I have exhausted my investigations into this problem and am now hoping someone may be able to see what is causing my problem in the below winBUGS or R code. I would greatly appreciate your time if you could help. Kind Regards Dom

WINBUGS CODE

model {
## loop over data for likelihood 
for(i in 1:Ntotal){
  N[i] <- log(N0[P_ID_Bug[i]] - 25)-(Age[i]/(Beta_0 + Beta_1*Age[i]))  
  Y[i] ~ dnorm(N[i],tauY)
}
tauY ~ dgamma(1.0E-3, 1.0E-3)
Beta_0 ~ dnorm(9,0.25)
Beta_1 ~ dnorm(0.16,400)

## hierarchical model for each Plots intercept & slope
for (p in 1:P_ID_Length) {
    N0[p] ~ dgamma(r_N0, lambda_N0)
} 
mean_N0 ~ dnorm(5000,1.0E-6)
sigma_N0 ~ dnorm(5000,0.25E-6)
lambda_N0 <- mean_N0/(sigma_N0*sigma_N0)
r_N0 <- mean_N0 * lambda_N0
}

R CODE

data <- list(P_ID_Length = length(P_ID),
         P_ID_Bug = P_ID_Bug,
         Age=Grouped_SDen$Age, 
         Y =Grouped_SDen$LogSDen_Ha,   
         Ntotal=nrow(Grouped_SDen))

inits1 <- list(N0= rep(coef(NLS_SDen_Log_1)[[1]], P_ID_Length), 
 Beta_0 = coef(NLS_SDen_Log_1)[[2]], 
 Beta_1 = coef(NLS_SDen_Log_1)[[3]],
 tauY = 20,
 mean_N0 = 4800,
 sigma_N0 = 800
)

inits2 <- list(N0= rep(coef(NLS_SDen_Log_1)[[1]], P_ID_Length), 
 Beta_0 = coef(NLS_SDen_Log_1)[[2]], 
 Beta_1 = coef(NLS_SDen_Log_1)[[3]],
 tauY = 20,
 mean_N0 = 4800,
 sigma_N0 = 800
 )
inits <- list(inits1, inits2)
parameters <- c("N0", "Beta_0", "Beta_1", "tauY", "mean_N0", "sigma_N0")
sims <- bugs(model.file= "C:/WS/Post-Doc/TINNR/PAPER_4_WinBugs/Stocking_Growth.bug",
         data = data,
         parameters = parameters,
         inits = inits,
         n.chains = 2,
         n.iter = 1000, 
         n.burnin = 500, 
         n.thin = 2,
         debug=TRUE,
         bugs.directory = "C:/Program Files/WinBUGS14/")

I have also tried using the following format for inits:

inits <- function(){
  list(N0= rep(coef(NLS_SDen_Log_1)[[1]], P_ID_Length), 
   Beta_0 = coef(NLS_SDen_Log_1)[[2]], 
   tauY = 1,
   mean_N0 = 4800,
   sigma_N0 = 800
   ) 
}

Note that the first and second inits are the same and below I show you what the second list looks like. Thanks again for finding the time to help.

[[2]]
[[2]]$N0
  [1] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [13] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [25] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [37] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [49] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [61] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [73] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [85] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531
 [97] 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531 4920.531

[[2]]$Beta_0
[1] 8.710965

[[2]]$Beta_1
[1] 0.1623536

[[2]]$tauY
[1] 20

[[2]]$mean_N0
[1] 4800

[[2]]$sigma_N0
[1] 800
0

There are 0 answers