prior
Prior specification helpers.
This module provides helpers for constructing brms-compatible prior specifications and for querying the default priors implied by a model.
Notes
Executed inside the worker process that hosts the embedded R session.
Classes¶
Functions¶
prior(prior, class_=None, coef=None, group=None, dpar=None, resp=None, nlpar=None, lb=None, ub=None, **kwargs)
¶
Create a brms-style prior specification.
This function mirrors the behavior of brms::prior_string() and allows
specifying priors for regression parameters, group-level effects, nonlinear
parameters, distributional parameters, and more — using a typed Python
interface. All arguments correspond directly to the parameters of
prior_string() in brms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prior
|
str
|
The prior definition as a string, exactly as brms expects it. Examples include :: |
required |
class_
|
str
|
Parameter class (e.g. |
None
|
coef
|
str
|
Coefficient name for class-level effects. |
None
|
group
|
str
|
Grouping variable for hierarchical/multilevel effects. |
None
|
dpar
|
str
|
Distributional parameter (e.g. |
None
|
resp
|
str
|
Response variable name for multivariate models. |
None
|
nlpar
|
str
|
Nonlinear parameter name if using nonlinear formulas. |
None
|
lb
|
float
|
Lower bound for truncated priors. |
None
|
ub
|
float
|
Upper bound for truncated priors. |
None
|
**kwargs
|
Any
|
Any additional keyword arguments supported by |
{}
|
Returns:
| Type | Description |
|---|---|
PriorSpec
|
A typed prior specification object used by |
See Also
brms::prior_string : R documentation
Notes
This function does not validate the prior expression string itself — validation occurs inside brms.
Examples:
get_prior(formula, data=None, family='gaussian', **kwargs)
¶
Get default priors for a model specification.
Wrapper around R brms::get_prior().
Returns a DataFrame with default priors for each parameter class in the specified brms model. Useful for reviewing and customizing priors before fitting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str or FormulaConstruct
|
Model formula (e.g. |
required |
data
|
DataFrame or dict
|
Dataset containing model variables. Required for data-dependent priors |
None
|
family
|
str or ListSexpVector
|
Distribution family (e.g., "gaussian", "poisson", "binomial") |
"gaussian"
|
**kwargs
|
Additional arguments passed to brms::get_prior() (e.g., autocor, data2, knots, drop_unused_levels) |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: prior, class, coef, group, resp, dpar, nlpar, lb, ub, source. Each row represents a parameter or parameter class that can have a custom prior. |
See Also
default_prior : Generic function for getting default priors prior : Create custom prior specifications brms::get_prior : R documentation
Examples:
default_prior(object, data=None, family='gaussian', **kwargs)
¶
Get default priors for brms model parameters (generic function).
Wrapper around R brms::default_prior().
Generic function to retrieve default prior specifications for all parameters in a brms model. Accepts formula objects, brmsformula objects, or other model specification objects. This is the generic version of get_prior().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object
|
str, FormulaResult, or ListSexpVector
|
Model specification: formula string, brmsformula object, mvbrmsformula, or any object that can be coerced to these classes |
required |
data
|
DataFrame or dict
|
Dataset containing model variables. Required for data-dependent priors |
None
|
family
|
str or ListSexpVector
|
Distribution family (e.g., "gaussian", "poisson", "binomial"). Can be a list of families for multivariate models |
"gaussian"
|
**kwargs
|
Additional arguments passed to brms::get_prior() (e.g., autocor, data2, knots, drop_unused_levels, sparse) |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: prior, class, coef, group, resp, dpar, nlpar, lb, ub, source. Each row specifies a parameter class with its default prior. The 'prior' column is empty except for internal defaults. |
See Also
get_prior : Convenience function with formula parameter prior : Create custom prior specifications brms::default_prior : R documentation
Examples:
Get default priors for a Poisson model:
from brmspy import brms
priors = brms.default_prior(
object="count ~ zAge + zBase * Trt + (1|patient)",
data=epilepsy,
family="poisson"
)
print(priors)
Use with formula object: