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: strlink: strprior_sd: float = 2.5intercept_sd: float = 10.0dispersion: float-
A fixed dispersion; 1 by default for the Poisson, binomial and negative binomial. A Tweedie needs one.
dispersion_scale: float = 10.0chains: int = 4, 1000, 1000tune: int = 4, 1000, 1000draws: int = 4, 1000, 1000seed: int = 0target_accept: float = 0.8max_depth: int = 10theta: floatpower: floatlink_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: Designy: list of float
Returns
BayesGlmFit