bayesvl-stan-utilities | R Documentation |
Functions to generate Stan code and run simulations using a model object of class bayesvl
, which represents a Bayesian directed acyclic graph (DAG).
bvl_model2Stan(dag, ppc = "")
bvl_modelFit(dag, data, warmup = 1000, iter = 5000, chains = 2, ppc = "", ...)
bvl_stanPriors(dag)
bvl_stanParams(dag)
bvl_formula (dag, nodeName, outcome = T, re = F)
bvl_stanLikelihood (dag)
bvl_stanLoo (dag, ...)
bvl_stanWAIC (dag, ...)
dag |
An object of class |
data |
A data frame or list containing the observed data for model fitting. |
warmup |
Number of warmup iterations; defaults to half of |
iter |
Total number of iterations for sampling. Default is 5000. |
chains |
Number of MCMC chains to run. Default is 2. |
ppc |
Optional: a character string containing Stan code for posterior predictive checks. |
... |
Additional arguments passed to underlying functions. |
nodeName |
The name of the node to generate formula for. |
outcome |
Logical. Whether to include outcome distribution. Default is |
re |
Logical. Whether to recursively trace all upstream nodes. Default is |
The following outputs are returned depending on the function used:
bvl_model2Stan
: Returns a character string containing the generated Stan model code.
bvl_modelFit
: Returns an object of class bayesvl
with the following slots:
model
: The Stan model code.
stanfit
: A stanfit
object returned by rstan
.
standata
: The data list used in sampling.
pars
: A list of parameter names being monitored.
formula
: The formula representation of the model.
bvl_stanPriors
: Returns a character string of the prior distributions used in the model.
bvl_stanParams
: Returns a character string of parameter block content for Stan.
bvl_formula
: Returns the formula associated with the specified node.
La Viet-Phuong, Vuong Quan-Hoang
For documentation, case studies, worked examples, and other tutorial materials, see:
# Design the model using a directed acyclic graph
model <- bayesvl()
model <- bvl_addNode(model, "Lie", "binom")
model <- bvl_addNode(model, "B", "binom")
model <- bvl_addNode(model, "C", "binom")
model <- bvl_addNode(model, "T", "binom")
model <- bvl_addArc(model, "B", "Lie", "slope")
model <- bvl_addArc(model, "C", "Lie", "slope")
model <- bvl_addArc(model, "T", "Lie", "slope")
# Generate Stan model code
model_string <- bvl_model2Stan(model)
cat(model_string)
# Display priors in generated Stan model
bvl_stanPriors(model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.