| VB_Fit | R Documentation |
VB fit object
VB fit object
An R6 class storing posterior samples and related information from Automatic Differentiation Variational Inference (ADVI).
BayesRTMB::RTMB_Fit_Base -> advi_fit
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.
get_point_estimate()Get point estimate for a target parameter.
VB_Fit$get_point_estimate(target, chains = NULL, best_chains = NULL)
targetTarget parameter name.
chainsNumeric vector of chains to include. If NULL, the best chain is used.
best_chainsInteger; number of best chains to retain based on ELBO.
Matrix, array, vector, or scalar point estimate.
estimate()Get point estimates from variational draws.
VB_Fit$estimate(
pars = NULL,
type = c("mean", "EAP", "marginal_map", "joint_map", "MAP"),
component = c("all", "parameters", "transform", "generate"),
chains = NULL,
best_chains = NULL,
drop = TRUE,
...
)parsOptional character or numeric vector of parameter names or indices to extract. Supports special keywords: "parameters", "transform", "generate", and "all".
typeCharacter string specifying the estimation type.
componentCharacter string specifying the component to filter by.
chainsNumeric vector of chains to include. If NULL, the best chain is used.
best_chainsNumber of best chains to include.
dropLogical; if TRUE and only one parameter is selected, return the value directly instead of a list.
...Additional arguments passed to draws().
A named list of point estimates, or a single value if 'drop = TRUE'.
EAP()Calculate Expected A Posteriori (EAP) estimates from the best variational estimate by default.
VB_Fit$EAP( pars = "parameters", chains = NULL, best_chains = NULL, drop = TRUE, ... )
parsOptional character vector of parameter names to extract.
chainsNumeric vector of chains to include. If NULL, the best chain is used.
best_chainsNumber of best chains to include.
dropLogical; whether to drop the list if only one parameter is selected.
...Additional arguments passed to 'estimate()'.
A named list of EAP estimates.
MAP()Calculate Maximum A Posteriori (MAP) estimates from the best variational estimate by default.
VB_Fit$MAP(
pars = "parameters",
chains = NULL,
best_chains = NULL,
type = c("marginal", "joint"),
drop = TRUE,
...
)parsOptional character vector of parameter names to extract.
chainsNumeric vector of chains to include. If NULL, the best chain is used.
best_chainsNumber of best chains to include.
typeCharacter string; "marginal" or "joint" MAP.
dropLogical; whether to drop the list if only one parameter is selected.
...Additional arguments passed to 'estimate()'.
A named list of MAP estimates.
new()Create a new 'VB_Fit' object.
VB_Fit$new( model, fit, random_fit, elbo_history, laplace, posterior_mean, ELBO, rel_obj_vals, best_chain, mu_history )
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.
print()Print a brief summary of the fitted object.
VB_Fit$print(...)
...Additional arguments passed to the 'summary' method.
The object itself, invisibly.
draws()Extract posterior draws for selected parameters.
VB_Fit$draws( pars = NULL, chains = NULL, best_chains = NULL, inc_random = FALSE, inc_transform = TRUE, inc_generate = TRUE, best_only = FALSE )
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.
A 3D array of posterior draws '[iterations, chains, parameters]'.
summary()Summarize posterior draws.
VB_Fit$summary( pars = NULL, max_rows = 10, digits = 2, inc_random = FALSE, inc_transform = TRUE, inc_generate = TRUE )
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.
A data frame containing the summarized posterior statistics.
plot_elbo()Plot the ELBO history to diagnose convergence.
VB_Fit$plot_elbo(tail_n = 1000, ests = NULL, type = "l", ...)
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.
The object itself, invisibly.
plot_trajectory()Plot the parameter trajectory from the final optimization window.
VB_Fit$plot_trajectory(pars = NULL, type = "l", ...)
parsCharacter vector specifying the names of parameters to plot. If NULL, plots all available parameters.
typeCharacter string; the type of plot. Default is "l" (lines).
...Additional arguments passed to the 'matplot' function.
The object itself, invisibly.
transformed_draws()Compute transformed parameters from posterior draws.
VB_Fit$transformed_draws(
tran_fn = NULL,
progress = c("auto", "none", "bar", "message"),
tape = c("auto", "none", "force")
)tran_fnAn optional user-supplied function that takes data and parameter lists to return transformed quantities.
progressProgress reporting style: '"auto"', '"none"', '"bar"', or '"message"'. '"auto"' and '"bar"' use line-based messages.
tapeDerived-quantity evaluation mode. '"auto"' tries RTMB tape evaluation and falls back to R evaluation on error; '"none"' always uses R evaluation; '"force"' requires tape evaluation and errors if it fails.
The 'VB_Fit' object itself, invisibly.
generated_quantities()Compute generated quantities from posterior draws.
VB_Fit$generated_quantities(
code,
progress = c("auto", "none", "bar", "message"),
tape = c("auto", "none", "force")
)codeAn 'rtmb_code({ ... })' or '{ ... }' block containing the logic to be calculated using posterior samples.
progressProgress reporting style: '"auto"', '"none"', '"bar"', or '"message"'. '"auto"' and '"bar"' use line-based messages.
tapeDerived-quantity evaluation mode. '"auto"' tries RTMB tape evaluation and falls back to R evaluation on error; '"none"' always uses R evaluation; '"force"' requires tape evaluation and errors if it fails.
The 'VB_Fit' object itself (invisibly). Results are added to the 'generate_fit' field. Existing generated quantities with the same name are replaced.
WAIC()Compute WAIC from pointwise generated log likelihood.
VB_Fit$WAIC(...)
...Additional arguments passed to 'draws()', such as 'chains' or 'best_chains'.
A 'waic_BayesRTMB' object.
diagnose()Run basic diagnostics for the variational fit.
VB_Fit$diagnose(...)
...Additional arguments passed to 'diagnose_vb_fit()'.
A 'diagnose_BayesRTMB' object.
clone()The objects of this class are cloneable with this method.
VB_Fit$clone(deep = FALSE)
deepWhether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.