TEbrm_advi: Run a brm model with ADVI

View source: R/TEbrm_advi.R

TEbrm_adviR Documentation

Run a brm model with ADVI

Description

Uses Stan's stochastic gradient ascent methods "fullrank" or "meanfield" rather than full Bayesian sampling. Is likely to be faster than typical sampling for large models, but possibly less accurate. This function fits the model several times and returns the best model (initial model selection uses Bayesian R-squared, final model selection uses 10-fold cross-validation). Beware: This re-fitting has a tendency to crash R sometimes.

Usage

TEbrm_advi(
  formIn,
  dataIn = data.frame(),
  ...,
  algorithm = "fullrank",
  conv_thresh = 0.5,
  quiet = F
)

Arguments

formIn

Model formula, as in brm.

dataIn

Data, as in brm.

...

Any other argument to pass to brm.

algorithm

Which ADVI algorithm to use: "meanfield" or "fullrank".

conv_thresh

Re-fit models are compared, with the standardized distance (mean_diff / SD) being calculated. Models keep being re-fit until at least 2 models' largest standardized differences are smaller than this value (or until a certain number of models has been fit in total, which scales inversely with this value). The better-fitting of these two models is then returned. Values over 30 will cause an error, which should not be an issue for any normal use of this function.

quiet

Progress is printed by default, but can be suppressed with quiet=T.

Details

Stochastic gradient ascent in Stan uses Automatic Differentiation Variational Inference (ADVI).

Note

Re-fitting a model within this function is not comprehensive. If using ADVI, it is recommended to use TEbrm_advi multiple times, and choose the best using comparisons of fit, such as fit_model$criteria$kfold (estimated using add_criterion(fit_model,'kfold')).

See Also

vb and http://mc-stan.org

Examples

## Not run: 
## can be used in place of brm
m <- TEbrm_advi(ratio ~ resp, anstrain_s1)
summary(m)
conditional_effects(m)

## Use in the context of TEfits
m1 <- TEbrm(
acc ~ tef_change_expo3('trialNum')
,data = anstrain_s1,
,algorithm = 'meanfield'
)


## End(Not run)

akcochrane/TEfits documentation built on June 12, 2025, 11:10 a.m.