Introduction to bkmr and bkmrhat

bkmr is a package to implement Bayesian kernel machine regression (BKMR) using Markov chain Monte Carlo (MCMC). Notably, bkmr is missing some key features in Bayesian inference and MCMC diagnostics: 1) no facility for running multiple chains in parallel 2) no inference across multiple chains 3) limited posterior summary of parameters 4) limited diagnostics. The bkmrhat package is a lightweight set of function that fills in each of those gaps by enabling post-processing of bkmr output in other packages and building a small framework for parallel processing.

How to use the bkmrhat package

  1. Fit a BKMR model for a single chain using the kmbaryes function from bkmr, or use multiple parallel chains kmbayes_parallel from bkmrhat
  2. Perform diagnostics on single or multiple chains using the kmbayes_diagnose function (uses functions from the rstan package) OR convert the BKMR fit(s) to mcmc (one chain) or mcmc.list (multiple chains) objects from the coda package using as.mcmc or as.mcmc.list from the bkmrhat package. The coda package has a whole host of inference and diagnostic procedures (but may lag behind some of the diagnostics functions from rstan).
  3. Perform posterior summaries using coda functions or combine chains from a kmbayes_parallel fit using kmbayes_combine. Final posterior inferences can be made on the combined object, which enables use of bkmr package functions for visual summaries of independent and joint effects of exposures in the bkmr model.

First, simulate some data from the bkmr function

library("bkmr")
library("bkmrhat")
library("coda")
Sys.setenv(R_FUTURE_SUPPORTSMULTICORE_UNSTABLE="quiet") # for future package

set.seed(111)
dat <- bkmr::SimData(n = 50, M = 5, ind=1:3, Zgen="realistic")
y <- dat$y
Z <- dat$Z
X <- cbind(dat$X, rnorm(50))
head(cbind(y,Z,X))
##               y          z1          z2          z3          z4         z5
## [1,]  4.1379128 -0.06359282 -0.02996246 -0.14190647 -0.44089352 -0.1878732
## [2,] 12.0843607 -0.07308834  0.32021690  1.08838691  0.29448354 -1.4609837
## [3,]  7.8859254  0.59604857  0.20602329  0.46218114 -0.03387906 -0.7615902
## [4,]  1.1609768  1.46504863  2.48389356  1.39869461  1.49678590  0.2837234
## [5,]  0.4989372 -0.37549639  0.01159884  1.17891641 -0.05286516 -0.1680664
## [6,]  5.0731242 -0.36904566 -0.49744932 -0.03330522  0.30843805  0.6814844
##                           
## [1,]  1.0569172 -1.0503824
## [2,]  4.8158570  0.3251424
## [3,]  2.6683461 -2.1048716
## [4,] -0.7492096 -0.9551027
## [5,] -0.5428339 -0.5306399
## [6,]  1.6493251  0.8274405

Example 1: single vs multi-chains

There is some overhead in parallel processing when using the future package, so the payoff when using parallel processing may vary by the problem. Here it is about a 2-4x speedup, but you can see more benefit at higher iterations. Note that this may not yield as many usable iterations as a single large chain if a substantial burnin period is needed, but it will enable useful convergence diagnostics. Note that the future package can implement sequential processing, which effectively turns the kmbayes_parallel into a loop, but still has all other advantages of multiple chains.

# enable parallel processing (up to 4 simultaneous processes here)
future::plan(strategy = future::multiprocess, workers=4, .skip=TRUE)

# single run of 4000 observations from bkmr package
set.seed(111)
system.time(kmfit <- suppressMessages(kmbayes(y = y, Z = Z, X = X, iter = 4000, verbose = FALSE, varsel = FALSE)))
##    user  system elapsed 
##  12.063   0.148  12.622
# 4 runs of 1000 observations from bkmrhat package
set.seed(111)
system.time(kmfit5 <- suppressMessages(kmbayes_parallel(nchains=4, y = y, Z = Z, X = X, iter = 1000, verbose = FALSE, varsel = FALSE)))
## Chain 1 
## Chain 2 
## Chain 3 
## Chain 4
##    user  system elapsed 
##   0.058   0.003   4.584

Example 2: Diagnostics

The diagnostics from the rstan package come from the monitor function (see the help files for that function in the rstan pacakge)

# Using rstan functions (set burnin/warmup to zero for comparability with coda numbers given later
#  posterior summaries should be performed after excluding warmup/burnin)
singlediag = kmbayes_diagnose(kmfit, warmup=0, digits_summary=2)
## Single chain
## Inference for the input samples (1 chains: each with iter = 4000; warmup = 0):
## 
##            Q5  Q50  Q95 Mean  SD  Rhat Bulk_ESS Tail_ESS
## beta1     1.9  2.0  2.1  2.0 0.0  1.00     2820     3194
## beta2     0.0  0.1  0.3  0.1 0.1  1.00     3739     3535
## lambda    3.9 10.0 22.3 11.2 5.9  1.00      346      222
## r1        0.0  0.0  0.1  0.0 0.1  1.01      129      173
## r2        0.0  0.0  0.1  0.0 0.1  1.00      182      181
## r3        0.0  0.0  0.0  0.0 0.0  1.01      158      112
## r4        0.0  0.0  0.1  0.0 0.1  1.03      176      135
## r5        0.0  0.0  0.0  0.0 0.1  1.00      107      114
## sigsq.eps 0.2  0.3  0.5  0.4 0.1  1.00     1262     1563
## 
## For each parameter, Bulk_ESS and Tail_ESS are crude measures of 
## effective sample size for bulk and tail quantities respectively (an ESS > 100 
## per chain is considered good), and Rhat is the potential scale reduction 
## factor on rank normalized split chains (at convergence, Rhat <= 1.05).
# Using rstan functions (multiple chains enable R-hat)
multidiag = kmbayes_diagnose(kmfit5, warmup=0, digits_summary=2)
## Parallel chains
## Inference for the input samples (4 chains: each with iter = 1000; warmup = 0):
## 
##            Q5  Q50  Q95 Mean  SD  Rhat Bulk_ESS Tail_ESS
## beta1     1.9  2.0  2.1  2.0 0.0  1.00     2358     3633
## beta2     0.0  0.1  0.3  0.1 0.1  1.00     3097     2702
## lambda    5.0 10.2 22.8 11.5 5.3  1.00      417      399
## r1        0.0  0.0  0.3  0.1 0.2  1.05      105       64
## r2        0.0  0.0  0.1  0.0 0.1  1.01      147       96
## r3        0.0  0.0  0.9  0.1 0.3  1.02      107       64
## r4        0.0  0.0  0.1  0.0 0.1  1.00      176      125
## r5        0.0  0.0  0.0  0.0 0.1  1.04      118      110
## sigsq.eps 0.2  0.3  0.5  0.3 0.1  1.01      603      374
## 
## For each parameter, Bulk_ESS and Tail_ESS are crude measures of 
## effective sample size for bulk and tail quantities respectively (an ESS > 100 
## per chain is considered good), and Rhat is the potential scale reduction 
## factor on rank normalized split chains (at convergence, Rhat <= 1.05).
# using coda functions, not using any burnin (for demonstration only)
kmfitcoda = as.mcmc(kmfit, iterstart = 1)
kmfit5coda = as.mcmc.list(kmfit5, iterstart = 1)

