models.BayesGlm

A Bayesian GLM sampled with NUTS (nuts-rs, the Rust core of nutpie).

Usage

models.BayesGlm()

Normal priors with mean 0 on the coefficients: standard deviation intercept_sd for an all-ones column, prior_sd for the others (on the link scale; standardize covariates). For the Gaussian, gamma and inverse Gaussian the dispersion is sampled too, with a half-normal prior of scale dispersion_scale, unless dispersion fixes it. Chains run in parallel, start near the maximum-likelihood fit, and replay exactly from seed.

Parameters

family: str
link: str
prior_sd: float = 2.5
intercept_sd: float = 10.0
dispersion: float

A fixed dispersion; 1 by default for the Poisson, binomial and negative binomial. A Tweedie needs one.

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
theta: float
power: float
link_power: float

Examples

>>> from prospicio.models import BayesGlm, Design
>>> x = [(i % 4) - 1.5 for i in range(40)]
>>> y = [[1.0, 2.0, 3.0, 5.0][i % 4] for i in range(40)]
>>> d = Design([[1.0] * 40, x], ["(Intercept)", "x"])
>>> fit = BayesGlm("poisson", chains=2, tune=300, draws=300).fit(d, y)
>>> all(s["rhat"] < 1.05 for s in fit.summary())

True

Methods

Name Description
fit() Samples the posterior.

fit()

Samples the posterior.

Usage

fit(design, y)
Parameters
design: Design
y: list of float
Returns
BayesGlmFit