Skip to content

brms results

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

Examples:

Create prior specifications (prefer using prior()):

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)

Functions

to_brms_kwargs()

Convert PriorSpec to keyword arguments for brms::prior_string().

Maps Python dataclass fields to R function arguments, handling the class_ -> class parameter name conversion.

Returns:

Type Description
dict

Keyword arguments ready for brms::prior_string()

Examples:

from brmspy import prior
p = prior("normal(0, 1)", class_="b", coef="age")
kwargs = p.to_brms_kwargs()
print(kwargs)
# {'prior': 'normal(0, 1)', 'class': 'b', 'coef': 'age'}

IDConstantData

Bases: InferenceData

Typed .constant_data extension to idata

IDPredictionsConstantData

Bases: InferenceData

Typed .predictions_constant_data extension to idata

IDObservedData

Bases: IDConstantData

Typed .posterior extension to idata

IDPosterior

Bases: IDConstantData

Typed .posterior extension to idata

IDPosteriorPredictive

Bases: IDConstantData

Typed .posterior_predictive extension to idata

IDPredictions

Bases: IDPredictionsConstantData

Typed .predictions extension to idata

IDLogLikelihoodInsample

Bases: IDConstantData

Typed .log_likelihood extension to idata

IDLogLikelihoodOutsample

Bases: IDPredictionsConstantData

Typed .log_likelihood extension to idata

IDBrm

Bases: IDConstantData

Typed arviz.InferenceData for fitted brms models.

Extends arviz.InferenceData with type hints for IDE autocomplete. In brmspy, the fitted model result typically exposes an .idata attribute of this type.

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 (inherited from arviz.InferenceData).

dims dict

Dimension specifications for variables (inherited from arviz.InferenceData).

See Also

brmspy.brms.brm : Creates fitted model results (alias: brmspy.brms.fit). arviz.InferenceData : Base class documentation.

Examples:

from brmspy import brms

model = brms.brm("y ~ x", data=df, chains=4)

# Type checking and autocomplete
assert isinstance(model.idata, IDFit)
print(model.idata.posterior)

RListVectorExtension dataclass

Generic result container with R objects.

Attributes:

Name Type Description
r ListVector

R object from brms

IDResult dataclass

Bases: Generic[T_idata], RListVectorExtension

Generic result container with arviz and R objects.

Attributes:

Name Type Description
idata InferenceData

arviz InferenceData object

r ListVector

R object from brms

SummaryResult dataclass

Bases: RListVectorExtension

Parsed summary output for a fitted model.

This is a convenience container that holds both:

  • structured Python data (mostly pandas DataFrames)
  • the underlying R object reference in .r (as a worker-side handle)

Attributes:

Name Type Description
formula str

Model formula string as reported by brms.

data_name str

Data name as reported by brms (may be an internal label).

nobs int

Number of observations.

prior DataFrame

Prior summary table.

fixed DataFrame

Fixed effects summary table.

random dict[str, DataFrame] or None

Random effects summary tables (if present).

LooResult dataclass

Bases: RListVectorExtension

Parsed brms::loo() result.

Attributes:

Name Type Description
estimates, pointwise, diagnostics DataFrame

LOO tables.

psis_object Any or None

PSIS object (if present). May be an R-handle wrapper depending on conversion.

elpd_loo, p_loo, looic float

Key scalar metrics.

se_elpd_loo, se_p_loo, se_looic float

Standard errors for the corresponding scalars.

Functions

__repr__()

Pretty print LOO-CV results.

LooCompareResult dataclass

Bases: RListVectorExtension

Result of comparing models by a LOO-style criterion.

Attributes:

Name Type Description
table DataFrame

Comparison table.

criterion str

Criterion name (e.g. "loo").