# single chain trace plot
traceplot(kmfitcoda)

plot of chunk diagnostics 1plot of chunk diagnostics 1plot of chunk diagnostics 1plot of chunk diagnostics 1plot of chunk diagnostics 1plot of chunk diagnostics 1plot of chunk diagnostics 1plot of chunk diagnostics 1plot of chunk diagnostics 1 The trace plots look typical, and fine, but trace plots don't give a full picture of convergence. Note that there is apparent quick convergence for a couple of parameters demonstrated by movement away from the starting value and concentration of the rest of the samples within a narrow band.

Seeing visual evidence that different chains are sampling from the same marginal distributions is reassuring about the stability of the results.

# multiple chain trace plot
traceplot(kmfit5coda)

plot of chunk diagnostics 2plot of chunk diagnostics 2plot of chunk diagnostics 2plot of chunk diagnostics 2plot of chunk diagnostics 2plot of chunk diagnostics 2plot of chunk diagnostics 2plot of chunk diagnostics 2plot of chunk diagnostics 2

Now examine “cross correlation”, which can help identify highly correlated parameters in the posterior, which can be problematic for MCMC sampling. Here there is a block {r3,r4,r5} which appear to be highly correlated. All other things equal, having highly correlated parameters in the posterior means that more samples are needed than would be needed with uncorrelated parameters.

# multiple cross-correlation plot (combines all samples)
crosscorr(kmfit5coda)
##                 beta1       beta2       lambda          r1          r2
## beta1     1.000000000  0.03499376  0.002359281  0.05145805  0.10488344
## beta2     0.034993759  1.00000000 -0.107992816 -0.05367503 -0.02749756
## lambda    0.002359281 -0.10799282  1.000000000  0.12300031  0.11104722
## r1        0.051458052 -0.05367503  0.123000307  1.00000000  0.86958985
## r2        0.104883437 -0.02749756  0.111047218  0.86958985  1.00000000
## r3        0.001572616 -0.08534418  0.130666665  0.91479595  0.73861260
## r4        0.142452377 -0.01223393  0.079722941  0.82980867  0.90711404
## r5        0.161900085  0.01702033  0.016581762  0.62814229  0.78262044
## sigsq.eps 0.008792498  0.08592043 -0.298156688 -0.28836606 -0.28337966
##                     r3          r4          r5    sigsq.eps
## beta1      0.001572616  0.14245238  0.16190008  0.008792498
## beta2     -0.085344175 -0.01223393  0.01702033  0.085920426
## lambda     0.130666665  0.07972294  0.01658176 -0.298156688
## r1         0.914795951  0.82980867  0.62814229 -0.288366058
## r2         0.738612599  0.90711404  0.78262044 -0.283379656
## r3         1.000000000  0.68436685  0.43061975 -0.301232945
## r4         0.684366853  1.00000000  0.80868268 -0.227868759
## r5         0.430619749  0.80868268  1.00000000 -0.087690711
## sigsq.eps -0.301232945 -0.22786876 -0.08769071  1.000000000
crosscorr.plot(kmfit5coda)

plot of chunk diagnostics 2b

Now examine “autocorrelation” to identify parameters that have high correlation between subsequent iterations of the MCMC sampler, which can lead to inefficient MCMC sampling. All other things equal, having highly autocorrelated parameters in the posterior means that more samples are needed than would be needed with low-autocorrelation parameters.

# multiple chain trace plot
#autocorr(kmfit5coda) # lots of output
autocorr.plot(kmfit5coda)

plot of chunk diagnostics 2cplot of chunk diagnostics 2c

Graphical tools can be limited, and are sometimes difficult to use effectively with scale parameters (of which bkmr has many). Additionally, no single diagnostic is perfect, leading many authors to advocate the use of multiple, complementary diagnostics. Thus, more formal diagnostics are helpful.

Gelman's r-hat diagnostic gives an interpretable diagnostic: the expected reduction in the standard error of the posterior means if you could run the chains to an infinite size. These give some idea about when is a fine idea to stop sampling. There are rules of thumb about using r-hat to stop sampling that are available from several authors (for example you can consult the help files for rstan and coda).

Effective sample size is also useful - it estimates the amount of information in your chain, expressed in terms of the number of independent posterior samples it would take to match that information (e.g. if we could just sample from the posterior directly).

# Gelman's r-hat using coda estimator (will differ from rstan implementation)
gelman.diag(kmfit5coda)
## Potential scale reduction factors:
## 
##           Point est. Upper C.I.
## beta1            NaN        NaN
## beta2            NaN        NaN
## lambda           NaN        NaN
## r1               NaN        NaN
## r2               NaN        NaN
## r3               NaN        NaN
## r4               NaN        NaN
## r5               NaN        NaN
## sigsq.eps        NaN        NaN
## 
## Multivariate psrf
## 
## 0.999
# effective sample size
effectiveSize(kmfitcoda)
##      beta1      beta2     lambda         r1         r2         r3         r4 
## 2411.61878 2865.78299  431.49158   87.11091  260.29419  328.45388  181.61903 
##         r5  sigsq.eps 
##  123.06100 1719.70679
effectiveSize(kmfit5coda)
##      beta1      beta2     lambda         r1         r2         r3         r4 
## 2546.99571 4000.00000  468.76001   49.13918  111.02355   61.79098  150.74636 
##         r5  sigsq.eps 
##  326.90745 1068.08491

Example 3: Posterior summaries

Posterior kernel marginal densities, 1 chain

# posterior kernel marginal densities using `mcmc` and `mcmc` objects
densplot(kmfitcoda)

