0

我有一个关于尝试使用 R2OpenBUGS 使 OpenBUGS322 与 R 一起运行的基本问题。

运行多个试用脚本时(请参阅下面的一个示例),我收到一个错误

矩阵(,n.sims,n.parameters)中的错误:无效的'nrow'值(太大或NA)

通过搜索,我发现其他人使用 OpenBUGS322 和 OpenBUGS321 应该可以正常工作。但是,任何人都可以建议我在哪里可以找到旧版本。我需要 OpenBUGS321setup.exe,但在任何地方都找不到。

(我已经修复了其他几个问题,例如 dbus 配置,当 XQuartz 提示时,OpenBUGS 现在会打开)

这里有更多信息来了解我是否走在正确的道路上。

我正在运行版本:Mac OS X 10.5.8 Wine 1.4.1 XQuartz 2.6.3 OpenBUGS322

WinBUGS 教科书中的试用代码,添加了 WINE 和 OpenBUGS 的路径(不是 100% 确定是否正确)

非常感谢您的帮助。

脚本:

y10<-rnorm(n=10, mean=600, sd=30)
y1000<-rnorm(n=1000, mean=600, sd=30)
summary(lm(y1000~1))
library(R2OpenBUGS)

#setwd("/Users/Pavel/wine/ProgramFiles/OpenBUGS322")
setwd("/Users/Pavel/Documents/R/OpenBUGS")
sink("model.txt")
 cat("
model{
population.mean~dunif(0,5000)
precision<-1/population.variance
population.variance<-population.sd* population.sd
 population.sd~dunif(0,100)
for(i in 1:nobs){
 mass[i]~dnorm(population.mean, precision)
}
}
", fill=TRUE)
 sink()

WINE="/opt/local/bin/wine"
WINEPATH="/opt/local/bin/winepath"
OpenBUGS.pgm="/Users/Pavel/wine/ProgramFiles/OpenBUGS322/OpenBUGS.exe"

#Package the data to be handed to OpenBUGS
win.data<-list(mass=y1000, nobs=length(y1000))

#Function to generate starting values
inits<-function()
list(population.mean=rnorm(1,600), population.sd=runif(1,1,30))

#Parameters to be monitored
params<-c("population.mean", "population.sd", "population.variance")

#MCMC settings
nc<-3     #Number of chains
ni<-1000  #Number of draws for each chain
nb<-1     #number of draws to discard as burn -in
nt<-1     #Thinning rate

out<-bugs(data=win.data, inits=inits, parameters.to.save=params, model.file="model.txt",    n.thin=nt, n.chains=nc, n.burnin=nb, n.iter=ni, OpenBUGS.pgm=OpenBUGS.pgm, WINE=WINE,     WINEPATH=WINEPATH,useWINE=T)
4

1 回答 1

1

你可以rjags改用吗?语法几乎相同:

require(rjags)

modelstring <- "
    model {
        for(i in 1:nobs){
            mass[i] ~ dnorm(m, prec) # precision
        }
        m ~ dunif(0, 5000)
        prec <- 1/sqrt(SD) # convert to Std Deviation
        SD ~ dunif(0, 100)
    }
"
writeLines(modelstring,con="model.txt")

y1000 <- stats::rnorm(n=1000, mean=600, sd=30)

dataList <- list(
    mass = y1000,
    nobs = length(y1000)
    )

initsList <-  list(
    m = stats::rnorm(n=1, mean=600, sd=1),
    SD = stats::runif(n=1, min=1, max=30)
    )

parameters <- c("m","SD") # to be monitored.
adaptSteps <- 100         #  "tune" the samplers.
burnInSteps <- 100        #  "burn-in" the samplers.
nChains <- 3              # Number of chains to run.
numSavedSteps <-2000      # Total number of steps in chains to save.
thinSteps <- 1            # Number of steps to "thin" (1=keep every step).
nPerChain <- ceiling(( numSavedSteps * thinSteps ) / nChains) # Steps per chain

jagsModel <- rjags::jags.model(
    "model.txt", data=dataList,
    inits=initsList, n.chains=nChains,
    n.adapt=adaptSteps)

stats::update(jagsModel, n.iter=burnInSteps)

MCMC1 <- as.matrix(rjags::coda.samples(
    jagsModel, variable.names=parameters,
    n.iter=nPerChain, thin=thinSteps))

SDsample <- matrix(MCMC1[,grep("SD",colnames(MCMC1))],
                ncol=length(grep("SD",colnames(MCMC1))))

然后,您可以转换为方差:

SDsample^2

如果您正在寻找 OpenBUGS321setup.exe,您应该可以在此处找到它。我注意到它在 WINE 下没有经过很好的测试。Linux模拟器有可能吗?

于 2013-02-02T02:25:21.187 回答