我在R中运行R2WinBUGS时遇到错误。这是重现性的代码。
#Set working directory
setwd("H://AChaudhuri/Testing/CSVS")
matrix=NULL
csvs <- paste("MVN", 1:2, ".csv", sep="")
for(i in 1:length(csvs)){
matrix[[i]] <- read.csv(file=csvs[i], header=T)
print(matrix[[i]])
}
所以现在我已经阅读了两个看起来像
的模拟数据集 Y1 Y2
1 11 6
2 8 5
3 25 13
4 1 13
5 8 22
Y1 Y2
1 9 1
2 7 9
3 25 13
4 1 18
5 9 12
我的下一步是在这些数据集上运行多变量logit正态模型 并为此类模拟数据集自动执行此过程。这是模特 声明:
model
{
for (j in 1 : Nf)
{
p1[j, 1:2 ] ~ dmnorm(gamma[1:2 ], T[1:2 ,1:2 ])
for (i in 1:2)
{
logit(p[j,i])<-p1[j,i]
Y[j,i] ~ dbin(p[j,i],n)
}}
我正在尝试使用以下代码在R2WinBUGS中运行它
bugs.output <- list()
for(i in 1:2){
Y <-(matrix[i])
bugs.output[[i]] <- bugs(
data=list(Y=Y, Nf=5), # change for no of sites
inits=NULL,
model.file="M-LN_model_trial.txt",
parameters.to.save = c("p","rho","sigma2"),
n.chains=1, n.iter=12000, n.burnin=5000,
bugs.directory="H://AChaudhuri/winbugs14/WinBUGS14",
working.directory=NULL)}
Error in FUN(X[[1L]], ...) :
.C(..): 'type' must be "real" for this format
> traceback()
6: .C("str_signif", x = x, n = n, mode = as.character(mode), width = as.integer(width),
digits = as.integer(digits), format = as.character(format),
flag = as.character(flag), result = blank.chars(i.strlen),
PACKAGE = "base")
5: FUN(X[[1L]], ...)
4: lapply(data, formatC, digits = digits, format = "E")
3: write.datafile(lapply(data, formatC, digits = digits, format = "E"),
file.path(dir, data.file))
2: bugs.data(data, dir = getwd(), digits)
1: bugs(data = list(Y = Y, Nf = 5), model.file = "M-LN_model_trial.txt",
parameters.to.save = c("p", "rho", "sigma2"), n.chains = 1,
n.iter = 12000, n.burnin = 5000, bugs.directory = "C://Tina/USB_Backup_042213 /winbugs14/WinBUGS14",
working.directory = NULL)
任何建议都会有所帮助。 谢谢!
答案 0 :(得分:1)
我有同样的错误。在我的情况下,问题是Y是真/假而不是0/1格式。