plot of chunk post summaries 1plot of chunk post summaries 1plot of chunk post summaries 1plot of chunk post summaries 1plot of chunk post summaries 1plot of chunk post summaries 1plot of chunk post summaries 1plot of chunk post summaries 1plot of chunk post summaries 1

Posterior kernel marginal densities, multiple chains combined. Look for multiple modes that may indicate non-convergence of some chains

# posterior kernel marginal densities using `mcmc` and `mcmc` objects
densplot(kmfit5coda)

plot of chunk post summaries 2plot of chunk post summaries 2plot of chunk post summaries 2plot of chunk post summaries 2plot of chunk post summaries 2plot of chunk post summaries 2plot of chunk post summaries 2plot of chunk post summaries 2plot of chunk post summaries 2

Other diagnostics from the coda package are available here.

Finally, the chains from the original kmbayes_parallel fit can be combined into a single chain (see the help files for how to deal with burn-in, the default in bkmr is to use the first half of the chain, which is respected here). The kmbayes_combine function smartly first combines the burn-in iterations and then combines the iterations after burnin, such that the burn-in rules of subsequent functions within the bkmr package are respected. Note that unlike the as.mcmc.list function, this function combines all iterations into a single chain, so trace plots will not be good diagnotistics in this combined object, and it should be used once one is assured that all chains have converged and the burn-in is acceptable.

With this combined set of samples, you can follow any of the post-processing functions from the bkmr functions, which are described here: https://jenfb.github.io/bkmr/overview.html. For example, see below the estimation of the posterior mean difference along a series of quantiles of all exposures in Z.

# posterior summaries using `mcmc` and `mcmc` objects
summary(kmfitcoda)
## 
## Iterations = 1:4000
## Thinning interval = 1 
## Number of chains = 1 
## Sample size per chain = 4000 
## 
## 1. Empirical mean and standard deviation for each variable,
##    plus standard error of the mean:
## 
##               Mean      SD  Naive SE Time-series SE
## beta1      1.98349 0.04392 0.0006945      0.0008944
## beta2      0.11999 0.08532 0.0013490      0.0015937
## lambda    11.18052 5.90540 0.0933725      0.2842909
## r1         0.03010 0.06385 0.0010095      0.0068408
## r2         0.03656 0.05690 0.0008997      0.0035270
## r3         0.02131 0.04065 0.0006427      0.0022429
## r4         0.02855 0.06641 0.0010500      0.0049278
## r5         0.02904 0.09543 0.0015089      0.0086023
## sigsq.eps  0.35283 0.08228 0.0013009      0.0019840
## 
## 2. Quantiles for each variable:
## 
##               2.5%     25%      50%      75%    97.5%
## beta1      1.90086 1.95474  1.98287  2.01177  2.07218
## beta2     -0.04513 0.06141  0.12001  0.17716  0.28713
## lambda     3.23941 7.01814 10.00979 14.12075 25.93332
## r1         0.01022 0.01232  0.01807  0.02767  0.09818
## r2         0.01018 0.01433  0.02172  0.04049  0.12353
## r3         0.01015 0.01180  0.01488  0.02198  0.05655
## r4         0.01040 0.01299  0.01670  0.02582  0.08533
## r5         0.01025 0.01219  0.01532  0.01951  0.07021
## sigsq.eps  0.22855 0.29302  0.34057  0.39833  0.54838
summary(kmfit5coda)
## 
## Iterations = 1:1000
## Thinning interval = 1 
## Number of chains = 4 
## Sample size per chain = 1000 
## 
## 1. Empirical mean and standard deviation for each variable,
##    plus standard error of the mean:
## 
##               Mean      SD  Naive SE Time-series SE
## beta1      1.98361 0.04371 0.0006912      0.0008665
## beta2      0.12219 0.08560 0.0013535      0.0013540
## lambda    11.54914 5.29769 0.0837638      0.2447789
## r1         0.05932 0.17439 0.0027574      0.0248871
## r2         0.04629 0.09736 0.0015394      0.0092434
## r3         0.09170 0.27612 0.0043659      0.0351403
## r4         0.04714 0.12707 0.0020091      0.0103533
## r5         0.02316 0.05927 0.0009372      0.0032794
## sigsq.eps  0.34141 0.07891 0.0012476      0.0024154
## 
## 2. Quantiles for each variable:
## 
##               2.5%     25%      50%      75%    97.5%
## beta1      1.90021 1.95485  1.98255  2.01203  2.07334
## beta2     -0.03791 0.06681  0.12411  0.17823  0.29494
## lambda     4.03771 8.11272 10.15487 13.97751 25.60664
## r1         0.01075 0.01345  0.01702  0.02490  0.75815
## r2         0.01077 0.01356  0.02097  0.03700  0.34470
## r3         0.01032 0.01205  0.01690  0.02361  1.21138
## r4         0.01003 0.01185  0.01784  0.03152  0.32628
## r5         0.01105 0.01152  0.01477  0.02016  0.04189
## sigsq.eps  0.20738 0.28892  0.33774  0.38460  0.51568
# highest posterior density intervals using `mcmc` and `mcmc` objects
HPDinterval(kmfitcoda)
##                 lower       upper
## beta1      1.90086937  2.07231225
## beta2     -0.04051413  0.29012992
## lambda     2.68866745 22.62238656
## r1         0.01002094  0.06754473
## r2         0.01002597  0.09683241
## r3         0.01003504  0.04392585
## r4         0.01000511  0.06510500
## r5         0.01005733  0.04755863
## sigsq.eps  0.21411781  0.52229778
## attr(,"Probability")
## [1] 0.95
HPDinterval(kmfit5coda)
## [[1]]
##                 lower       upper
## beta1      1.90740384  2.07789602
## beta2     -0.03997548  0.28934198
## lambda     3.55386120 23.10095724
## r1         0.01039420  0.27828663
## r2         0.01022868  0.12603177
## r3         0.01024533  0.93819730
## r4         0.01000060  0.12604772
## r5         0.01057609  0.03037713
## sigsq.eps  0.19663177  0.50582793
## attr(,"Probability")
## [1] 0.95
## 
## [[2]]
##                 lower       upper
## beta1      1.90740384  2.07789602
## beta2     -0.03997548  0.28934198
## lambda     3.55386120 23.10095724
## r1         0.01039420  0.27828663
## r2         0.01022868  0.12603177
## r3         0.01024533  0.93819730
## r4         0.01000060  0.12604772
## r5         0.01057609  0.03037713
## sigsq.eps  0.19663177  0.50582793
## attr(,"Probability")
## [1] 0.95
## 
## [[3]]
##                 lower       upper
## beta1      1.90740384  2.07789602
## beta2     -0.03997548  0.28934198
## lambda     3.55386120 23.10095724
## r1         0.01039420  0.27828663
## r2         0.01022868  0.12603177
## r3         0.01024533  0.93819730
## r4         0.01000060  0.12604772
## r5         0.01057609  0.03037713
## sigsq.eps  0.19663177  0.50582793
## attr(,"Probability")
## [1] 0.95
## 
## [[4]]
##                 lower       upper
## beta1      1.90740384  2.07789602
## beta2     -0.03997548  0.28934198
## lambda     3.55386120 23.10095724
## r1         0.01039420  0.27828663
## r2         0.01022868  0.12603177
## r3         0.01024533  0.93819730
## r4         0.01000060  0.12604772
## r5         0.01057609  0.03037713
## sigsq.eps  0.19663177  0.50582793
## attr(,"Probability")
## [1] 0.95
# combine multiple chains into a single chain
fitkmccomb = kmbayes_combine(kmfit5)


