Learn R Programming

BayesTools (version 0.3.0)

posterior_extraction_helpers: Helper functions for extracting and formatting posterior distributions

Description

Internal helper functions to extract posterior samples from JAGS fits and reformat them for further processing (summary tables, diagnostics, plots). These functions consolidate common logic that was duplicated across runjags_estimates_table, .diagnostics_plot_data, and plotting functions.

Helper to remove all columns associated with a parameter

Usage

.extract_posterior_samples(fit, as_list = FALSE)

.remove_auxiliary_parameters( model_samples, prior_list, remove_parameters = NULL )

.remove_parameter_columns(model_samples, prior, par_name)

.filter_parameters( prior_list, remove_parameters = NULL, remove_formulas = NULL, keep_parameters = NULL, keep_formulas = NULL, remove_spike_0 = TRUE )

.process_spike_and_slab( model_samples, prior_list, par, conditional = FALSE, remove_inclusion = FALSE, warnings = NULL )

.apply_parameter_transformations( model_samples, transformations, prior_list, transform_factors = FALSE )

.transform_factor_contrasts( model_samples, prior_list, transform_factors = FALSE, transformations = NULL )

.rename_factor_levels(model_samples, prior_list)

Value

matrix or mcmc.list of posterior samples

list with cleaned model_samples and updated prior_list

updated model_samples matrix

list with filtered model_samples and prior_list

list with updated model_samples, prior_list, and warnings

updated model_samples matrix

updated model_samples matrix

updated model_samples matrix with renamed columns

Arguments

fit

a JAGS model fit object

as_list

whether to return samples as mcmc.list (TRUE) or merged matrix (FALSE)

model_samples

matrix of posterior samples

prior_list

list of prior objects

remove_parameters

character vector of parameter names to remove, or TRUE to remove all non-formula parameters. If "bias" is specified and the bias prior contains PET, PEESE, or weightfunction priors, the corresponding parameters (PET, PEESE, omega) are also added to the removal list.

prior

prior object for the parameter

par_name

name of the parameter

remove_formulas

character vector of formula names whose parameters should be removed

keep_parameters

character vector of parameter names to keep (all others removed unless in keep_formulas). If "bias" is specified and the bias prior contains PET, PEESE, or weightfunction priors, the corresponding parameters (PET, PEESE, omega) are also added to the keep list.

keep_formulas

character vector of formula names whose parameters should be kept (all others removed unless in keep_parameters)

remove_spike_0

whether to remove spike at 0 priors

par

parameter name

conditional

whether to compute conditional summary

remove_inclusion

whether to remove inclusion indicators

warnings

character vector for collecting warnings

transformations

list of transformations to apply

transform_factors

whether to transform orthonormal/meandif to differences