r语言 - 错误错误:"expected the collection operator c error pos 13018"



我正在尝试使用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

我有一种感觉,这个问题源于缺少某些变量(或变量)初始值的声明。

我发现了这个错误。我错误地指定了 t0[i] 向量,而我应该将其指定为矩阵。从 R 开始,t0 被定义为矩阵(请参阅上面的变量列表),而在 WinBUGS 中,会引发集合错误,因为它需要 t0 作为向量。

相关内容

最新更新