Convenience wrapper around compress_posterior() for brms::brmsfit objects. Returns a list with both the compressed posterior and the original fit structure (with fit$fit cleared) so the model can be reconstructed later via reconstruct_brmsfit().

compress_brmsfit(
  brmsfit,
  method = c("mclust", "mvdens_gmm", "mvdens_kde"),
  variables = NULL,
  n_components = 3L,
  model_name = NULL,
  verbose = FALSE,
  ...
)

Arguments

brmsfit

A brms::brmsfit object using the cmdstanr backend.

method

One of 'mclust', 'mvdens_gmm', 'mvdens_kde'. See compression_methods().

variables

Optional character vector of parameter names to keep. If NULL (default) all columns are used.

n_components

Integer number of mixture components (used by "mclust" and "mvdens_gmm"). Default 3.

model_name

mclust covariance structure (e.g. "VVV", "EEE", or a vector of allowed model names). Ignored by other methods. When NULL (default) poco auto-selects a sensible set: the spherical and diagonal models c("EII", "VII", "EEI", "EVI", "VEI", "VVI") are used when nrow(draws) <= ncol(draws) so covariances remain identifiable, otherwise mclust's full default set is used and BIC picks the best.

verbose

Logical; print backend progress. Default FALSE.

...

Additional arguments forwarded to the backend (e.g. mclust::Mclust()).

Value

A list with two elements:

compressed

a posterior_compressed object;

structure

the brmsfit (so reconstruct_brmsfit() can rebuild a usable model).

Details

Requires the brms model to have been fit with backend = "cmdstanr". Draws are extracted via posterior::as_draws_matrix(), so brms's user-facing parameter names (e.g. b_x, sd_group__Intercept) are preserved.

Examples

if (FALSE) { # \dontrun{
fit <- brms::brm(y ~ x, data = dat, backend = "cmdstanr")
result <- compress_brmsfit(fit, method = "mclust", n_components = 5)

saveRDS(result$compressed, "model_compressed.rds", compress = "xz")
saveRDS(result$structure,  "model_structure.rds")

fit_recon <- reconstruct_brmsfit(result)
} # }