Skip to main content

models.BayesGlmm

A Bayesian GLMM: the model of Glmm with priors, sampled with NUTS

Usage

Source

models.BayesGlmm()

jointly with the random effects (non-centred, b = Λ v with v ~ N(0, I)), the chains started at the Laplace fit.

The priors: N(0, prior_sd²) on each coefficient (intercept_sd for an all-ones column), half-normal with scale sd_scale on each random term’s standard deviation, LKJ(lkj) on each factor’s correlations (uniform at 1), and half-normal with scale dispersion_scale on the gamma’s or Tweedie’s dispersion.

Parameters

family: str = "poisson"

"poisson", "gamma" or "tweedie" (needs power).

power: float

The Tweedie power, in (1, 2).

prior_sd: float = 2.5, 10.0
intercept_sd: float = 2.5, 10.0
sd_scale: float = 1.0
lkj: float = 1.0
dispersion_scale: float = 10.0
chains: int = 4, 1000, 1000
tune: int = 4, 1000, 1000
draws: int = 4, 1000, 1000
seed: int = 0
target_accept: float = 0.8
max_depth: int = 10

Examples

>>> from prospicio.models import BayesGlmm, Design
>>> y = [float((i * 7) % 5 + i % 4) for i in range(40)]
>>> site = [f"s{i % 4}" for i in range(40)]
>>> spec = BayesGlmm(chains=2, tune=300, draws=300)
>>> fit = spec.fit(Design([[1.0] * 40], ["(Intercept)"]), {"site": site}, y)
>>> all(s["rhat"] < 1.05 for s in fit.summary())

True

Methods

Name Description
fit() Samples the posterior.

fit()

Samples the posterior.

Usage

Source

fit(design, groups, y)
Parameters
design: Design

The fixed effects, with any offset and prior weights.

groups: dict of str to sequence or dict

The grouping factors, as in Glmm.fit.

y: sequence of float
Returns
BayesGlmmFit