| Title: | Bayesian Factor Modelling via Generalized Lower Triangular Priors |
|---|---|
| Description: | Sparse Bayesian factor models for multivariate data, built around a flexible Generalized Lower Triangular (GLT) process prior on the loading matrix by Canale and Frühwirth-Schnatter (2026) <doi:10.48550/arXiv.2610.09762>. The number of active factors, their sparsity pattern, and the loadings themselves are learned jointly via a Markov chain Monte Carlo sampler implemented in C++ with 'Rcpp' and 'RcppArmadillo'. |
| Authors: | Antonio Canale [aut, cre] |
| Maintainer: | Antonio Canale <[email protected]> |
| License: | GPL-2 |
| Version: | 1.0 |
| Built: | 2026-10-29 17:17:46 UTC |
| Source: | https://github.com/cran/glt |
Fits a Bayesian Gaussian factor model under a Generalized Lower Triangular (GLT) process prior using an MCMC sampler implemented in C++ via Rcpp. The package provides tools for model fitting, posterior summarisation, identification post-processing, and visualisation of loading matrices and variance decompositions.
The main entry point is gltfa(), which accepts a data matrix y (T x m)
and returns a "gltfit" object containing posterior draws and metadata.
gltfa()Fit a GLT factor model via MCMC.
get_variance()Compute posterior draws of the factor and total covariance matrices.
get_pivots()Extract pivot row indices from a binary allocation
matrix Delta.
plot_real_matrix()Visualise a numeric matrix as a colour image using a diverging palette.
Maintainer: Antonio Canale [email protected]
Authors:
Antonio Canale [email protected]
Canale, A. and Frühwirth-Schnatter, S. (2026). "The generalized lower triangular process prior." Technical Report,
A thin wrapper that tags a numeric matrix with class "facmatrix" so that
it is plotted via plot.facmatrix() (a colour-image raster) rather than
via the default matrix print/plot methods.
facmatrix(mat)facmatrix(mat)
mat |
A numeric matrix. |
mat with class "facmatrix" prepended.
For each column of Delta, returns the row index of the first 1, which
defines the pivot row for that factor.
get_pivots(Delta)get_pivots(Delta)
Delta |
An |
An integer vector of length H.
For each saved MCMC draw, computes the matrices
(factor covariance) and
(total marginal covariance), where
.
get_variance(fit)get_variance(fit)
fit |
A |
A named list with two elements:
LLtAn array of
draws.
totalAn array of
draws.
Fits a Bayesian Gaussian factor model under a Generalized Lower Triangular (GLT) process prior using an MCMC sampler implemented in C++ via Rcpp. This is the main user-facing entry point of the package.
gltfa( y, mcmc = list(), Hmax = ncol(y), prior = list(), init = list(), control = list(), fixed = list(), verbose = interactive() )gltfa( y, mcmc = list(), Hmax = ncol(y), prior = list(), init = list(), control = list(), fixed = list(), verbose = interactive() )
y |
A numeric |
mcmc |
A named list of MCMC settings. Recognised fields:
|
Hmax |
A positive integer giving a conservative upper bound for the
number of active factors. Default |
prior |
A named list of prior hyperparameters. Recognised fields:
|
init |
A named list of initial values for the sampler. Recognised fields:
|
control |
A named list of algorithmic and storage options. Recognised fields:
|
fixed |
A named list of logical flags indicating which MCMC updates to
skip. For example, |
verbose |
Logical. Whether to print sampling progress to the console.
Defaults to |
The model is:
where is a sparse lower-triangular loading matrix controlled
by a binary allocation matrix , and
.
Notation and dimensions:
y is a numeric matrix of dimension .
Lambda is a loading matrix of dimension .
Delta is a binary allocation matrix of dimension .
Eta is a factor score matrix of dimension .
An object of class "gltfit", a named list with components:
drawsA named list of posterior draws (if control$store_draws = TRUE):
Lambda (),
Delta (),
sigma2 (),
H (), and optionally
Eta ().
metaA named list with nsave, Hmax, T, m.
inputA named list echoing the processed mcmc, prior,
control, and fixed arguments.
callThe matched call.
Canale, A. and Frühwirth-Schnatter, S. (2026). "The generalized lower triangular process prior." arXiv preprint arXiv:2610.09762.
get_variance(), get_pivots(), plot_real_matrix()
set.seed(42) Y <- matrix(rnorm(200 * 10), nrow = 200, ncol = 10) fit <- gltfa( y = Y, mcmc = list(niter = 2000, nburn = 1000, thin = 1), Hmax = 5, prior = list(a_sigma = 2, b_sigma = 1), init = list(H = 2), control = list(store_draws = TRUE, seed = 1L, random_scan = TRUE), verbose = FALSE )set.seed(42) Y <- matrix(rnorm(200 * 10), nrow = 200, ncol = 10) fit <- gltfa( y = Y, mcmc = list(niter = 2000, nburn = 1000, thin = 1), Hmax = 5, prior = list(a_sigma = 2, b_sigma = 1), init = list(H = 2), control = list(store_draws = TRUE, seed = 1L, random_scan = TRUE), verbose = FALSE )
Fits the Kowal & Canale (2020) simultaneous transformation and rounding
(STAR) extension of gltfa() to discrete-valued (e.g. counts, ordinal)
observed data. A continuous latent matrix z is linked to the observed
matrix y via a column-specific monotone transform G_j and a
column-specific threshold sequence, and modelled with a regression mean
plus the same sparse GLT factor model used by gltfa():
gltfa_star( y, X = NULL, thresholds = NULL, g_type = "exp", mcmc = list(), Hmax = ncol(y), prior = list(), init = list(), control = list(), fixed = list(), verbose = interactive() )gltfa_star( y, X = NULL, thresholds = NULL, g_type = "exp", mcmc = list(), Hmax = ncol(y), prior = list(), init = list(), control = list(), fixed = list(), verbose = interactive() )
y |
An integer (or coercible) |
X |
A numeric |
thresholds |
A list of length |
g_type |
Character vector of length 1 or |
mcmc, Hmax, control, fixed, verbose
|
As in |
prior |
A named list of prior hyperparameters; see
|
init |
A named list of initial values; see
|
Two extra Gibbs steps run before the original 8-step sampler on each
iteration: imputing z from its truncated-normal full conditional (Step
0a), and updating the regression coefficients Beta (Step 0b, conjugate
normal). The residual epsilon = z - X Beta is then fed into the
unchanged Delta/pivots/H/Lambda/sigma2/Eta updates.
An object of class c("gltfit_star", "gltfit"). In addition to
the components documented in gltfa(), draws$Beta holds p x m
draws of the regression coefficients (always stored), and last$z /
last$epsilon hold the final latent-z / residual draws (not stored
across iterations).
Canale, A. and Frühwirth-Schnatter, S. (2026). "The generalized lower triangular process prior." arXiv preprint arXiv:2610.09762,
Kowal, D. and Canale, A. (2020). "Simultaneous transformation and rounding (STAR) models for integer-valued data." Electronic Journal of Statistics, 14(1), 1744-1772.
set.seed(42) Ycounts <- matrix(rpois(100 * 6, lambda = 3), nrow = 100, ncol = 6) fit <- gltfa_star( y = Ycounts, Hmax = 3, mcmc = list(niter = 500, nburn = 250, thin = 1), init = list(H = 1), control = list(store_draws = TRUE, seed = 1L), verbose = FALSE )set.seed(42) Ycounts <- matrix(rpois(100 * 6, lambda = 3), nrow = 100, ncol = 6) fit <- gltfa_star( y = Ycounts, Hmax = 3, mcmc = list(niter = 500, nburn = 250, thin = 1), init = list(H = 1), control = list(store_draws = TRUE, seed = 1L), verbose = FALSE )
Renders a numeric matrix as a raster image using a diverging colour palette
(via signed_palette() by default), with optional grid lines and axis labels.
Rows increase downward (matrix convention).
plot_real_matrix( mat, palette_fun = signed_palette, draw_grid = TRUE, grid_col = "grey80", axes = TRUE, xlab = "column", ylab = "row", asp = 1, main = "", legend = FALSE, legend_n = 100, legend_width = 1.4, legend_digits = 2, v_lines = NULL, h_lines = NULL, ... )plot_real_matrix( mat, palette_fun = signed_palette, draw_grid = TRUE, grid_col = "grey80", axes = TRUE, xlab = "column", ylab = "row", asp = 1, main = "", legend = FALSE, legend_n = 100, legend_width = 1.4, legend_digits = 2, v_lines = NULL, h_lines = NULL, ... )
mat |
A numeric matrix to plot. |
palette_fun |
A function with signature |
draw_grid |
Logical. Whether to draw cell grid lines. Default |
grid_col |
Character. Colour of the grid lines. Default |
axes |
Logical. Whether to draw row and column axes. Default |
xlab |
Character. Label for the horizontal axis. Default |
ylab |
Character. Label for the vertical axis. Default |
asp |
Numeric. Aspect ratio passed to |
main |
Character. Plot title. Default |
legend |
Logical. Whether to draw a colour-scale legend to the right
of the matrix image. Default |
legend_n |
Integer. Number of colour steps used to build the legend
gradient. Default |
legend_width |
Numeric. Width of the legend panel in inches.
Default |
legend_digits |
Integer. Number of decimal digits shown on the
legend axis labels. Default |
v_lines |
Numeric vector or |
h_lines |
Numeric vector or |
... |
Additional arguments forwarded to |
This is the internal workhorse used by plot.facmatrix(); it remains
available for plotting plain numeric matrices directly.
Invisibly NULL; called for its side effect of producing a plot.
signed_palette()
S3 plot method for objects of class "facmatrix". Renders the matrix as
a colour-image raster using signed_palette() by default; see
plot_real_matrix() for the full set of supported arguments.
## S3 method for class 'facmatrix' plot(x, ...)## S3 method for class 'facmatrix' plot(x, ...)
x |
A |
... |
Additional arguments passed on to |
Invisibly x; called for its side effect of producing a plot.
plot_real_matrix(), facmatrix()
Print a "summary.gltfit" object
## S3 method for class 'summary.gltfit' print(x, ...)## S3 method for class 'summary.gltfit' print(x, ...)
x |
A |
... |
Currently unused. |
Invisibly x.
Computes posterior averages (across admissible saved MCMC draws) of
Lambda, Delta, sigma2, and H, along with the
posterior average of , where
. The posterior-mean Lambda,
Delta, and Omega matrices are returned with class
"facmatrix" so they inherit plot.facmatrix().
## S3 method for class 'gltfit' summary(object, ...)## S3 method for class 'gltfit' summary(object, ...)
object |
An object of class |
... |
Currently unused. |
Before averaging, draws are filtered using admissible_draws(): a draw is
dropped when, after removing spurious columns (loadings on a single
variable) and any resulting all-zero rows, the allocation matrix fails
sparvaride::counting_rule_holds(). This mirrors the usual post-processing
step for GLT-type factor models, where unidentified draws (e.g. those with
too few active variables per factor) should not contribute to posterior
summaries of Lambda/Delta.
object$draws$Lambda and object$draws$Delta are stored as
ragged lists of length , each element an matrix ( is the active number of factors for that draw, see
object$draws$H). Kept draws are zero-padded to before elementwise averaging. sigma2 draws are stored as
an matrix, averaged over kept rows.
is computed per kept draw as (using the draw's own, unpadded )
and then averaged.
A named list with class "summary.gltfit" containing:
LambdaPosterior mean loading matrix (),
class "facmatrix".
DeltaPosterior mean allocation matrix (),
class "facmatrix".
sigma2Posterior mean idiosyncratic variances (length ).
HPosterior mean number of active factors (scalar).
OmegaPosterior mean of
(), class "facmatrix".
n_admissibleNumber of draws retained after filtering.
n_totalTotal number of saved draws before filtering.
gltfa(), plot.facmatrix(), sparvaride::counting_rule_holds()