## models.GlmmFit


A GLM with random intercepts and slopes, from [Glmm.fit](models.Glmm.md#prospicio.models.Glmm.fit).


Usage

``` python
models.GlmmFit()
```


## Attributes

| Name | Description |
|----|----|
| [coefficients](#coefficients) | The fixed effects `β`. |
| [correlations](#correlations) | Each factor's correlation matrix of its terms, as a list of |
| [covariance](#covariance) | `β`'s covariance, row-major, from the marginal likelihood's |
| [dispersion](#dispersion) | The dispersion `φ`: the response's variance is `φ μ^p / w`; 1 |
| [dispersion_standard_error](#dispersion_standard_error) | `φ`'s standard error, `φ` times that of `log φ`; 0 for the |
| [fitted](#fitted) | Each row's mean with its random effects. |
| [group_names](#group_names) | Each random term's grouping factor, a factor repeated for each of |
| [log_likelihood](#log_likelihood) | The marginal log-likelihood, by the approximation fitted. |
| [names](#names) | The fixed effects' names. |
| [random_effects](#random_effects) | Each factor's random effects: a dict of name to a dict of |
| [sd](#sd) | Each random term's standard deviation `σ`. |
| [sd_standard_errors](#sd_standard_errors) | Each `σ`'s standard error, `σ` times that of `log σ`; NaN |
| [standard_errors](#standard_errors) | `β`'s standard errors. |
| [term_names](#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](models.GlmmFit.md#prospicio.models.GlmmFit.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`


[levels](pricing.RateLevel.md#prospicio.pricing.RateLevel.levels) (sorted), [terms](models.MarsFit.md#prospicio.models.MarsFit.terms) and, for each term, [values](reserving.Triangle.md#prospicio.reserving.Triangle.values) (the conditional modes), `conditional_variance` (lme4's `condVar`) and `prediction_variance` (with the estimates' uncertainty, glmmTMB's `condVar`), each a dict of term to a list by level (the independent factors of one name joined).


------------------------------------------------------------------------


#### 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()](#from_json) | Reads an artifact written by [to_json](models.Terms.md#prospicio.models.Terms.to_json). |
| [predict()](#predict) | Expected response for each row of [design](models.Coding.md#prospicio.models.Coding.design), adding each row's |
| [to_json()](#to_json) | The fit as a versioned JSON artifact: the specification, the fixed |

------------------------------------------------------------------------


#### from_json()


Reads an artifact written by [to_json](models.Terms.md#prospicio.models.Terms.to_json).


Usage

``` python
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](models.Coding.md#prospicio.models.Coding.design), adding each row's


Usage

``` python
predict(design, groups=None)
```


random effects by label and covariate ([groups](distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution.groups) as in [Glmm.fit](models.Glmm.md#prospicio.models.Glmm.fit)); a level the fit has not seen, or a factor left out of [groups](distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution.groups), adds 0 (the population mean).


------------------------------------------------------------------------


#### to_json()


The fit as a versioned JSON artifact: the specification, the fixed


Usage

``` python
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](models.Terms.md#prospicio.models.Terms.from_json) reads it back and predicts as the fit did; `pickle` uses the same document.


##### Returns


`str`  


##### Examples

``` python
>>> 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

``` python
>>> pickle.loads(pickle.dumps(fit)).to_json() == fit.to_json()
```

True