# For example:
summary(fitkmccomb)
## Fitted object of class 'bkmrfit'
## Iterations: 4000 
## Outcome family: gaussian  
## Model fit on: 2021-01-26 15:12:05 
## Running time:  3.02155 secs 
## 
## Acceptance rates for Metropolis-Hastings algorithm:
##    param      rate
## 1 lambda 0.4001000
## 2     r1 0.1770443
## 3     r2 0.2440610
## 4     r3 0.1820455
## 5     r4 0.2030508
## 6     r5 0.1170293
## 
## Parameter estimates (based on iterations 2001-4000):
##       param     mean      sd    q_2.5   q_97.5
## 1     beta1  1.98348 0.04097  1.90740  2.06825
## 2     beta2  0.11937 0.08279 -0.03319  0.28290
## 3 sigsq.eps  0.33892 0.06961  0.22680  0.50465
## 4        r1  0.01933 0.01170  0.01098  0.05578
## 5        r2  0.03155 0.02212  0.01118  0.10519
## 6        r3  0.01918 0.00945  0.01058  0.04947
## 7        r4  0.02578 0.02654  0.01003  0.07725
## 8        r5  0.01579 0.00577  0.01089  0.03158
## 9    lambda 11.78451 5.19641  4.89097 25.66783
mean.difference <- suppressWarnings(OverallRiskSummaries(fit = fitkmccomb, y = y, Z = Z, X = X, 
                                      qs = seq(0.25, 0.75, by = 0.05), 
                                      q.fixed = 0.5, method = "exact"))
mean.difference
##    quantile        est         sd
## 1      0.25 -0.7229150 0.11559899
## 2      0.30 -0.5823031 0.09340586
## 3      0.35 -0.3949272 0.07699192
## 4      0.40 -0.2747890 0.04412531
## 5      0.45 -0.1505780 0.02463272
## 6      0.50  0.0000000 0.00000000
## 7      0.55  0.2164267 0.04057414
## 8      0.60  0.3354014 0.04924951
## 9      0.65  0.5150216 0.07974133
## 10     0.70  0.8824856 0.13862509
## 11     0.75  0.9778237 0.14740760
with(mean.difference, {
  plot(quantile, est, pch=19, ylim=c(min(est - 1.96*sd), max(est + 1.96*sd)), 
       axes=FALSE, ylab= "Mean difference", xlab = "Joint quantile")
  segments(x0=quantile, x1=quantile, y0 = est - 1.96*sd, y1 = est + 1.96*sd)
  abline(h=0)
  axis(1)
  axis(2)
  box(bty='l')
})

plot of chunk post summaries 3

Example 4: diagnostics and inference when variable selection is used (Bayesian model averaging over the scale parameters of the kernel function)

These results parallel previous session and are given here without comment, other than to note that no fixed effects (X variables) are included, and that it is useful to check the posterior inclusion probabilities to ensure they are similar across chains.

