I am writing a program in R which uses R2OpenBUGS. The code is given at the bottom. The following error is coming while running it-
model is syntactically correct
data loaded
expected multivariate node
model must have been compiled but not updated to be able to change RN generator
BugsCmds:NoCompileInits
BugsCmds:NoCompileInits
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 DIC can be monitored
model must be initialized before updating
model must be initialized before monitors used
DIC monitor not set
Please help me out to correct the code-
The following is the OpenBUGS code.
## BUGS Model
model {
# model for joint distribution of nuhat
nuhat[1:m]~dmnorm(mean[], B[,])
for(i in 1:m){
mean[i]<-mu
}
B[1:m,1:m]<-SIGMA[1:m,1:m]+tau2*inverse(C[1:m,1:m])
C[1:m,1:m]<-DW[1:m,1:m]-rho*W[1:m,1:m]
# priors on parameters
mu~dunif(-5,5)
rho~dunif (-1,1)
tau2~dunif (0, 1000)
}
## Data
list(m=5, nuhat=c(-0.228352281,-0.290119586,-0.211553228,-0.252395328,-0.263358489),
SIGMA=structure(.Data=c( 1.451677,0,0,0,0,
0,1.578091,0,0,0,
0,0,1.386538,0,0,
0,0,0,1.484578,0,
0,0,0,0,1.500409), .Dim=c(5,5)),
DW=structure(.Data=c(2,0,0,0,0,
0,2,0,0,0,
0,0,3,0,0,
0,0,0,2,0,
0,0,0,0,1), .Dim=c(5,5)),
W=structure(.Data=c(0,1,1,0,0,
1,0,0,1,0,
1,0,0,1,1,
0,1,1,0,0,
0,0,1,0,0), .Dim=c(5,5)))
## Inits
list(mu=-1,tau2=1,rho=0.5)
OpenBUGS does not let you assign matrices for deterministic nodes in the same way it does for random nodes. For example (forgetting for the moment what
B
,SIGMA
andDW
in your model actually are)...,is okay, but
does not seem to work. Instead you have to create a loops to assign each element of the matrix, e.g.
The
inverse
transformation in your code (which is part of the calculation ofB
) cannot not be done element wise, so this has to go outside any loops assigning values to deterministic matrix elements.With both these rules in mind, your model will work if you re-express as: