## models.Glmm


A GLM with random intercepts and slopes, `log μ = Xβ + offset + Σ zᵀb`,


Usage

``` python
models.Glmm()
```


each factor's effects at a level `N(0, Σ)` with `Σ` unstructured: the Poisson, gamma or Tweedie (fixed power in (1, 2)) with the log link, fitted by maximum marginal likelihood as glmmTMB and `lme4::glmer`.

[fit](risk.Gpd.md#prospicio.risk.Gpd.fit)'s [groups](distributions.PredictiveDistribution.md#prospicio.distributions.PredictiveDistribution.groups) is a dict of each factor's name to every row's labels (a random intercept, `(1 | g)`) or to a dict with [labels](aggregate.EventSet.md#prospicio.aggregate.EventSet.labels), `slopes` (covariate name to every row's value: `(1 + x | g)`), [intercept](models.Terms.md#prospicio.models.Terms.intercept) (false for `(0 + x | g)`) and `correlated` (false for `(1 + x || g)`).


## Parameters


`family: str = ``"poisson"`  
`"poisson"`, `"gamma"` or `"tweedie"` (needs [power](reserving.ApcGlm.md#prospicio.reserving.ApcGlm.power)).

`power: float`  
The Tweedie power.

`nodes: int`  
Adaptive Gauss-Hermite quadrature with this many nodes (`glmer(nAGQ = nodes)`), for a single grouping factor with a single term; the Laplace approximation when left out.


## Examples

``` python
>>> from prospicio.models import Design, Glmm
>>> y = [float((i * 7) % 5 + i % 4) for i in range(40)]
>>> site = [f"s{i % 4}" for i in range(40)]
>>> fit = Glmm().fit(Design([[1.0] * 40], ["(Intercept)"]), {"site": site}, y)
>>> fit.converged and fit.sd[0] > 0
```

True


## Methods

| Name | Description |
|----|----|
| [fit()](#fit) | Fits the model. |

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


#### fit()


Fits the model.


Usage

``` python
fit(design, groups, y)
```


##### Parameters


`design: Design`  
The fixed effects, with any offset and prior weights.

`groups: dict of str to sequence or dict`  
Each grouping factor's name and every row's label, or a dict with [labels](aggregate.EventSet.md#prospicio.aggregate.EventSet.labels), `slopes`, [intercept](models.Terms.md#prospicio.models.Terms.intercept) and `correlated` (see [Glmm](models.Glmm.md#prospicio.models.Glmm)). Factors are crossed; a factor nested in another takes the joined labels, as lme4's `a:b` (`f"{a}:{b}"`).

`y: sequence of float`  


##### Returns


`GlmmFit`
