sample_precision_prior()

Draws precision matrices \(K\) from the prior of a Gaussian graphical model using the same constrained NUTS sampler that drives bgm() for continuous data.

Description

Off-diagonals are placed on the association scale \(K_{yy,ij} = -K_{ij}/2\) and assigned the supplied interaction_prior. A normal_prior(scale = s) therefore constrains \(K_{yy}\) with standard deviation \(s\), equivalent to a \(\mathrm{Normal}(0, 2s)\) prior on \(K_{ij}\) itself. The diagonals \(K_{ii}\) are drawn from the supplied precision_scale_prior. When edge_indicators is supplied, off-diagonals at excluded positions are constrained to zero throughout the chain via RATTLE projection.

Usage

sample_precision_prior(
  p,
  n_samples,
  n_warmup              = 2000L,
  interaction_prior     = cauchy_prior(scale = 2.5),
  precision_scale_prior = gamma_prior(shape = 1, rate = 1),
  step_size             = 0.1,
  max_depth             = 10L,
  seed                  = 1L,
  verbose               = TRUE,
  edge_indicators       = NULL
)

Arguments

Argument Description
p Integer. Dimension of the precision matrix (\(p \ge 2\)).
n_samples Integer. Number of post-warmup draws to keep.
n_warmup Integer. NUTS warmup iterations. Default: 2000.
interaction_prior A bgms_parameter_prior for the off-diagonal entries. Allowed: cauchy_prior(), normal_prior(). beta_prime_prior() is not supported here. Default: cauchy_prior(scale = 2.5).
precision_scale_prior A bgms_scale_prior for the diagonal entries of \(K\). Allowed: gamma_prior(), exponential_prior(). Default: gamma_prior(1, 1).
step_size Positive numeric. Initial NUTS step size used to seed dual-averaging adaptation. Default: 0.1.
max_depth Integer. Maximum NUTS tree depth. Default: 10.
seed Integer. RNG seed for the chain. Default: 1.
verbose Logical. If TRUE (default), print a progress bar.
edge_indicators Optional integer \(p \times p\) matrix with 1 = edge included, 0 = excluded. Must be symmetric with 1s on the diagonal. Default: full graph (all edges included).

Value

A list with components:

Component Description
K_offdiag Numeric matrix n_samples \(\times\) \(p(p-1)/2\) of upper-triangle off-diagonal entries of \(K\) for each draw, in column-major order \((K_{12}, K_{13}, K_{23}, K_{14}, \ldots)\). Excluded edges are returned as 0.
K_diag Numeric matrix n_samples \(\times\) \(p\) of diagonal entries \(K_{11}, \ldots, K_{pp}\).
offdiag_names Character vector of length \(p(p-1)/2\) naming the columns of K_offdiag (e.g. "K_1_2").
diag_names Character vector of length \(p\) naming the columns of K_diag.
step_size The initial NUTS step size used.
edge_indicators The integer edge-indicator matrix used (full graph if not supplied).

Examples

# Default Cauchy(0, 2.5) off-diagonal, Gamma(1, 1) diagonal, p = 4.
draws = sample_precision_prior(
  p = 4, n_samples = 200, n_warmup = 200,
  verbose = FALSE
)
dim(draws$K_offdiag) # 200 x 6
colnames(draws$K_offdiag) = draws$offdiag_names
head(draws$K_offdiag)

# Sparser graph: drop the (1, 4) edge.
E = matrix(1L, 4, 4)
E[1, 4] = E[4, 1] = 0L
draws = sample_precision_prior(
  p = 4, n_samples = 200, n_warmup = 200,
  edge_indicators = E, verbose = FALSE
)
colnames(draws$K_offdiag) = draws$offdiag_names
all(draws$K_offdiag[, "K_1_4"] == 0) # TRUE

See also

cauchy_prior(), normal_prior(), gamma_prior(), exponential_prior(), bgm().