我想构建一个像
这样的模型Model3 <- function() {
# Likelihood of the model
for (i in 1:n) {
response2[i] ~ dbern(p[i])
logit(p[i]) <- m[i]
m[i] <- mfe[i]
mfe[i] <- beta[1] + f[i]
# the f functions or the if-else step like
f_branch[i, 2] <- alpha
f_branch[i, 1] <- 1+alpha*exp(-((1/phi)*X2[i,1])^2)
# the decision
if_branch[i] <- 1 + step(-(X2[i,1] - 2))
f[i] <- f_branch[i, if_branch[i]]
f[i] <- f_branch[i, if_branch[i]]
}
# Prediction step
for(ii in 1:ndist) {
if_branch2[ii] <- 1 + step(-(Dist[ii] - 2))
fhat[ii] <- f_branch2[ii, if_branch2[ii]]
fhat[ii] <- f_branch2[ii, if_branch2[ii]]
f_branch2[ii, 2] <- alpha
f_branch2[ii, 1] <- 1 + alpha*exp(-((1/phi)*Dist[ii])^2)
}
# Prior distribution of the fixed effects parameters
beta[1] ~ dnorm(0, 1.0E-6)}
# priors for the f function
alpha ~ dgamma(1, 1)
phi ~ dunif(0, 2)
}
我收到错误:Attempt to redefine node f[1]
答案 0 :(得分:0)
在这种情况下,错误消息非常明显 - 您定义f[1]
,然后在下一行再次定义它,因为您重复了这一行:
f[i] <- f_branch[i, if_branch[i]]
删除该行的第二个实例,该错误应该消失。
您还复制了该行:
fhat[ii] <- f_branch2[ii, if_branch2[ii]]
所以你也需要删除它的第二个实例。