Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as.mcmc.list.bkmrfit.list

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)
Sys.setenv(R_FUTURE_SUPPORTSMULTICORE_UNSTABLE="quiet")
future::plan(strategy = future::multiprocess, 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

Parallel Chain Tools for Bayesian Kernel Machine Regression

v1.0.2
GPL (>= 3)
Authors
Alexander Keil [aut, cre]
Initial release
2021-02-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.