Learn R Programming

R2WinBUGS (version 0.2-7)

attach.all: Attach / detach elements of a bugs objects to search path

Description

The database is attached to the Rsearch path. See attach for details.

Usage

attach.all(.a, overwrite = FALSE)
    detach.all()

Arguments

.a
A bugs object
overwrite
If TRUE, overwrites variables if necessary. (The usual "attach" function in R only attaches the variables that are not yet defined.)

Value

  • attach.all invisibly returns the environment. detach.all detaches the environment named .a created by attach.all.

See Also

bugs, attach, detach

Examples

Run this code
# An example model file is given in:
model.file <- file.path(.path.package("R2WinBUGS"), "model", "schools.txt")
# Some example data (see ?schools for details):
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))
}
parameters <- c("theta", "mu.theta", "sigma.theta")      
## You may need to edit "bugs.directory",
## also you need write access in the working directory:
schools.sim <- bugs(data, inits, parameters, model.file, 
    n.chains = 3, n.iter = 1000, 
    bugs.directory = "c:/Program Files/WinBUGS14/",
    working.directory = NULL)

# Do some inferential summaries
attach.all(schools.sim)
# posterior probability that the coaching program in school A 
# is better than in school C:
print(mean(theta[,1] > theta[,3]))
# 50# and school C's program:
print(quantile(theta[,1] - theta[,3], c(.25, .75)))  
plot(theta[,1], theta[,3])

Run the code above in your browser using DataLab