VB fit object
VB fit object
Details
An R6 class storing posterior samples and related information from Automatic Differentiation Variational Inference (ADVI).
Super class
BayesRTMB::RTMB_Fit_Base -> advi_fit
Public fields
modelAn `RTMB_Model` object used for estimation.
fitA 3D array of posterior draws for fixed model parameters.
random_fitA 3D array of posterior draws for random effects, if available.
transform_fitA 3D array of posterior draws for transformed parameters, if available.
generate_fitA 3D array of posterior draws for generated quantities, if available.
transform_dimsA list storing dimension information for transformed parameters.
generate_dimsA list storing dimension information for generated quantities.
elbo_historyA list of numeric vectors storing the Evidence Lower Bound (ELBO) history during optimization for each chain.
laplaceLogical; whether Laplace approximation was used to marginalize random effects.
posterior_meanA named numeric vector of posterior mean estimates.
ELBOA numeric vector of final ELBO values for each chain.
rel_obj_valsA numeric vector of final relative objective tolerance values for each chain.
best_chainInteger; the index of the chain with the maximum ELBO.
mu_historyMatrix of the parameter trajectory from the final window.
Methods
Method new()
Create a new `VB_Fit` object.
Usage
VB_Fit$new(
model,
fit,
random_fit,
elbo_history,
laplace,
posterior_mean,
ELBO,
rel_obj_vals,
best_chain,
mu_history
)Arguments
modelAn `RTMB_Model` object.
fitA 3D array of parameter draws.
random_fitA 3D array of random effect draws.
elbo_historyA list of numeric vectors of ELBO values for each chain.
laplaceLogical; indicates if Laplace approximation was used.
posterior_meanA named numeric vector of posterior means.
ELBOA numeric vector of final ELBO values for each chain.
rel_obj_valsA numeric vector of final relative objective tolerance values for each chain.
best_chainInteger; the index of the chain with the maximum ELBO.
mu_historyMatrix of the parameter trajectory from the final window.
Method print()
Print a brief summary of the fitted object.
Method draws()
Extract posterior draws for selected parameters.
Usage
VB_Fit$draws(
pars = NULL,
chains = NULL,
best_chains = NULL,
inc_random = FALSE,
inc_transform = TRUE,
inc_generate = TRUE,
best_only = FALSE
)Arguments
parsCharacter or numeric vector specifying the names or indices of parameters to extract. If NULL, all available parameters are extracted.
chainsNumeric vector specifying the chains to extract. If NULL, draws from all chains are returned.
best_chainsInteger; number of best chains to retain based on ELBO. If supplied, chains with the highest ELBO are retained.
inc_randomLogical; whether to include random effects in the output. Default is FALSE.
inc_transformLogical; whether to include transformed parameters in the output. Default is TRUE.
inc_generateLogical; whether to include generated quantities in the output. Default is TRUE.
best_onlyLogical; whether to extract only from the chain with the maximum ELBO. Default is FALSE unless explicitly requested.
Method summary()
Summarize posterior draws.
Usage
VB_Fit$summary(
pars = NULL,
max_rows = 10,
digits = 2,
inc_random = FALSE,
inc_transform = TRUE,
inc_generate = TRUE
)Arguments
parsCharacter or numeric vector specifying the names or indices of parameters to summarize. If NULL, all available parameters are summarized.
max_rowsInteger; maximum number of rows to print in the summary table. Default is 10.
digitsInteger; number of decimal places to print. Default is 2.
inc_randomLogical; whether to include random effects in the summary. Default is FALSE.
inc_transformLogical; whether to include transformed parameters in the summary. Default is TRUE.
inc_generateLogical; whether to include generated quantities in the summary. Default is TRUE.
Method plot_elbo()
Plot the ELBO history to diagnose convergence.
Arguments
tail_nInteger; the number of recent iterations to plot. If NULL, plots the entire history. Default is 2000.
estsCharacter string `"best"`, numeric vector of estimate indices (e.g., `c(1, 3)`), or `NULL` to plot all. Default is `NULL`.
typeCharacter string; the type of plot. Default is "l" (lines).
...Additional arguments passed to the `plot` function.
Method plot_trajectory()
Plot the parameter trajectory from the final optimization window.
Method transformed_draws()
Compute transformed parameters from posterior draws.
Method generated_quantities()
Compute generated quantities from posterior draws.