Types
Result types for brmspy functions.
Classes¶
PriorSpec
dataclass
¶
Python representation of a brms prior specification.
This dataclass provides a typed interface to brms::prior_string() arguments,
allowing Python developers to specify priors with IDE autocomplete and
type checking. Use the prior() factory function to create instances.
Attributes:
| Name | Type | Description |
|---|---|---|
prior |
str
|
Prior distribution as string (e.g., "normal(0, 1)", "exponential(2)") |
class_ |
(str, optional)
|
Parameter class: "b" (fixed effects), "sd" (group SD), "Intercept", "sigma", "cor", etc. |
coef |
(str, optional)
|
Specific coefficient name for class-level priors |
group |
(str, optional)
|
Grouping variable for hierarchical effects |
dpar |
(str, optional)
|
Distributional parameter (e.g., "sigma", "phi", "zi") |
resp |
(str, optional)
|
Response variable for multivariate models |
nlpar |
(str, optional)
|
Non-linear parameter name |
lb |
(float, optional)
|
Lower bound for truncated priors |
ub |
(float, optional)
|
Upper bound for truncated priors |
See Also
prior : Factory function to create PriorSpec instances brms::prior_string : R documentation https://paulbuerkner.com/brms/reference/prior_string.html
Examples:
Create prior specifications (prefer using prior() function):
from brmspy.types import PriorSpec
# Fixed effect prior
p1 = PriorSpec(prior="normal(0, 1)", class_="b")
# Group-level SD prior
p2 = PriorSpec(
prior="exponential(2)",
class_="sd",
group="patient"
)
# Coefficient-specific prior with bounds
p3 = PriorSpec(
prior="normal(0, 1)",
class_="b",
coef="age",
lb=0 # Truncated at zero
)
IDFit
¶
Bases: InferenceData
Typed InferenceData for fitted brms models.
Extends arviz.InferenceData with type hints for IDE autocomplete.
Guarantees the presence of specific data groups returned by fit().
Attributes:
| Name | Type | Description |
|---|---|---|
posterior |
Dataset
|
Posterior samples of model parameters |
posterior_predictive |
Dataset
|
Posterior predictive samples (with observation noise) |
log_likelihood |
Dataset
|
Log-likelihood values for each observation |
observed_data |
Dataset
|
Original observed response data |
coords |
dict
|
Coordinate mappings for dimensions |
dims |
dict
|
Dimension specifications for variables |
See Also
brmspy.brms.fit : Creates IDFit objects arviz.InferenceData : Base class documentation
Examples:
from brmspy import brms
model = brms.fit("y ~ x", data=df, chains=4)
# Type checking and autocomplete
assert isinstance(model.idata, IDFit)
print(model.idata.posterior) # IDE autocomplete works!
IDEpred
¶
Bases: InferenceData
Typed InferenceData for posterior_epred results.
Contains expected values E[Y|X] without observation noise.
Attributes:
| Name | Type | Description |
|---|---|---|
posterior |
Dataset
|
Expected value samples (no observation noise) |
See Also
brmspy.brms.posterior_epred : Creates IDEpred objects
IDPredict
¶
Bases: InferenceData
Typed InferenceData for posterior_predict results.
Contains posterior predictive samples with observation noise.
Attributes:
| Name | Type | Description |
|---|---|---|
posterior_predictive |
Dataset
|
Posterior predictive samples (includes observation noise) |
See Also
brmspy.brms.posterior_predict : Creates IDPredict objects
IDLinpred
¶
Bases: InferenceData
Typed InferenceData for posterior_linpred results.
Contains linear predictor values (before applying link function).
Attributes:
| Name | Type | Description |
|---|---|---|
predictions |
Dataset
|
Linear predictor samples |
See Also
brmspy.brms.posterior_linpred : Creates IDLinpred objects
IDLogLik
¶
Bases: InferenceData
Typed InferenceData for log_lik results.
Contains log-likelihood values for model comparison.
Attributes:
| Name | Type | Description |
|---|---|---|
log_likelihood |
Dataset
|
Log-likelihood values for each observation |
See Also
brmspy.brms.log_lik : Creates IDLogLik objects arviz.loo : LOO-CV using log-likelihood
RListVectorExtension
dataclass
¶
Generic result container with R objects.
Attributes:
| Name | Type | Description |
|---|---|---|
r |
ListVector
|
R object from brms |
GenericResult
dataclass
¶
Bases: RListVectorExtension
Generic result container with arviz and R objects.
Attributes:
| Name | Type | Description |
|---|---|---|
idata |
InferenceData
|
arviz InferenceData object |
r |
ListVector
|
R object from brms |
FitResult
dataclass
¶
Bases: RListVectorExtension
Result from fit() function.
Attributes:
| Name | Type | Description |
|---|---|---|
idata |
InferenceData
|
arviz InferenceData with posterior, posterior_predictive, log_likelihood, and observed_data groups |
r |
ListVector
|
brmsfit R object from brms::brm() |
PosteriorEpredResult
dataclass
¶
Bases: RListVectorExtension
Result from posterior_epred() function.
Attributes:
| Name | Type | Description |
|---|---|---|
idata |
InferenceData
|
arviz InferenceData with expected values in 'posterior' group |
r |
ListVector
|
R matrix from brms::posterior_epred() |
PosteriorPredictResult
dataclass
¶
Bases: RListVectorExtension
Result from posterior_predict() function.
Attributes:
| Name | Type | Description |
|---|---|---|
idata |
InferenceData
|
arviz InferenceData with predictions in 'posterior_predictive' group |
r |
ListVector
|
R matrix from brms::posterior_predict() |
LogLikResult
dataclass
¶
Bases: RListVectorExtension
Result from log_lik() function.
Attributes:
| Name | Type | Description |
|---|---|---|
idata |
IDLogLik
|
arviz InferenceData with log-likelihood values |
r |
ListVector
|
R matrix from brms::log_lik() |
See Also
brmspy.brms.log_lik : Creates LogLikResult objects
Examples:
from brmspy import brms
import arviz as az
model = brms.fit("y ~ x", data=df, chains=4)
loglik = brms.log_lik(model)
# Use for model comparison
loo = az.loo(model.idata)
print(loo)
PosteriorLinpredResult
dataclass
¶
Bases: RListVectorExtension
Result from posterior_linpred() function.
Attributes:
| Name | Type | Description |
|---|---|---|
idata |
IDLinpred
|
arviz InferenceData with linear predictor values |
r |
ListVector
|
R matrix from brms::posterior_linpred() |
See Also
brmspy.brms.posterior_linpred : Creates PosteriorLinpredResult objects
Examples:
from brmspy import brms
model = brms.fit("count ~ age", data=df, family="poisson", chains=4)
linpred = brms.posterior_linpred(model)
# Linear predictor on log scale (for Poisson)
print(linpred.idata.predictions)
FormulaResult
dataclass
¶
Bases: RListVectorExtension
Result from formula() function.
Attributes:
| Name | Type | Description |
|---|---|---|
r |
ListVector
|
R brmsformula object |
dict |
Dict
|
Python dictionary representation of formula |
See Also
brmspy.brms.formula : Creates FormulaResult objects
Examples:
from brmspy import brms
# Create formula with options
f = brms.formula("y ~ x", decomp="QR")
# Use in fit()
model = brms.fit(f, data=df, chains=4)
LooResult
dataclass
¶
Bases: RListVectorExtension