Gibbs sampler for the Bradley–Terry Stochastic Block Model (BT–SBM)
Source:R/gibbs_bt_sbm.R
gibbs_bt_sbm.RdRuns a Gibbs sampler for the BT–SBM with optional DP/PY/DM/GN priors on
the partition. Returns raw draws plus minimal summaries; n_ij is
computed internally as w_ij + t(w_ij).
Arguments
- w_ij
Integer or numeric square matrix \(n \times n\) of directed wins (i over j). Must be nonnegative with zero diagonal. The function builds \(n_{ij} = w_{ij} + w_{ji}\) internally.
- a, b
Positive shape and rate parameters for the Gamma prior \(\lambda_k \sim \mathrm{Gamma}(a,b)\). By default, \(b = \exp(\psi(a))\), so that \(\mathbb{E}[\log \lambda_k] = 0\) a priori.
- prior
Character scalar, one of
"DP","PY","DM","GN".- alpha_PY, sigma_PY
Hyperparameters for Pitman–Yor / Dirichlet Process. For
prior="DP"usealpha_PY(withsigma_PYignored). Forprior="PY"use bothalpha_PYandsigma_PY in (0,1).- beta_DM, K_DM
Hyperparameters for the finite Dirichlet–Multinomial prior.
K_DMis the maximum number of allowed clusters.- gamma_GN
Hyperparameter for the Gnedin prior.
- T_iter, T_burn
Integers: total iterations and burn-in. Must satisfy
T_burn < T_iter.- init_x
Optional integer vector of length
nwith initial labels (1-based).- store_z
Logical; if
TRUE, store latentZdraws (heavy).- verbose
Logical; if
TRUE, prints progress every 1000 iterations.
Value
A list with:
x_samples: integer matrix \(S \times n\) of raw labels (\(S = T_{\mathrm{iter}}-T_{\mathrm{burn}}\)).lambda_samples: list of length \(S\); each element is a numeric vector of length \(L_{\mathrm{cap}}\) for that draw, withNAat empty labels.K_per_iter: integer vector length \(S\) (occupied cluster count per saved draw).L_cap_per_iter: integer vector length \(S\) (label capacity trace).z_samples: ifstore_z=TRUE, a numeric array \(S \times n \times n\); otherwiseNULL.
Details
Row names of w_ij (if present) are propagated to item-level outputs;
otherwise items are named Item_1, ..., Item_n.