使用R2winBUGS的非线性分层模型的gen.inits错误

时间:2015-06-24 05:49:59

标签: r hierarchical-data bayesian r2winbugs non-linear-regression

我对贝叶斯统计数据相对较新,并尝试在某些树木放养密度数据上使用R2winBUGS应用非线性层次模型。我希望有人能帮我找到R2winBUGS给我以下错误的原因:

gen.inits无法执行(灰显)

即使我收到此错误,代码仍然会产生输出。对于收敛的参数,模型产生看似合理的输出但是当我使用两个链时,有两个参数(下面代码中的mean_N0 sigma_N0)不能很好地混合(不收敛)。链似乎从初始值开始(即mean_N0从4800.5和4799.5开始,而sigma_N0从800.5和799.5开始),但不要远离这些值。两个参数的平均值与初始设定值相差约0.5。我不确定上述错误是否导致了这种收敛问题 我已经用尽了对这个问题的调查,现在我希望有人能够在下面的winBUGS或R代码中看到导致我问题的原因。如果你能提供帮助,我将非常感谢你的时间。 亲切的问候 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/")

我也试过使用以下格式:

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
   ) 
}

请注意,第一个和第二个是相同的,下面我将向您展示第二个列表的外观。再次感谢您抽出时间寻求帮助。

[[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 个答案:

没有答案