Learn R Programming

dclone (version 1.7-2)

bugs.fit: Fit BUGS models with cloned data

Description

Convenient functions designed to work well with cloned data arguments and WinBUGS and OpenBUGS.

Usage

bugs.fit(data, params, model, inits = NULL, 
    format = c("mcmc.list", "bugs"), 
    program = c("winbugs", "openbugs"), 
    seed = NULL, ...)
## S3 method for class 'bugs':
as.mcmc.list(x, ...)

Arguments

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 custommodel object (see Examples).
inits
Optional specification of initial values in the form of a list or a function. If NULL, initial values will be generated automatically.
format
Required output format.
program
The program to use, not case sensitive. winbugs calls the function bugs, openbugs calls the function openbugs a
seed
Random seed (bugs.seed argument for bugs, seed argument for openbugs).
x
A fitted 'bugs' object.
...
Further arguments of the bugs function, except for codaPkg are passed also, most notably the ones to set up burn-in, thin, etc. (see Details).

Value

  • 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.

encoding

UTF-8

See Also

Underlying functions: openbugs, bugs Methods: dcsd, confint.mcmc.list.dc, coef.mcmc.list, quantile.mcmc.list, vcov.mcmc.list.dc

Examples

Run this code
## fitting with WinBUGS, bugs example
if (.Platform$OS.type == "windows") {
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")
sim <- bugs.fit(dat, param, bugs.model, inits)
dat2 <- dclone(dat, 2, multiply="J")
sim2 <- bugs.fit(dat2, param, bugs.model)
## fitting the model with OpenBUGS
sim3 <- bugs.fit(dat2, param, bugs.model, program="openbugs", n.thin=1)
## fitting the model with JAGS
sim4 <- jags.fit(dat2, param, bugs.model)
}

Run the code above in your browser using DataLab