Skip to main content

models.BayesGlmmFit

A sampled Bayesian GLMM, from BayesGlmm.fit.

Usage

Source

models.BayesGlmmFit()

Attributes

Name Description
divergences Divergent transitions among the kept draws.
effect_draws The random effects’ draws, one row per draw, in the order of
effect_names The random effects’ names, b[g|level|term].
laplace The Laplace fit the chains started from.
names The fixed coefficients’ names.
parameter_draws The parameters’ draws on their natural scale, one row per draw
parameter_names The parameters’ names: the coefficients, each factor’s
random_effects Each factor’s random effects: a dict of name to a dict of

divergences

Divergent transitions among the kept draws.

divergences: int


effect_draws

The random effects’ draws, one row per draw, in the order of

effect_draws: list[list[float]]


effect_names

The random effects’ names, b[g|level|term].

effect_names: list[str]


laplace

The Laplace fit the chains started from.

laplace: GlmmFit


names

The fixed coefficients’ names.

names: list[str]


parameter_draws

The parameters’ draws on their natural scale, one row per draw

parameter_draws: list[list[float]]

(chain by chain), in the order of parameter_names.


parameter_names

The parameters’ names: the coefficients, each factor’s

parameter_names: list[str]

sd[g|term] and cor[g|a,b], then dispersion when it is free.


random_effects

Each factor’s random effects: a dict of name to a dict of

random_effects: dict

levels (sorted), terms, and mean and sd (the posterior’s), each a dict of term to a list by level (the independent factors of one name joined).

Methods

Name Description
from_json() Reads an artifact written by to_json.
predict() The posterior mean of each row’s mean, adding its random effects by
summary() Posterior summary of each parameter: one dict per parameter with
to_json() The fit as a versioned JSON artifact: the specification with its

from_json()

Reads an artifact written by to_json.

Usage

Source

from_json(text)
Parameters
text: str
Returns
BayesGlmmFit
Raises
ValueError
For malformed JSON, another format, a newer format version or inconsistent fields.

predict()

The posterior mean of each row’s mean, adding its random effects by

Usage

Source

predict(design, groups=None)

label and covariate (groups as in Glmm.fit); a level the fit has not seen, or a factor left out, adds 0 in every draw.


summary()

Posterior summary of each parameter: one dict per parameter with

Usage

Source

summary()

name, mean, sd, q05, q50, q95, rhat, ess_bulk and ess_tail.

Returns
list of dict

to_json()

The fit as a versioned JSON artifact: the specification with its

Usage

Source

to_json()

priors and sampler settings, the posterior draws of the parameters and the random effects, their layout, and the Laplace fit the chains started from, numbers bit for bit (#978). from_json reads it back; pickle uses the same document.

Returns
str
Examples
>>> import pickle
>>> from prospicio.models import BayesGlmm, BayesGlmmFit, Design
>>> y = [float((i * 7) % 5 + i % 4) for i in range(40)]
>>> site = [f"s{i % 4}" for i in range(40)]
>>> d = Design([[1.0] * 40], ["(Intercept)"])
>>> fit = BayesGlmm(chains=1, tune=60, draws=20).fit(d, {"site": site}, y)
>>> BayesGlmmFit.from_json(fit.to_json()).to_json() == fit.to_json()

True

>>> pickle.loads(pickle.dumps(fit)).to_json() == fit.to_json()

True