teddyao
在R里面调用R2OpenBUGS运行OpenBUGS出错,非常沮丧,请求帮助。
我的dataset里面有三个variable,两个ID和一个分数。可以理解为,ID1给ID2打了个分。ID1和ID2里面都有重复的。在运行之后出现以下的问题,我怀疑我对Model的definition有问题。
出错的Log file里面写:
model is syntactically correct
data loaded
multiple definitions of node b[4580520]
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
整个code都贴出来,如下:
[code lang = 'r']
library(R2OpenBUGS)
# prepare the data (including variables the peergrades and IDs)
data = read.csv("",header=TRUE)
peergrade = data$peergrade
peergrade = (peergrade-mean(peergrade)) # center the scores
author = data$author_id
submission_author = data$submission_author_id
I=length(peergrade)
author_id = unique(data$author_id) # get the unique IDs
K=length(author_id)
submission_author_id = unique(data$submission_author_id)
J=length(submission_author_id)
data = list("K", "J", "I", "peergrade", "author", "submission_author", "author_id", "submission_author_id")
# define the model
model.pg1 <- function(){
for (i in 1:I){
peergrade~dnorm(mu,tau[author])
mu <- t[submission_author]+b[author]
}
for (k in 1:K){
b[author_id[k]]~dnorm(0,0.01)
tau[author_id[k]]~dgamma(1,1)
}
for (j in 1:J){
t[submission_author_id[j]]~dnorm(0,0.01)
}
}
# write the model code out to a file
write.model(model.pg1, "model.pg1.txt")
model.file = paste(getwd(),"model.pg1.txt", sep="/")
# initialization of variables
inits <- function(){
list(b = rnorm(K, 0, 100), t = rnorm(J, 0, 100), tau = rgamma(K,1,1))}
# these are the parameters to save
parameters = c("b", "t","tau")
# run the model
PG1 = bugs(data, inits, model.file = model.file, parameters=parameters, n.chains = 3, n.iter = 50, debug=TRUE)
print(PG1)
[/code]