# NOT RUN {
##from ?jags example in R2jags package
# }
# NOT RUN {
require(R2jags)
model.file <- system.file(package="R2jags", "model", "schools.txt")
file.show(model.file)
##data
J <- 8.0
y <- c(28.4,7.9,-2.8,6.8,-0.6,0.6,18.0,12.2)
sd <- c(14.9,10.2,16.3,11.0,9.4,11.4,10.4,17.6)
jags.data <- list (J = J, y = y, sd = sd)
jags.inits <- function(){
list(theta=rnorm(J, 0, 100), mu=rnorm(1, 0, 100),
sigma=runif(1, 0, 100))
}
jags.parameters <- c("theta", "mu", "sigma")
##run model
schools.sim <- jags(data = jags.data, inits = jags.inits,
parameters = jags.parameters,
model.file = model.file,
n.chains = 3, n.iter = 10)
#note that n.iter should be higher
##set up in list
Cand.mods <- list(schools.sim)
Model.names <- "hierarchical model"
##other models can be added to Cand.mods
##to compare them to the top model
##model selection table
dictab(cand.set = Cand.mods, modnames = Model.names)
detach(package:R2jags)
# }
Run the code above in your browser using DataLab