Description Usage Arguments Details Value Note See Also Examples
The database is attached/detached to the search path. See
attach for details.
1 2 3 4 | attach.all(x, overwrite = NA, name = "attach.all")
attach.bugs(x, overwrite = NA)
detach.all(name = "attach.all")
detach.bugs()
|
x |
An object, which must be of class |
overwrite |
If |
name |
The name of the environment where |
While attach.all attaches all elements of an object x to
a database called name, attach.bugs attaches all
elements of x$sims.list to the database bugs.sims itself
making use of attach.all.
detach.all and detach.bugs are removing the databases
mentioned above.
attach.all also attaches n.sims (the
number of simulations saved from the MCMC runs) to the database.
Each scalar parameter in the model is attached as vectors of length
n.sims, each vector is attached as a 2-way array (with first
dimension equal to n.sims), each matrix is attached as a 3-way
array, and so forth.
attach.all and attach.bugs invisibly return the
environment(s).
detach.all and detach.bugs detach the
environment(s) named name created by attach.all.
Without detaching, do not use attach.all or attach.bugs
on another (bugs) object, because instead of the given name, an
object called name is attached. Therefore strange things may
happen ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # An example model file is given in:
model.file <- system.file("model", "schools.txt", package="R2OpenBUGS")
# 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")
## Not run:
## See ?bugs if the following fails:
schools.sim <- bugs(data, inits, parameters, model.file,
n.chains = 3, n.iter = 1000,
working.directory = NULL)
# Do some inferential summaries
attach.bugs(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])
detach.bugs()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.