### Example for running BUGS through R setwd("j:/RbugsExample") library(lme4) library(Matrix) library(R2WinBUGS) library(BRugs) setwd("j:/RbugsExample") schools <- read.table ("schools.dat", header=T) J <- nrow(schools) y <- schools$estimate sigma.y <- schools$sd data <- list ("J", "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.sim <- bugs (data, inits, parameters, "schools.bug", n.chains=3, n.iter=1000) schools.sim <- bugs (data, inits, parameters, "schools.bug", n.chains=3, n.iter=1000, debug=T) print (schools.sim) plot (schools.sim) schools.sim$summary #info that was printed using print() command attach.bugs(schools.sim) #The simulated parameter values are now saved in R as: #"theta": a 1500 x 8 matrix, representing 1500 simulations of the vector theta #"mu.theta": a vector of length 1500 of simulations of mu.theta #"sigma.theta": a vector of length 1500 of simulations of sigma.theta. help(bugs)