as.mcmc.list.bkmrfit.list: Convert multi-chain bkmrfit to mcmc.list for coda MCMC...

View source: R/coda_funs.R

as.mcmc.list.bkmrfit.listR Documentation

Convert multi-chain bkmrfit to mcmc.list for coda MCMC diagnostics

Description

Converts a kmrfit.list (from the bkmrhat package) into an mcmc.list object from the coda package.The coda package enables many different types of MCMC diagnostics, including geweke.diag, traceplot and effectiveSize. Posterior summarization is also available, such as HPDinterval and summary.mcmc. Using multiple chains is necessary for certain MCMC diagnostics, such as gelman.diag, and gelman.plot.

Usage

## S3 method for class 'list.bkmrfit.list'
as.mcmc(x, ...)

Arguments

x

object of type kmrfit.list (from bkmrhat package)

...

arguments to as.mcmc.bkmrfit

Value

An mcmc.list object

Examples

# following example from https://jenfb.github.io/bkmr/overview.html
 
set.seed(111)
library(coda)
dat <- bkmr::SimData(n = 50, M = 4)
y <- dat$y
Z <- dat$Z
X <- dat$X
set.seed(111)

future::plan(strategy = future::multisession, workers=2)
# run 2 parallel Markov chains (more usually better)
fitkm.list <- kmbayes_parallel(nchains=2, y = y, Z = Z, X = X, iter = 1000,
  verbose = FALSE, varsel = FALSE)
mcmcobj = as.mcmc.list(fitkm.list)
summary(mcmcobj)
# Gelman/Rubin diagnostics won't work on certain objects,
# like delta parameters (when using variable selection),
# so the rstan version of this will work better (does not give errors)
 try(gelman.diag(mcmcobj))
# lots of functions in the coda package to use
plot(mcmcobj)
# both of these will also fail with delta functions (when using variable selection)
try(gelman.plot(mcmcobj))
try(geweke.plot(mcmcobj))

closeAllConnections()


bkmrhat documentation built on March 29, 2022, 9:08 a.m.