as.mcmc.bkmrfit {bkmrhat}R Documentation

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 class 'bkmrfit'
as.mcmc(x, iterstart = 1, thin = 1, ...)

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

Value

An mcmc object

Examples


# following example from https://jenfb.github.io/bkmr/overview.html
 
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))


[Package bkmrhat version 1.1.3 Index]