2014-11-23 44 views
1

我正在尝试使用R2OpenBUGS库评估来自R的分层模型。BUGS错误:“预计集合运算符c错误pos 13018”

相关变量是:

Ñ = 191,

p = 4,

ķ = 1,

X = N * P矩阵(即191 * 4)的值,

T0 = K *(X” * X),

Ŷ =具有长度为N的连续数据的矢量,

MU0 =的4个零向量(即C(0,0,0,0)),

概率 = 0.5(即C(0.5,0.5,0.5,0.5))的4个概率向量,

indimodel =矢量的4个参数分组(即c(1,2,4,8))。

对于tau和伽马初始值使用下面的函数中的R生成:

inits<-function() 
{ 
    list(tau=runif(1,0,10),gama=c(1,1,1,1)) 
} 

因此,臭虫应该只产生()相关的变量在从inits列表中缺少的初始值。

然而,当我尝试运行了以下错误模型:

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 

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

+0

也许你可以提供一些数据,以便我们可以复制错误。 – gjabel 2014-11-28 08:34:35

回答

0

我发现了这个bug。我错误地指定了t0 [i]这个向量,当时我应该将它指定为矩阵。从R开始,t0被定义为一个矩阵(参见上面变量列表),并且在WinBUGS中,抛出集合错误,因为它期望t0是向量。