set.seed(111)
system.time(kmfitbma.list <- suppressWarnings(kmbayes_parallel(nchains=4, y = y, Z = Z, X = X, iter = 1000, verbose = FALSE, varsel = TRUE)))
## Chain 1
## Iteration: 100 (10% completed; 0.14543 secs elapsed)
## Iteration: 200 (20% completed; 0.30289 secs elapsed)
## Iteration: 300 (30% completed; 0.43152 secs elapsed)
## Iteration: 400 (40% completed; 0.55677 secs elapsed)
## Iteration: 500 (50% completed; 0.68924 secs elapsed)
## Iteration: 600 (60% completed; 0.82487 secs elapsed)
## Iteration: 700 (70% completed; 0.97162 secs elapsed)
## Iteration: 800 (80% completed; 1.10693 secs elapsed)
## Iteration: 900 (90% completed; 1.26416 secs elapsed)
## Iteration: 1000 (100% completed; 1.404 secs elapsed)
## Chain 2
## Iteration: 100 (10% completed; 0.14907 secs elapsed)
## Iteration: 200 (20% completed; 0.2985 secs elapsed)
## Iteration: 300 (30% completed; 0.43175 secs elapsed)
## Iteration: 400 (40% completed; 0.56238 secs elapsed)
## Iteration: 500 (50% completed; 0.70424 secs elapsed)
## Iteration: 600 (60% completed; 0.84983 secs elapsed)
## Iteration: 700 (70% completed; 0.9975 secs elapsed)
## Iteration: 800 (80% completed; 1.13579 secs elapsed)
## Iteration: 900 (90% completed; 1.28437 secs elapsed)
## Iteration: 1000 (100% completed; 1.43621 secs elapsed)
## Chain 3
## Iteration: 100 (10% completed; 0.149 secs elapsed)
## Iteration: 200 (20% completed; 0.29737 secs elapsed)
## Iteration: 300 (30% completed; 0.43043 secs elapsed)
## Iteration: 400 (40% completed; 0.5635 secs elapsed)
## Iteration: 500 (50% completed; 0.70906 secs elapsed)
## Iteration: 600 (60% completed; 0.85769 secs elapsed)
## Iteration: 700 (70% completed; 1.00267 secs elapsed)
## Iteration: 800 (80% completed; 1.1434 secs elapsed)
## Iteration: 900 (90% completed; 1.29095 secs elapsed)
## Iteration: 1000 (100% completed; 1.44325 secs elapsed)
## Chain 4
## Iteration: 100 (10% completed; 0.14819 secs elapsed)
## Iteration: 200 (20% completed; 0.29209 secs elapsed)
## Iteration: 300 (30% completed; 0.42277 secs elapsed)
## Iteration: 400 (40% completed; 0.55731 secs elapsed)
## Iteration: 500 (50% completed; 0.70806 secs elapsed)
## Iteration: 600 (60% completed; 0.85628 secs elapsed)
## Iteration: 700 (70% completed; 1.00118 secs elapsed)
## Iteration: 800 (80% completed; 1.14505 secs elapsed)
## Iteration: 900 (90% completed; 1.29048 secs elapsed)
## Iteration: 1000 (100% completed; 1.4422 secs elapsed)
##    user  system elapsed 
##   0.055   0.003   1.601
bmadiag = kmbayes_diagnose(kmfitbma.list)
## Parallel chains
## Inference for the input samples (4 chains: each with iter = 1000; warmup = 500):
## 
##            Q5  Q50  Q95 Mean  SD  Rhat Bulk_ESS Tail_ESS
## beta1     1.9  2.0  2.0  2.0 0.0  1.01      430     1693
## beta2     0.0  0.1  0.3  0.1 0.1  1.00     1331     1263
## lambda    4.7 11.5 32.4 14.0 8.6  1.00      150      178
## r1        0.0  0.0  0.0  0.0 0.0  1.03       48       85
## r2        0.0  0.0  0.1  0.0 0.0  1.01       50       85
## r3        0.0  0.0  0.0  0.0 0.0  1.01      118       46
## r4        0.0  0.0  0.0  0.0 0.0  1.06       57       69
## r5        0.0  0.0  0.0  0.0 0.0  1.08      167       95
## sigsq.eps 0.2  0.4  0.5  0.4 0.1  1.00      488     1280
## 
## For each parameter, Bulk_ESS and Tail_ESS are crude measures of 
## effective sample size for bulk and tail quantities respectively (an ESS > 100 
## per chain is considered good), and Rhat is the potential scale reduction 
## factor on rank normalized split chains (at convergence, Rhat <= 1.05).
# posterior exclusion probability of each chain
lapply(kmfitbma.list, function(x) t(ExtractPIPs(x)))
## [[1]]
##          [,1]    [,2]    [,3]    [,4]    [,5]   
## variable "z1"    "z2"    "z3"    "z4"    "z5"   
## PIP      "0.886" "0.838" "0.438" "0.782" "0.574"
## 
## [[2]]
##          [,1]    [,2]    [,3]    [,4]    [,5]   
## variable "z1"    "z2"    "z3"    "z4"    "z5"   
## PIP      "0.886" "0.838" "0.438" "0.782" "0.574"
## 
## [[3]]
##          [,1]    [,2]    [,3]    [,4]    [,5]   
## variable "z1"    "z2"    "z3"    "z4"    "z5"   
## PIP      "0.886" "0.838" "0.438" "0.782" "0.574"
## 
## [[4]]
##          [,1]    [,2]    [,3]    [,4]    [,5]   
## variable "z1"    "z2"    "z3"    "z4"    "z5"   
## PIP      "0.886" "0.838" "0.438" "0.782" "0.574"
kmfitbma.comb = kmbayes_combine(kmfitbma.list)
summary(kmfitbma.comb)
## Fitted object of class 'bkmrfit'
## Iterations: 4000 
## Outcome family: gaussian  
## Model fit on: 2021-01-26 15:12:12 
## Running time:  1.40494 secs 
## 
## Acceptance rates for Metropolis-Hastings algorithm:
##               param     rate
## 1            lambda 0.480120
## 2 r/delta (overall) 0.260065
## 3 r/delta  (move 1) 0.379015
## 4 r/delta  (move 2) 0.156015
## 
## Parameter estimates (based on iterations 2001-4000):
##       param     mean      sd    q_2.5   q_97.5
## 1     beta1  1.97377 0.04492  1.88211  2.05474
## 2     beta2  0.12162 0.08991 -0.05801  0.31086
## 3 sigsq.eps  0.36722 0.08908  0.23180  0.58529
## 4        r1  0.02035 0.01129  0.00000  0.02936
## 5        r2  0.02318 0.02166  0.00000  0.08988
## 6        r3  0.00723 0.01059  0.00000  0.03599
## 7        r4  0.01349 0.01005  0.00000  0.04053
## 8        r5  0.00894 0.00992  0.00000  0.04334
## 9    lambda 13.95773 8.62564  4.48324 39.65770
## 
## Posterior inclusion probabilities:
##   variable   PIP
## 1       z1 0.886
## 2       z2 0.838
## 3       z3 0.438
## 4       z4 0.782
## 5       z5 0.574
ExtractPIPs(kmfitbma.comb) # posterior inclusion probabilities
##   variable   PIP
## 1       z1 0.886
## 2       z2 0.838
## 3       z3 0.438
## 4       z4 0.782
## 5       z5 0.574
mean.difference2 <- suppressWarnings(OverallRiskSummaries(fit = kmfitbma.comb, y = y, Z = Z, X = X,                                       qs = seq(0.25, 0.75, by = 0.05), 
                                      q.fixed = 0.5, method = "exact"))
mean.difference2
##    quantile        est         sd
## 1      0.25 -0.6373201 0.11960408
## 2      0.30 -0.5108233 0.09815783
## 3      0.35 -0.3328134 0.08949531
## 4      0.40 -0.2426528 0.04812088
## 5      0.45 -0.1425157 0.02468133
## 6      0.50  0.0000000 0.00000000
## 7      0.55  0.1987361 0.04558399
## 8      0.60  0.3028661 0.05298498
## 9      0.65  0.4742272 0.08868922
## 10     0.70  0.8277111 0.16071137
## 11     0.75  0.9081320 0.15888003
with(mean.difference2, {
  plot(quantile, est, pch=19, ylim=c(min(est - 1.96*sd), max(est + 1.96*sd)), 
       axes=FALSE, ylab= "Mean difference", xlab = "Joint quantile")
  segments(x0=quantile, x1=quantile, y0 = est - 1.96*sd, y1 = est + 1.96*sd)
  abline(h=0)
  axis(1)
  axis(2)
  box(bty='l')
})

plot of chunk varsel

Example 5: Parallel posterior summaries as diagnostics

