models.GlmmFit
A GLM with random intercepts and slopes, from Glmm.fit.
Usage
models.GlmmFit()Attributes
| Name | Description |
|---|---|
| coefficients |
The fixed effects β.
|
| correlations | Each factor’s correlation matrix of its terms, as a list of |
| covariance |
β’s covariance, row-major, from the marginal likelihood’s
|
| dispersion |
The dispersion φ: the response’s variance is φ μ^p / w; 1
|
| dispersion_standard_error |
φ’s standard error, φ times that of log φ; 0 for the
|
| fitted | Each row’s mean with its random effects. |
| group_names | Each random term’s grouping factor, a factor repeated for each of |
| log_likelihood | The marginal log-likelihood, by the approximation fitted. |
| names | The fixed effects’ names. |
| random_effects | Each factor’s random effects: a dict of name to a dict of |
| sd |
Each random term’s standard deviation σ.
|
| sd_standard_errors |
Each σ’s standard error, σ times that of log σ; NaN
|
| standard_errors |
β’s standard errors.
|
| term_names |
Each random term’s name, "(Intercept)" or a slope’s covariate.
|
coefficients
The fixed effects β.
coefficients: list[float]
correlations
Each factor’s correlation matrix of its terms, as a list of
correlations: list[tuple[str, list[str], list[list[float]]]]
(name, terms, matrix), the matrix a list of rows.
covariance
β’s covariance, row-major, from the marginal likelihood’s
covariance: list[float]
Hessian (glmmTMB’s vcov).
dispersion
The dispersion φ: the response’s variance is φ μ^p / w; 1
dispersion: float
for the Poisson.
dispersion_standard_error
φ’s standard error, φ times that of log φ; 0 for the
dispersion_standard_error: float
Poisson.
fitted
Each row’s mean with its random effects.
fitted: list[float]
group_names
Each random term’s grouping factor, a factor repeated for each of
group_names: list[str]
its terms (parallel to sd).
log_likelihood
The marginal log-likelihood, by the approximation fitted.
log_likelihood: float
names
The fixed effects’ names.
names: list[str]
random_effects
Each factor’s random effects: a dict of name to a dict of
random_effects: dict
sd
Each random term’s standard deviation σ.
sd: list[float]
sd_standard_errors
Each σ’s standard error, σ times that of log σ; NaN
sd_standard_errors: list[float]
for a σ at 0.
standard_errors
β’s standard errors.
standard_errors: list[float]
term_names
Each random term’s name, "(Intercept)" or a slope’s covariate.
term_names: list[str]
Methods
| Name | Description |
|---|---|
| from_json() | Reads an artifact written by to_json. |
| predict() | Expected response for each row of design, adding each row’s |
| to_json() | The fit as a versioned JSON artifact: the specification, the fixed |
from_json()
Reads an artifact written by to_json.
Usage
from_json(text)Parameters
text: str
Returns
GlmmFit
Raises
ValueError- For malformed JSON, another format, a newer format version or inconsistent fields.
predict()
Expected response for each row of design, adding each row’s
Usage
predict(design, groups=None)to_json()
The fit as a versioned JSON artifact: the specification, the fixed
Usage
to_json()effects and their covariance, the variance components, the optimizer’s parameters, the dispersion, every factor’s predicted random effects with their variances, and the fit statistics; numbers bit for bit (#978). from_json reads it back and predicts as the fit did; pickle uses the same document.
Returns
str
Examples
>>> import pickle
>>> from prospicio.models import Design, Glmm, GlmmFit
>>> y = [float((i * 7) % 5 + i % 4) for i in range(40)]
>>> site = [f"s{i % 4}" for i in range(40)]
>>> d = Design([[1.0] * 40], ["(Intercept)"])
>>> fit = Glmm().fit(d, {"site": site}, y)
>>> GlmmFit.from_json(fit.to_json()).predict(d, {"site": site}) == fit.predict(d, {"site": site})True
>>> pickle.loads(pickle.dumps(fit)).to_json() == fit.to_json()True