`bkmrhat` v1.1.2

Diagnostics and multi-chain tools with Bayesian kernel machine regression (bkmr)

Bayesian kernel machine regression (BKMR) is a semi-parametric approach to Bayesian GLMs. The `bkmr` package implements BKMR under identity and probit links, but does not implement standard Bayesian diagnostics or interface with R packages that can do these diagnostics, nor does it allow easy implementation of parallel chains, which is one of the easiest ways to speed up Markov chain Monte Carlo on modern computers. This package fixes those problems.

Note that this package functions best using the development verision of the bkmr package (instructions here)

# Quick start

#### install

``````install.packages("devtools")
devtools::install_github("alexpkeil1/bkmrhat", build_vignettes = TRUE)``````

#### simulate data from a `bkmr` package function

``````set.seed(111)
library(coda)
library(bkmr)
library(bkmrhat)
dat <- bkmr::SimData(n = 50, M = 4)
y <- dat\$y
Z <- dat\$Z
X <- dat\$X
set.seed(111)``````

#### fit BKMR model via four parallel MCMC chains (10,000 iterations total)

``````future::plan(strategy = future::multisession)
# run 4 parallel Markov chains
fitkm.list <- kmbayes_parallel(nchains=4, y = y, Z = Z, X = X, iter = 2500,
verbose = FALSE, varsel = TRUE)``````

#### run diagnostics from `rstan` package

``````# rstan has a few excellent diagnostics (modern r-hat and effective sample size)
diagres = kmbayes_diag(fitkm.list)
# estimate of standard error (gives margin of error for reporting estimates)
diagres[,"se_mean"]``````

#### convert to `coda` package object for other diagnostics

``````mcmcobj = as.mcmc.list(fitkm.list)
# lots of functions in the coda package to use
# get info on rejection probabilities (from h() function in bkmr - won't be correct for discrete parameters like delta parameters)
rejectionRate(mcmcobj)
# check trace plots for obvious issues between/within chains
plot(mcmcobj)
# autocorrelation for efficiency issues
acfplot(mcmcobj)
# posterior correlation for
crosscorr(mcmcobj)
# Gelman/Rubin diagnostics for convergence (multivariate may fail when including delta functions from variable selection)
try(gelman.diag(mcmcobj, multivariate = FALSE))
# batch standard error: a different approach to estimating standard error
batchSE(kmres)
# effective size, another way to assess whether enough samples have been made (I prefer the `rstan` implementations)
effectiveSize(mcmcobj)
try(geweke.diag(mcmcobj))
# posterior summary
summary(mcmcobj)
# HPD intervals by chain
HPDinterval(mcmcobj)
``````

#### combine chains and use `bkmr` native posterior functions

``````combobj = comb_bkmrfits(fitkm.list)
combobj\$iter
summary(combobj) # rejection rates will be slightly off for multi-chain objects
# mean difference function from `bkmr` package (default burnin of half of total number of iterations)
mdiff = OverallRiskSummaries(fit = combobj,
qs = seq(.05, 0.95, by = 0.1),
q.fixed = 0.5, method = "exact")
mdiff``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.69657624,"math_prob":0.94066334,"size":2675,"snap":"2022-27-2022-33","text_gpt3_token_len":688,"char_repetition_ratio":0.109322354,"word_repetition_ratio":0.0,"special_character_ratio":0.22317757,"punctuation_ratio":0.11238532,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9900521,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-25T05:31:45Z\",\"WARC-Record-ID\":\"<urn:uuid:728a75f6-6f14-466d-a458-ed19ee0027f0>\",\"Content-Length\":\"4810\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:381852d0-ddae-429f-8394-9603b5f06575>\",\"WARC-Concurrent-To\":\"<urn:uuid:e584d989-959d-4c6a-b255-38ffcce4e37d>\",\"WARC-IP-Address\":\"5.196.141.73\",\"WARC-Target-URI\":\"http://cran.fhcrc.org/web/packages/bkmrhat/readme/README.html\",\"WARC-Payload-Digest\":\"sha1:O3WJB7UH5SLETKET563KEOP4GTQJRTHN\",\"WARC-Block-Digest\":\"sha1:MTNF2OW4BG3GX67L7Z5SK6E6ZIPV4ED6\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103034170.1_warc_CC-MAIN-20220625034751-20220625064751-00043.warc.gz\"}"}