bkmrhat also has ported versions of the native posterior summarization functions to compare how these summaries vary across parallel chains. Note that these should serve as diagnostics, and final posterior inference should be done on the combined chain. The easiest of these functions to demonstrate is the OverallRiskSummaries_parallel function, which simply runs OverallRiskSummaries (from the bkmr package) on each chain and combines the results. Notably, this function fixes the y-axis at zero for the median, so it under-represents overall predictive variation across chains, but captures variation in effect estimates across the chains. Ideally, that variation is negligible - e.g. if you see differences between chains that would result in different interpretations, you should re-fit the model with more iterations. In this example, the results are reasonably consistent across chains, but one might want to run more iterations if, say, the differences seen across the upper error bounds are of such a magnitude as to be practically meaningful.

set.seed(111)
system.time(kmfitbma.list <- suppressWarnings(kmbayes_parallel(nchains=4, y = y, Z = Z, X = X, iter = 1000, verbose = FALSE, varsel = TRUE)))
## Chain 1
## Iteration: 100 (10% completed; 0.10404 secs elapsed)
## Iteration: 200 (20% completed; 0.21638 secs elapsed)
## Iteration: 300 (30% completed; 0.32607 secs elapsed)
## Iteration: 400 (40% completed; 0.43536 secs elapsed)
## Iteration: 500 (50% completed; 0.54192 secs elapsed)
## Iteration: 600 (60% completed; 0.65635 secs elapsed)
## Iteration: 700 (70% completed; 0.76611 secs elapsed)
## Iteration: 800 (80% completed; 0.87288 secs elapsed)
## Iteration: 900 (90% completed; 1.07966 secs elapsed)
## Iteration: 1000 (100% completed; 1.1969 secs elapsed)
## Chain 2
## Iteration: 100 (10% completed; 0.10999 secs elapsed)
## Iteration: 200 (20% completed; 0.22065 secs elapsed)
## Iteration: 300 (30% completed; 0.32787 secs elapsed)
## Iteration: 400 (40% completed; 0.44224 secs elapsed)
## Iteration: 500 (50% completed; 0.54776 secs elapsed)
## Iteration: 600 (60% completed; 0.65795 secs elapsed)
## Iteration: 700 (70% completed; 0.77138 secs elapsed)
## Iteration: 800 (80% completed; 0.87936 secs elapsed)
## Iteration: 900 (90% completed; 0.99193 secs elapsed)
## Iteration: 1000 (100% completed; 1.10262 secs elapsed)
## Chain 3
## Iteration: 100 (10% completed; 0.10934 secs elapsed)
## Iteration: 200 (20% completed; 0.22265 secs elapsed)
## Iteration: 300 (30% completed; 0.33178 secs elapsed)
## Iteration: 400 (40% completed; 0.44654 secs elapsed)
## Iteration: 500 (50% completed; 0.55349 secs elapsed)
## Iteration: 600 (60% completed; 0.66308 secs elapsed)
## Iteration: 700 (70% completed; 0.77579 secs elapsed)
## Iteration: 800 (80% completed; 0.88526 secs elapsed)
## Iteration: 900 (90% completed; 0.9955 secs elapsed)
## Iteration: 1000 (100% completed; 1.10496 secs elapsed)
## Chain 4
## Iteration: 100 (10% completed; 0.11125 secs elapsed)
## Iteration: 200 (20% completed; 0.22263 secs elapsed)
## Iteration: 300 (30% completed; 0.33346 secs elapsed)
## Iteration: 400 (40% completed; 0.45288 secs elapsed)
## Iteration: 500 (50% completed; 0.56162 secs elapsed)
## Iteration: 600 (60% completed; 0.67193 secs elapsed)
## Iteration: 700 (70% completed; 0.78441 secs elapsed)
## Iteration: 800 (80% completed; 0.8917 secs elapsed)
## Iteration: 900 (90% completed; 1.00245 secs elapsed)
## Iteration: 1000 (100% completed; 1.11239 secs elapsed)
##    user  system elapsed 
##   0.046   0.004   1.276
meandifference_par = OverallRiskSummaries_parallel(kmfitbma.list, y = y, Z = Z, X = X ,qs = seq(0.25, 0.75, by = 0.05), q.fixed = 0.5, method = "exact")
## Chain 1 
## Chain 2 
## Chain 3 
## Chain 4
head(meandifference_par)
##   quantile        est         sd chain
## 1     0.25 -0.6358542 0.12275218     1
## 2     0.30 -0.5091560 0.10058817     1
## 3     0.35 -0.3310590 0.09151714     1
## 4     0.40 -0.2416927 0.04986424     1
## 5     0.45 -0.1419028 0.02542547     1
## 6     0.50  0.0000000 0.00000000     1
nchains = length(unique(meandifference_par$chain))

with(meandifference_par, {
  plot.new()
  plot.window(ylim=c(min(est - 1.96*sd), max(est + 1.96*sd)), 
              xlim=c(min(quantile), max(quantile)),
       ylab= "Mean difference", xlab = "Joint quantile")
  for(cch in seq_len(nchains)){
    width = diff(quantile)[1]
    jit = runif(1, -width/5, width/5)
   points(jit+quantile[chain==cch], est[chain==cch], pch=19, col=cch) 
   segments(x0=jit+quantile[chain==cch], x1=jit+quantile[chain==cch], y0 = est[chain==cch] - 1.96*sd[chain==cch], y1 = est[chain==cch] + 1.96*sd[chain==cch], col=cch)
  }
  abline(h=0)
  axis(1)
  axis(2)
  box(bty='l')
  legend("bottom", col=1:nchains, pch=19, lty=1, legend=paste("chain", 1:nchains), bty="n")
})

regfuns_par = PredictorResponseUnivar_parallel(kmfitbma.list, y = y, Z = Z, X = X ,qs = seq(0.25, 0.75, by = 0.05), q.fixed = 0.5, method = "exact")
## Chain 1 
## Chain 2 
## Chain 3 
## Chain 4
head(regfuns_par)
##   variable         z        est        se chain
## 1       z1 -2.186199 -1.1852548 0.7398639     1
## 2       z1 -2.082261 -1.1364027 0.7108937     1
## 3       z1 -1.978323 -1.0867757 0.6819122     1
## 4       z1 -1.874385 -1.0364275 0.6529431     1
## 5       z1 -1.770446 -0.9854145 0.6240118     1
## 6       z1 -1.666508 -0.9337959 0.5951463     1
nchains = length(unique(meandifference_par$chain))

