Learn R Programming

lame (version 1.3.4)

rhat_dynamic_beta: Multivariate split-R-hat for dynamic_beta coefficient paths

Description

Given one or more multi-chain lame fits whose $BETA is [n_iter, p, T], computes the multivariate R-hat per coefficient \(k\) treating the length-\(T\) path as one multivariate observation per iteration.

Usage

rhat_dynamic_beta(fit_list, coefs = NULL)

Value

Data frame with one row per coefficient: coef, rhat_mvt, rhat_max_univariate, n_chains, n_iter_per_chain, n_periods. rhat_mvt is the Brooks-Gelman multivariate statistic; rhat_max_univariate

is the max over per-(k,t) split-R-hat values for comparison.

Arguments

fit_list

A list of fitted lame objects from lame_parallel(..., chains = K), or any ame_chain_list produced by re-running lame() with different seeds.

coefs

Optional character vector of coefficient names to subset (matches dimnames(fit$BETA)[[2]]).

Details

For chain \(c\), let \(\beta^{(c)}_t \in \mathbb{R}^T\) be the path. With \(m\) chains and \(n\) iterations per chain, define $$W_k = \tfrac{1}{m}\sum_c S_c^{(k)}, \quad B_k = \tfrac{n}{m-1}\sum_c (\bar\beta_c^{(k)} - \bar\beta^{(k)})(\bar\beta_c^{(k)} - \bar\beta^{(k)})'$$ where \(S_c^{(k)}\) is the within-chain sample covariance of path \(k\) in chain \(c\). Then \(V_k = ((n-1)/n) W_k + ((m+1)/(mn)) B_k\) and \(\hat R_k^{mvt} = \sqrt{\lambda_{\max}(W_k^{-1} V_k)}\). For nearly degenerate covariances we add a tiny ridge to \(W_k\).

Examples

Run this code
# \donttest{
data(YX_bin_list)
# note: pass seed = to lame() -- an external set.seed() does not vary
# the sampler, so it would produce identical chains
fit_list <- lapply(c(1L, 2L), function(s) {
  lame(YX_bin_list$Y, YX_bin_list$X, family = "binary", R = 0,
       dynamic_beta = "dyad", seed = s,
       nscan = 60, burn = 15, odens = 5, verbose = FALSE)
})
rhat_dynamic_beta(fit_list)
# }

Run the code above in your browser using DataLab