vb | R Documentation |

Approximately draw from a posterior distribution using variational inference.

This is still considered an experimental feature.
We recommend calling `stan`

or `sampling`

for
final inferences and only using `vb`

to get a rough idea of the parameter
distributions.

## S4 method for signature 'stanmodel' vb(object, data = list(), pars = NA, include = TRUE, seed = sample.int(.Machine$integer.max, 1), init = 'random', check_data = TRUE, sample_file = tempfile(fileext = '.csv'), algorithm = c("meanfield", "fullrank"), importance_resampling = FALSE, keep_every = 1, ...)

`object` |
An object of class |

`data` |
A named |

`pars` |
If not |

`include` |
Logical scalar defaulting to |

`seed` |
The seed for random number generation. The default is generated
from 1 to the maximum integer supported by |

`init` |
Initial values specification. See the detailed documentation for
the init argument in |

`check_data` |
Logical, defaulting to |

`sample_file` |
A character string of file name for specifying where to
write samples for |

`algorithm` |
Either |

`importance_resampling` |
Logical scalar (defaulting to |

`keep_every` |
Integer scalar (defaulting to 1) indicating the interval
by which to thin the draws when |

`...` |
Other optional parameters: -
`iter` (positive`integer` ), the maximum number of iterations, defaulting to 10000. -
`grad_samples` (positive`integer` ), the number of samples for Monte Carlo estimate of gradients, defaulting to 1. -
`elbo_samples` (positive`integer` ), the number of samples for Monte Carlo estimate of ELBO (objective function), defaulting to 100. (ELBO stands for "the evidence lower bound".) -
`eta` (`double` ), positive stepsize weighting parameter for variational inference but is ignored if adaptation is engaged, which is the case by default. -
`adapt_engaged` (`logical` ), a flag indicating whether to automatically adapt the stepsize, defaulting to`TRUE` . -
`tol_rel_obj` (positive`double` ), the convergence tolerance on the relative norm of the objective, defaulting to 0.01. -
`eval_elbo` (positive`integer` ), evaluate ELBO every Nth iteration, defaulting to 100. -
`output_samples` (positive`integer` ), number of posterior samples to draw and save, defaults to 1000. -
`adapt_iter` (positive`integer` ), the maximum number of iterations to adapt the stepsize, defaulting to 50. Ignored if`adapt_engaged = FALSE` .
Refer to the manuals for both CmdStan and Stan for more details. |

An object of `stanfit-class`

.

- vb
`signature(object = "stanmodel")`

Call Stan's variational Bayes methods
for the model defined by S4 class `stanmodel`

given the data, initial values, etc.

The Stan Development Team
*Stan Modeling Language User's Guide and Reference Manual*.
https://mc-stan.org.

The Stan Development Team
*CmdStan Interface User's Guide*.
https://mc-stan.org.

`stanmodel`

The manuals of CmdStan and Stan.

## Not run: m <- stan_model(model_code = 'parameters {real y;} model {y ~ normal(0,1);}') f <- vb(m) ## End(Not run)

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.