# single variable
with(regfuns_par[regfuns_par$variable=="z1",], {
  plot.new()
  plot.window(ylim=c(min(est - 1.96*se), max(est + 1.96*se)), 
              xlim=c(min(z), max(z)),
       ylab= "Predicted Y", xlab = "Z")
  pc = c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#999999")
  pc2 = c("#0000001A", "#E69F001A", "#56B4E91A", "#009E731A", "#F0E4421A", "#0072B21A", "#D55E001A", "#CC79A71A", "#9999991A")
  for(cch in seq_len(nchains)){
   ribbonX = c(z[chain==cch], rev(z[chain==cch]))
   ribbonY = c(est[chain==cch] + 1.96*se[chain==cch], rev(est[chain==cch] - 1.96*se[chain==cch]))
   polygon(x=ribbonX, y = ribbonY, col=pc2[cch], border=NA)
   lines(z[chain==cch], est[chain==cch], pch=19, col=pc[cch]) 
  }
  axis(1)
  axis(2)
  box(bty='l')
  legend("bottom", col=1:nchains, pch=19, lty=1, legend=paste("chain", 1:nchains), bty="n")
})

plot of chunk post diagnosticsplot of chunk post diagnostics

Example 6: Continuing a fit

Sometimes you just need to run more samples in an existing chain. For example, you run a bkmr fit for 3 days, only to find you don't have enough samples. A “continued” fit just means that you can start off at the last iteration you were at and just keep building on an existing set of results by lengthening the Markov chain. Unfortunately, due to how the kmbayes function accepts starting values (for the official install version), you can't quite do this exactly in many cases (The function will relay a message and possible solutions, if any. bkmr package authors are aware of this issue). The kmbayes_continue function continues a bkmr fit as well as the bkmr package will allow. The r parameters from the fit must all be initialized at the same value, so kmbayes_continue starts a new MCMC fit at the final values of all parameters from the prior bkmr fit, but sets all of the r parameters to the mean at the last iteration from the previous fit. Additionally, if h.hat parameters are estimated, these are fixed to be above zero to meet similar constraints, either by fixing them at their posterior mean or setting to a small positive value. One should inspect trace plots to see whether this will cause issues (e.g. if the traceplots demonstrate different patterns in the samples before and after the continuation). Here's an example with a quick check of diagnostics of the first part of the chain, and the combined chain (which could be used for inference or extended again, if necessary). We caution users that this function creates 2 distinct, if very similar Markov chains, and to use appropriate caution if traceplots differ before and after each continuation. Nonetheless, in many cases one can act as though all samples are from the same Markov chain.

Note that if you install the developmental version of the bkmr package you can continue fits from exactly where they left off, so you get a true, single Markov chain. You can install that via the commented code below

# install dev version of bkmr to allow true continued fits.
#install.packages("devtools")
#devtools::install_github("jenfb/bkmr")

