I asked this question on https://stackoverflow.com/, but I couldn't get what I want. So, I am asking it here.
I am running winbugs from R and I need to use some variables in R output. When I type schools.sim\$mean\$theta[1]
in R, I get 10.2. However, when I type schools.sim\$2.5%\$theta[1]
an error message come up. Any one what I am doing wrong or any other way to get the bayesian intervals?
here is an example:
This is the R code
library(R2WinBUGS)
data(schools)
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))
}
schools.sim <- bugs(data, inits, model.file = "D:/model.txt",
parameters = c("theta", "mu.theta", "sigma.theta"),
n.chains = 3, n.iter = 1000,
bugs.directory = "D:/PROGRAMLAR/WinBUGS14/")
schools.sim
and this is the winbugs code which must be stored as model.txt in D.
model {
for (j in 1:J)
{
y[j] ~ dnorm (theta[j], tau.y[j])
theta[j] ~ dnorm (mu.theta, tau.theta)
tau.y[j] <- pow(sigma.y[j], -2)
}
mu.theta ~ dnorm (0.0, 1.0E-6)
tau.theta <- pow(sigma.theta, -2)
sigma.theta ~ dunif (0, 1000)
}