大家好我是JAGS的新手,目前正在使用mcmc通过RJAGS进行贝叶斯推理。我一直在努力调试我的代码,直到我遇到这个错误“节点e1中的错误[3]节点与父母不一致”。
e1<-c(1,1,0,1,1,0,0,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,0,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,0,0,1,1,1,1,0,1)
e2<-c(1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,0,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,1,0,1,1,1,1,1)
c1<-c(2412,3485,881,1515,1824,1603,865,2638,332013,7379,1,1189,1,106,278,1406,9408,21596,15880,833,543,611,272,7883,
1,15091,11642,849,203,566,425,1,125124,687196,21377,3901,1131,543,1,21218,1118,5519,434800,1288,4700,820,659,6644,
1198,3581,1013,1021,5877,833,1,11797)
c2<-c(1189,905,902,1154,20896,14973,1665,1,1096,309,641,1,935,282,
1,566,2245,112,18366,1096,1476,1,2486,1131,607,67,19390,284,
641,566,1154,1,2672,4857,1131,1231,4594,655,1127,4187,1223,417,
3381,1,1006,1,1920,4964,1911,765 ,876,14,942,849,4130)
n<-c(56,55)
model<-function() {
#control
for(i in 1:n[1]){
e1[i] ~ dbern(p1[i])
c1[i] ~ dlnorm(eta[1],lambda[1])
p1[i] <- ilogit(alpha[1]+beta[1]*c1[i])
}
#treatment
for(i in 1:n[2]){
e2[i] ~ dbern(p2[i])
c2[i] ~ dlnorm(eta[2],lambda[2])
p2[i] <- ilogit(alpha[2]+beta[2]*c2[i])
}
for (t in 1:2) {
eta[t] ~ dgamma(9,2)
lambda[t] ~ dunif(0,100)
alpha[t] ~ dnorm(0,1)
beta[t] ~ ddexp(0, gamma)
}
gamma ~ dunif(1,10)
}
library(R2jags)
dataJags <- list("n","c1","c2","e1","e2")
params <- c("eta","lambda","alpha","beta")
inits <- function(){
list(eta=runif(2,0,1),lambda=runif(2,0,1),alpha=runif(2,0,1),beta=runif(2,0,1)
)
}
n.iter <- 10000
n.burnin <- 5000
n.thin <- floor((n.iter-n.burnin)/500)
flxpin <- jags(dataJags, inits, params, model.file=model,
n.chains=3, n.iter, n.burnin, n.thin,
DIC=TRUE, progress.bar="text")
我希望有人能给我如何调试这个。非常感谢。