set.seed(111)
# run 100 initial iterations for a model with only 2 exposures
Z2 = Z[,1:2]
kmfitbma.start <- suppressWarnings(kmbayes(y = y, Z = Z2, X = X, iter = 500, verbose = FALSE, varsel = FALSE))
## Iteration: 50 (10% completed; 0.06002 secs elapsed)
## Iteration: 100 (20% completed; 0.13957 secs elapsed)
## Iteration: 150 (30% completed; 0.19944 secs elapsed)
## Iteration: 200 (40% completed; 0.26965 secs elapsed)
## Iteration: 250 (50% completed; 0.3347 secs elapsed)
## Iteration: 300 (60% completed; 0.40892 secs elapsed)
## Iteration: 350 (70% completed; 0.46902 secs elapsed)
## Iteration: 400 (80% completed; 0.53943 secs elapsed)
## Iteration: 450 (90% completed; 0.60072 secs elapsed)
## Iteration: 500 (100% completed; 0.6739 secs elapsed)
kmbayes_diag(kmfitbma.start)
## Single chain
## Inference for the input samples (1 chains: each with iter = 500; warmup = 250):
## 
##            Q5  Q50  Q95 Mean  SD  Rhat Bulk_ESS Tail_ESS
## beta1     1.9  2.0  2.0  2.0 0.0  1.02      184      238
## beta2     0.0  0.1  0.2  0.1 0.1  1.00      259      197
## lambda    6.4 15.0 33.2 17.0 8.2  1.03       32       38
## r1        0.0  0.0  0.0  0.0 0.0  1.20        5       16
## r2        0.0  0.0  0.1  0.0 0.0  1.01       26       28
## sigsq.eps 0.3  0.4  0.5  0.4 0.1  1.00      195      157
## 
## For each parameter, Bulk_ESS and Tail_ESS are crude measures of 
## effective sample size for bulk and tail quantities respectively (an ESS > 100 
## per chain is considered good), and Rhat is the potential scale reduction 
## factor on rank normalized split chains (at convergence, Rhat <= 1.05).
##                  mean     se_mean         sd        2.5%         25%
## beta1      1.96002469 0.002996717 0.04071499  1.88732666  1.93049212
## beta2      0.09934846 0.005601868 0.09100445 -0.06425935  0.03866907
## lambda    17.03096186 1.480162990 8.16066439  5.99261263 10.62650587
## r1         0.02445179 0.006963033 0.01503557  0.01009566  0.01650405
## r2         0.02931652 0.003839555 0.02294888  0.01050284  0.01300914
## sigsq.eps  0.38177766 0.006062528 0.08483668  0.25337749  0.32965181
##                   50%         75%       97.5% n_eff      Rhat valid          Q5
## beta1      1.96168526  1.98761915  2.04042002   192 1.0174270     1  1.89496869
## beta2      0.09494353  0.15892943  0.26004214   263 0.9979147     1 -0.04566104
## lambda    14.97716478 22.17297877 35.85230190    32 1.0322926     1  6.39370841
## r1         0.02078562  0.03098429  0.04827171    12 1.1969882     1  0.01009566
## r2         0.02369039  0.03766762  0.09155390    38 1.0072685     1  0.01213386
## sigsq.eps  0.36834066  0.42589940  0.61832629   187 0.9989252     1  0.26493273
##                   Q50         Q95    MCSE_Q2.5    MCSE_Q25    MCSE_Q50
## beta1      1.96168526  2.02239974 0.0061439984 0.003896226 0.004052288
## beta2      0.09494353  0.24851228 0.0125216874 0.009226277 0.006555085
## lambda    14.97716478 33.24311222 1.2308679568 0.873763048 1.767460797
## r1         0.02078562  0.04809447 0.0006957382 0.002532962 0.004430201
## r2         0.02369039  0.07473096 0.0011501569 0.001816037 0.004755380
## sigsq.eps  0.36834066  0.53371298 0.0112954790 0.004960890 0.004978161
##              MCSE_Q75  MCSE_Q97.5     MCSE_SD Bulk_ESS Tail_ESS
## beta1     0.001302716 0.010539232 0.002122356      184      238
## beta2     0.008043386 0.008643991 0.003965505      259      197
## lambda    3.451601827 1.237140963 1.056843473       32       38
## r1        0.006131920 0.001462048 0.005269340        5       16
## r2        0.002075801 0.013178244 0.002737455       26       28
## sigsq.eps 0.006630407 0.039435542 0.004293256      195      157
# run 2000 additional iterations
moreiterations = kmbayes_continue(kmfitbma.start, iter=2000)
## Modifying r starting values to meet kmbayes initial value constraints (this isn't a perfect continuation)
## This issue can be fixed by updating bkmr to the development version via: install.packages('devtools'); devtools::install_github('jenfb/bkmr')
## Validating control.params...
## Validating starting.values...
## r should be a vector of length equal to the number of columns of Z.  Input will be repeated or truncated as necessary.
## Iteration: 201 (10% completed; 0.29741 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param rate
## 1 lambda 0.45
## 2     r1 0.23
## 3     r2 0.24
## Iteration: 401 (20% completed; 0.74997 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param   rate
## 1 lambda 0.4475
## 2     r1 0.2075
## 3     r2 0.2675
## Iteration: 601 (30% completed; 1.18804 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param      rate
## 1 lambda 0.4766667
## 2     r1 0.1850000
## 3     r2 0.2700000
## Iteration: 801 (40% completed; 1.48009 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param    rate
## 1 lambda 0.49625
## 2     r1 0.16500
## 3     r2 0.25875
## Iteration: 1001 (50% completed; 1.8147 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param  rate
## 1 lambda 0.499
## 2     r1 0.176
## 3     r2 0.251
## Iteration: 1201 (60% completed; 2.24038 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param      rate
## 1 lambda 0.4966667
## 2     r1 0.1741667
## 3     r2 0.2533333
## Iteration: 1401 (70% completed; 2.59691 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param      rate
## 1 lambda 0.4957143
## 2     r1 0.1800000
## 3     r2 0.2571429
## Iteration: 1601 (80% completed; 2.88893 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param     rate
## 1 lambda 0.490000
## 2     r1 0.181250
## 3     r2 0.269375
## Iteration: 1801 (90% completed; 3.20823 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param      rate
## 1 lambda 0.4800000
## 2     r1 0.1811111
## 3     r2 0.2750000
## Iteration: 2001 (100% completed; 3.50493 secs elapsed)
## Acceptance rates for Metropolis-Hastings algorithm:
##    param   rate
## 1 lambda 0.4905
## 2     r1 0.1780
## 3     r2 0.2770
kmbayes_diag(moreiterations)
## Single chain
## Inference for the input samples (1 chains: each with iter = 2500; warmup = 1250):
## 
##            Q5  Q50  Q95 Mean  SD  Rhat Bulk_ESS Tail_ESS
## beta1     1.9  2.0  2.0  2.0 0.0  1.00     1219     1219
## beta2     0.0  0.1  0.3  0.1 0.1  1.00     1194     1111
## lambda    3.9 11.8 28.7 14.0 9.3  1.01       80       62
## r1        0.0  0.0  0.1  0.0 0.0  1.01       67       56
## r2        0.0  0.0  0.1  0.0 0.0  1.03       52       39
## sigsq.eps 0.3  0.4  0.6  0.4 0.1  1.00      592     1072
## 
## For each parameter, Bulk_ESS and Tail_ESS are crude measures of 
## effective sample size for bulk and tail quantities respectively (an ESS > 100 
## per chain is considered good), and Rhat is the potential scale reduction 
## factor on rank normalized split chains (at convergence, Rhat <= 1.05).
##                  mean     se_mean         sd        2.5%        25%         50%
## beta1      1.95732832 0.001361673 0.04758648  1.86055186 1.92649484  1.95626700
## beta2      0.10593017 0.002658415 0.09175898 -0.07535931 0.04494582  0.10497201
## lambda    13.95848096 0.974444125 9.26601179  3.67843043 8.53661507 11.80221444
## r1         0.02388718 0.001815641 0.01576315  0.01026043 0.01314430  0.01785491
## r2         0.03816322 0.004231446 0.03411368  0.01083829 0.01615244  0.02628364
## sigsq.eps  0.40307782 0.003681697 0.08799969  0.26548543 0.33873822  0.39310969
##                   75%       97.5% n_eff     Rhat valid          Q5         Q50
## beta1      1.98861636  2.04891445  1218 1.000833     1  1.87703291  1.95626700
## beta2      0.16589538  0.29210556  1194 1.001112     1 -0.04661205  0.10497201
## lambda    17.17489007 36.48067829    93 1.009083     1  3.86142689 11.80221444
## r1         0.02913901  0.06679262    80 1.009978     1  0.01085156  0.01785491
## r2         0.04640817  0.13181877    83 1.026150     1  0.01085182  0.02628364
## sigsq.eps  0.45450760  0.60061908   571 1.000022     1  0.27983410  0.39310969
##                   Q95    MCSE_Q2.5     MCSE_Q25    MCSE_Q50    MCSE_Q75
## beta1      2.03734964 0.0021170461 0.0019635347 0.001741340 0.002094780
## beta2      0.25184715 0.0070705251 0.0029934904 0.003334672 0.003703081
## lambda    28.67942227 0.8743516725 0.7130727208 0.896066298 0.858318166
## r1         0.05476273 0.0005792735 0.0006850018 0.001656574 0.003657957
## r2         0.11010608 0.0001766024 0.0015788293 0.002436589 0.006589668
## sigsq.eps  0.56269045 0.0031279911 0.0030804472 0.004000827 0.007075587
##            MCSE_Q97.5     MCSE_SD Bulk_ESS Tail_ESS
## beta1     0.002408374 0.000963078     1219     1219
## beta2     0.005012008 0.001902498     1194     1111
## lambda    5.677054364 0.727212084       80       62
## r1        0.006089716 0.001288853       67       56
## r2        0.011876064 0.003005615       52       39
## sigsq.eps 0.010455310 0.002604683      592     1072
TracePlot(moreiterations, par="beta")
TracePlot(moreiterations, par="r")

plot of chunk continueplot of chunk continue

Acknowledgments

Thanks to Haotian “Howie” Wu for invaluable feedback on early versions of the package.