Learn R Programming

bkmrhat (version 1.1.7)

as.mcmc.bkmrfit: Convert bkmrfit to mcmc object for coda MCMC diagnostics

Description

Converts a kmrfit (from the bkmr package) into an mcmc object from the coda package. The coda package enables many different types of single chain MCMC diagnostics, including geweke.diag, traceplot and effectiveSize. Posterior summarization is also available, such as HPDinterval and summary.mcmc.

Usage

# S3 method for bkmrfit
as.mcmc(x, iterstart = 1, thin = 1, ...)

Value

An mcmc object

Arguments

x

object of type kmrfit (from bkmr package)

iterstart

first iteration to use (e.g. for implementing burnin)

thin

keep 1/thin % of the total iterations (at regular intervals)

...

unused

Examples

Run this code

# following example from https://jenfb.github.io/bkmr/overview.html
 # \donttest{
set.seed(111)
library(coda)
library(bkmr)
dat <- bkmr::SimData(n = 50, M = 4)
y <- dat$y
Z <- dat$Z
X <- dat$X
set.seed(111)
fitkm <- kmbayes(y = y, Z = Z, X = X, iter = 500, verbose = FALSE,
  varsel = FALSE)
mcmcobj <- as.mcmc(fitkm, iterstart=251)
summary(mcmcobj) # posterior summaries of model parameters
# compare with default from bkmr package, which omits first 1/2 of chain
summary(fitkm)
# note this only works on multiple chains (see kmbayes_parallel)
# gelman.diag(mcmcobj)
# lots of functions in the coda package to use
traceplot(mcmcobj)
# will also fail with delta functions (when using variable selection)
try(geweke.plot(mcmcobj))
# }

Run the code above in your browser using DataLab