我正在尝试使用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)),
概率 = 0.5的4个概率向量(即c(0.5,0.5,0.5,0.5)),
indimodel = 4个参数分组的向量(即c(1,2,4,8))。
使用R中的以下函数生成tau和gama的初始值:
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)
}
...我收到以下错误:
&#34;期望收集运算符c错误pos 13018&#34; &#34;变量N未定义&#34;
...在日志中描述为:
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
我觉得这个问题源于某些变量(或变量&#39;)初始值的缺失声明。
答案 0 :(得分:0)
我发现了这个错误。当我将它指定为矩阵时,我错误地指定了 t0 [i] 向量。从R开始, t0 被定义为矩阵(参见上面的变量列表),并且在WinBUGS中抛出了集合错误,因为它期望t0为向量。