brm
Model fitting wrappers.
This module contains the brms::brm() wrapper used by brmspy.brms.fit() /
brmspy.brms.brm().
Notes
This code executes inside the worker process (the process that hosts the embedded R session).
Classes¶
Functions¶
brm(formula, data, priors=None, family='gaussian', sample_prior='no', sample=True, backend='cmdstanr', formula_args=None, cores=2, *, return_idata=True, **brm_args)
¶
brm(formula: FormulaConstruct | ProxyListSexpVector | str, data: dict | pd.DataFrame, priors: Sequence[PriorSpec] | None = ..., family: str | ListSexpVector | None = ..., sample_prior: str = ..., sample: bool = ..., backend: str = ..., formula_args: dict | None = ..., cores: int | None = ..., *, return_idata: Literal[True] = True, **brm_args: Any) -> FitResult
brm(formula: FormulaConstruct | ProxyListSexpVector | str, data: dict | pd.DataFrame, priors: Sequence[PriorSpec] | None = ..., family: str | ListSexpVector | None = ..., sample_prior: str = ..., sample: bool = ..., backend: str = ..., formula_args: dict | None = ..., cores: int | None = ..., *, return_idata: Literal[False], **brm_args: Any) -> ProxyListSexpVector
Fit a Bayesian regression model with brms.
This is a thin wrapper around R brms::brm() that returns a structured
FitResult (including an ArviZ InferenceData).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str or FormulaConstruct
|
Model formula. Accepts a plain brms formula string (e.g. |
required |
data
|
dict or DataFrame
|
Model data. |
required |
priors
|
Sequence[PriorSpec] or None
|
Optional prior specifications created via |
None
|
family
|
str or ListSexpVector or None
|
brms family specification (e.g. |
"gaussian"
|
sample_prior
|
str
|
Passed to brms. Common values: |
"no"
|
sample
|
bool
|
If |
True
|
backend
|
str
|
Stan backend. Common values: |
"cmdstanr"
|
formula_args
|
dict or None
|
Reserved for future use. Currently ignored. |
None
|
cores
|
int or None
|
Number of cores for brms/cmdstanr. |
2
|
return_idata
|
bool
|
When working with large datasets, you might not want the full idata. when False, you get the R object proxy which can be forwarded to posterior_epred or other functions |
True
|
**brm_args
|
Additional keyword arguments passed to R |
{}
|
Returns:
| Type | Description |
|---|---|
FitResult
|
Result object with |
See Also
brms::brm : R documentation
Warnings
Using cores <= 1 can be unstable in embedded R sessions and may crash the
worker process. Prefer cores >= 2.
Examples: