Skip to content

stan

Stan code helpers.

This module exposes wrappers for generating Stan code from brms models without running sampling.

Notes

Executed inside the worker process that hosts the embedded R session.

Classes

Functions

make_stancode(formula, data, priors=None, family='poisson', sample_prior='no', formula_args=None)

Generate Stan code using R brms::make_stancode().

Useful for inspecting the generated Stan model before fitting.

Parameters:

Name Type Description Default
formula str or FormulaConstruct

Model formula.

required
data DataFrame

Model data.

required
priors Sequence[PriorSpec] or None

Optional prior specifications created via brmspy.brms.prior().

None
family str

Distribution family (e.g. "gaussian", "poisson").

"poisson"
sample_prior str

Prior sampling mode passed to brms ("no", "yes", "only").

"no"
formula_args dict or None

Reserved for future use. Currently ignored.

None

Returns:

Type Description
str

Complete Stan program as a string.

See Also

brms::make_stancode : R documentation

Examples:

from brmspy import brms

epilepsy = brms.get_brms_data("epilepsy")
code = brms.make_stancode(
    "count ~ zAge + zBase * Trt + (1|patient)",
    data=epilepsy,
    family="poisson",
)

assert isinstance(code, str)