I am trying to evaluate hierarchical models from R using the R2OpenBUGS library.
Relevant variables are:
N = 191,
p = 4,
k = 1,
x = N * p matrix (i.e. 191 * 4) of values,
t0 = k * (x' * x),
y = vector of continuous data with length N,
mu0 = vector of 4 zeros (i.e. c(0,0,0,0)),
prob = vector of 4 probabilities at 0.5 (i.e. c(0.5,0.5,0.5,0.5)),
indimodel = vector of 4 parameter groupings (i.e. c(1,2,4,8)).
Initial values for tau and gama are generated using the following function in R:
inits<-function()
{
list(tau=runif(1,0,10),gama=c(1,1,1,1))
}
Thus, BUGS should just generate initial values for relevant variables missing from the list in inits().
However, when I attempt to run the following BUGS model:
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)
}
...I get the following error:
"expected the collection operator c error pos 13018" "variable N is not defined"
...described in the log as:
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
I have a feeling that this issue stems from a missing declaration for some variable's (or variables') initial value(s).
I found the bug. I mistakenly specified t0[i] the vector, when I should have specified it as a matrix. From R, t0 is defined as a matrix (see list of variables above), and in WinBUGS the collection error is thrown because it expects t0 the vector.