Skip to main content

models.Glmm

A GLM with random intercepts and slopes, log μ = Xβ + offset + Σ zᵀb,

Usage

Source

models.Glmm()

each factor’s effects at a level N(0, Σ) with Σ unstructured: the Poisson, gamma or Tweedie (fixed power in (1, 2)) with the log link, fitted by maximum marginal likelihood as glmmTMB and lme4::glmer.

fit’s groups is a dict of each factor’s name to every row’s labels (a random intercept, (1 | g)) or to a dict with labels, slopes (covariate name to every row’s value: (1 + x | g)), intercept (false for (0 + x | g)) and correlated (false for (1 + x || g)).

Parameters

family: str = "poisson"

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

power: float

The Tweedie power.

nodes: int
Adaptive Gauss–Hermite quadrature with this many nodes (glmer(nAGQ = nodes)), for a single grouping factor with a single term; the Laplace approximation when left out.

Examples

>>> from prospicio.models import Design, Glmm
>>> y = [float((i * 7) % 5 + i % 4) for i in range(40)]
>>> site = [f"s{i % 4}" for i in range(40)]
>>> fit = Glmm().fit(Design([[1.0] * 40], ["(Intercept)"]), {"site": site}, y)
>>> fit.converged and fit.sd[0] > 0

True

Methods

Name Description
fit() Fits the model.

fit()

Fits the model.

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

Each grouping factor’s name and every row’s label, or a dict with labels, slopes, intercept and correlated (see Glmm). Factors are crossed; a factor nested in another takes the joined labels, as lme4’s a:b (f"{a}:{b}").

y: sequence of float
Returns
GlmmFit