stan
Classes¶
Functions¶
make_stancode(formula, data, priors=None, family='poisson', sample_prior='no', formula_args=None)
¶
Generate Stan code using brms::make_stancode().
Useful for inspecting the generated Stan model before fitting, understanding the model structure, or using the code with other Stan interfaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str or FormulaResult
|
brms formula specification |
required |
data
|
DataFrame
|
Model data |
required |
priors
|
list of PriorSpec
|
Prior specifications from prior() function |
None
|
family
|
str
|
Distribution family (gaussian, poisson, binomial, etc.) |
"poisson"
|
sample_prior
|
str
|
Whether to sample from prior: - "no": No prior samples - "yes": Include prior samples alongside posterior - "only": Sample from prior only (no data) |
"no"
|
formula_args
|
dict
|
Additional arguments passed to formula() |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Complete Stan program code as string |
See Also
brms::make_stancode : R documentation https://paulbuerkner.com/brms/reference/make_stancode.html fit : Fit model instead of just generating code make_standata : Generate Stan data block
Examples:
Generate Stan code for simple model:
from brmspy import brms
epilepsy = brms.get_brms_data("epilepsy")
stan_code = brms.make_stancode(
formula="count ~ zAge + zBase * Trt + (1|patient)",
data=epilepsy,
family="poisson"
)
print(stan_code[:500]) # Print first 500 characters
With custom priors:
from brmspy import prior
stan_code = brms.make_stancode(
formula="count ~ zAge",
data=epilepsy,
priors=[prior("normal(0, 1)", class_="b")],
family="poisson"
)
For prior predictive checks (sample_prior="only"):