bugs.fit | R Documentation |
Convenient functions designed to work well with cloned data arguments and WinBUGS and OpenBUGS.
bugs.fit(data, params, model, inits = NULL, n.chains = 3,
format = c("mcmc.list", "bugs"),
program = c("winbugs", "openbugs", "brugs"),
seed, ...)
## S3 method for class 'bugs'
as.mcmc.list(x, ...)
data |
A list (or environment) containing the data. |
params |
Character vector of parameters to be sampled. |
model |
Character string (name of the model file), a function containing
the model, or a |
inits |
Optional specification of initial values in the
form of a list or a function.
If |
n.chains |
number of Markov chains. |
format |
Required output format. |
program |
The program to use, not case sensitive.
|
seed |
Random seed ( |
x |
A fitted 'bugs' object. |
... |
Further arguments of the |
By default, an mcmc.list
object. If data cloning is used via the
data
argument, summary
returns a modified summary
containing scaled data cloning standard errors
(scaled by sqrt(n.clones)
), and
R_{hat}
values (as returned by gelman.diag
).
bugs.fit
can return a bugs
object if
format = "bugs"
.
In this case, summary is not changed, but the number of clones
used is attached as attribute
and can be retrieved by the function nclones
.
The function as.mcmc.list.bugs
converts a 'bugs' object
into 'mcmc.list' and retrieves
data cloning information as well.
Peter Solymos
Underlying functions:
bugs
in package R2WinBUGS,
openbugs
in package R2WinBUGS,
bugs
in package R2OpenBUGS
Methods: dcsd
, confint.mcmc.list.dc
,
coef.mcmc.list
, quantile.mcmc.list
,
vcov.mcmc.list.dc
## Not run:
## fitting with WinBUGS, bugs example
if (require(R2WinBUGS)) {
data(schools)
dat <- list(J = nrow(schools),
y = schools$estimate,
sigma.y = schools$sd)
bugs.model <- function(){
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)
}
inits <- function(){
list(theta=rnorm(nrow(schools), 0, 100), mu.theta=rnorm(1, 0, 100),
sigma.theta=runif(1, 0, 100))
}
param <- c("mu.theta", "sigma.theta")
if (.Platform$OS.type == "windows") {
sim <- bugs.fit(dat, param, bugs.model, inits)
summary(sim)
}
dat2 <- dclone(dat, 2, multiply="J")
if (.Platform$OS.type == "windows") {
sim2 <- bugs.fit(dat2, param, bugs.model,
program="winbugs", n.iter=2000, n.thin=1)
summary(sim2)
}
}
if (require(BRugs)) {
## fitting the model with OpenBUGS
## using the less preferred BRugs interface
sim3 <- bugs.fit(dat2, param, bugs.model,
program="brugs", n.iter=2000, n.thin=1)
summary(sim3)
}
if (require(R2OpenBUGS)) {
## fitting the model with OpenBUGS
## using the preferred R2OpenBUGS interface
sim4 <- bugs.fit(dat2, param, bugs.model,
program="openbugs", n.iter=2000, n.thin=1)
summary(sim4)
}
if (require(rjags)) {
## fitting the model with JAGS
sim5 <- jags.fit(dat2, param, bugs.model)
summary(sim5)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.