models.Glm

A generalized linear model, fitted by IRLS.

Usage

models.Glm()

Parameters

family: str

"gaussian", "poisson", "gamma", "inverse_gaussian", "binomial", "negative_binomial" (needs theta) or "tweedie" (needs power).

link: str

"identity", "log", "logit", "probit", "cloglog", "inverse", "inverse_squared" or "power" (needs link_power); the family’s canonical link by default.

dispersion: str or float

"pearson", "deviance" or a fixed value. By default 1 for the Poisson, binomial and negative binomial and Pearson’s estimate otherwise; "pearson" with the Poisson is the over-dispersed (quasi-) Poisson, which accepts negative responses as long as the fitted means stay positive.

theta: float
power: float
link_power: float

Examples

>>> from prospicio.models import Design, Glm
>>> d = Design([[1.0] * 4, [0.0, 0.0, 1.0, 1.0]], ["(Intercept)", "young"],
...            offset=[0.0, 0.0, 0.0, 0.0])
>>> fit = Glm("poisson", "log").fit(d, [1.0, 3.0, 4.0, 6.0])
>>> round(fit.coefficients[1], 10) == round(__import__("math").log(5 / 2), 10)

True

Methods

Name Description
fit() Fits the model.

fit()

Fits the model.

Usage

fit(design, y)
Parameters
design: Design
y: list of float
Returns
GlmFit
Raises
ValueError
If the design is collinear, a response is out of the family’s range, or IRLS does not converge.