我正在尝试使用 R2OpenBUGS 库从 R 评估分层模型。
相关变量是:
N = 191,
p = 4,
k = 1,
x = N * p 矩阵(即 191 * 4)的值,
t0 = k * (x' * x),
y = 长度为 N 的连续数据向量,
mu0 = 4 个零的向量(即 c(0,0,0,0)),
prob = 0.5 处 4 个概率的向量(即 c(0.5,0.5,0.5,0.5)),
indimodel = 4 个参数分组的向量(即 c(1,2,4,8))。
tau 和 gama 的初始值是使用 R 中的以下函数生成的:
inits<-function()
{
list(tau=runif(1,0,10),gama=c(1,1,1,1))
}
因此,BUGS 应该只为 inits() 列表中缺失的相关变量生成初始值。
但是,当我尝试运行以下 BUGS 模型时:
model
{
for (i in 1:N)
{
mu[i]<-inprod(x[i,],nu[])
y[i]~dnorm(mu[i],tau)
}
for (i in 1:p)
{
gama[i]~dbern(prob[i])
nu[i]<-beta[i]*gama[i]
}
for (i in 1:p)
{
beta[i]~dnorm(mu0[i],t0[i])
}
tau~dgamma(0.00001,0.00001)
model<-inprod(gama[],indimodel[])
sigma<-sqrt(1/tau)
}
...我收到以下错误:
“预计集合运算符 c 错误 pos 13018” “未定义变量 N”
...在日志中描述为:
model is syntactically correct
expected the collection operator c error pos 13018
variable N is not defined
model must have been compiled but not updated to be able to change RN generator
BugsCmds:NoCompileInits
model must be compiled before generating initial values
model must be initialized before updating
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before monitors used
model must be initialized before DIC can be monitored
model must be initialized before updating
model must be initialized before monitors used
DIC monitor not set
我有一种感觉,这个问题源于缺少对某些变量(或变量)初始值的声明。