# NOT RUN {
data(schools)
J <- nrow(schools)
y <- schools$estimate
y <- rnorm(length(y))
sigma.y <- schools$sd
schools.data <- list ("J", "y", "sigma.y")
## schools.data <- list(J=J, y=y, sigma.y=sigma.y)
inits <- function() {list (theta=rnorm(J,0,100),
mu.theta=rnorm(1,0,100),
sigma.theta=runif(1,0,100))}
parameters <- c("theta", "mu.theta", "sigma.theta")
schools.bug <- system.file("bugs/model/schools.bug", package="rbugs")
file.show(schools.bug)
# }
# NOT RUN {
## no tested examples for mac-os.
schools.sim <- rbugs(data=schools.data, inits, parameters,
schools.bug, n.chains=3, n.iter=1000,
bugs="/usr/bin/OpenBUGS",
bugsWorkingDir="~/tmp/")
## generate files only
schools.sim <- rbugs(data=schools.data, inits, parameters,
schools.bug, n.chains=3, n.iter=1000,
bugsWorkingDir="~/tmp/",
OpenBugs=TRUE, genFilesOnly=TRUE)
## MCMC analysis
library("coda")
schools.mcmc <- rbugs2coda(schools.sim)
summary(schools.mcmc)
effectiveSize(schools.mcmc)
gelman.diag(schools.mcmc)
## Windows using WinBugs
schools.sim <- rbugs(data=schools.data, inits, parameters,
schools.bug, n.chains=3, n.iter=1000,
bugs="C:/Program Files/WinBUGS14/WinBUGS14.exe",
bugsWorkingDir="C:/temp/",
OpenBugs = FALSE)
## Windows using OpenBUGS
schools.sim <- rbugs(data=schools.data, inits, parameters,
schools.bug, n.chains=3, n.iter=1000,
bugs="C:/Program Files/OpenBugs321/OpenBugs.exe",
bugsWorkingDir="C:/temp/",
OpenBugs=TRUE)
##MCMC analysis
library("coda")
schools.mcmc <- rbugs2coda(schools.sim)
summary(schools.mcmc)
effectiveSize(schools.mcmc)
gelman.diag(schools.mcmc)
# }
Run the code above in your browser using DataLab