## models.BayesGlmmFit


A sampled Bayesian GLMM, from [BayesGlmm.fit](models.BayesGlmm.md#prospicio.models.BayesGlmm.fit).


Usage

``` python
models.BayesGlmmFit()
```


## Attributes

| Name | Description |
|----|----|
| [divergences](#divergences) | Divergent transitions among the kept draws. |
| [effect_draws](#effect_draws) | The random effects' draws, one row per draw, in the order of |
| [effect_names](#effect_names) | The random effects' names, `b[g|level|term]`. |
| [laplace](#laplace) | The Laplace fit the chains started from. |
| [names](#names) | The fixed coefficients' names. |
| [parameter_draws](#parameter_draws) | The parameters' draws on their natural scale, one row per draw |
| [parameter_names](#parameter_names) | The parameters' names: the coefficients, each factor's |
| [random_effects](#random_effects) | Each factor's random effects: a dict of name to a dict of |

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


#### divergences


Divergent transitions among the kept draws.


`divergences: int`


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


#### effect_draws


The random effects' draws, one row per draw, in the order of


`effect_draws: list[list[float]]`


[effect_names](models.BayesGlmmFit.md#prospicio.models.BayesGlmmFit.effect_names).


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


#### effect_names


The random effects' names, `b[g|level|term]`.


`effect_names: list[str]`


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


#### laplace


The Laplace fit the chains started from.


`laplace: GlmmFit`


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


#### names


The fixed coefficients' names.


`names: list[str]`


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


#### parameter_draws


The parameters' draws on their natural scale, one row per draw


`parameter_draws: list[list[float]]`


(chain by chain), in the order of [parameter_names](models.BayesGlmmFit.md#prospicio.models.BayesGlmmFit.parameter_names).


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


#### parameter_names


The parameters' names: the coefficients, each factor's


`parameter_names: list[str]`


`sd[g|term]` and `cor[g|a,b]`, then [dispersion](models.GlmFit.md#prospicio.models.GlmFit.dispersion) when it is free.


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


#### 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 [mean](esg.Cir.md#prospicio.esg.Cir.mean) and [sd](models.GlmmFit.md#prospicio.models.GlmmFit.sd) (the posterior's), each a dict of term to a list by level (the independent factors of one name joined).


## Methods

| Name | Description |
|----|----|
| [from_json()](#from_json) | Reads an artifact written by [to_json](models.Terms.md#prospicio.models.Terms.to_json). |
| [predict()](#predict) | The posterior mean of each row's mean, adding its random effects by |
| [summary()](#summary) | Posterior summary of each parameter: one dict per parameter with |
| [to_json()](#to_json) | The fit as a versioned JSON artifact: the specification with its |

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


#### 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


`BayesGlmmFit`  


##### Raises


`ValueError`  
For malformed JSON, another format, a newer format version or inconsistent fields.


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


#### predict()


The posterior mean of each row's mean, adding its random effects by


Usage

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


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, adds 0 in every draw.


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


#### summary()


Posterior summary of each parameter: one dict per parameter with


Usage

``` python
summary()
```


[name](aggregate.Ledger.md#prospicio.aggregate.Ledger.name), [mean](esg.Cir.md#prospicio.esg.Cir.mean), [sd](models.GlmmFit.md#prospicio.models.GlmmFit.sd), `q05`, `q50`, `q95`, `rhat`, `ess_bulk` and `ess_tail`.


##### Returns


`list of dict`  


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


#### to_json()


The fit as a versioned JSON artifact: the specification with its


Usage

``` python
to_json()
```


priors and sampler settings, the posterior draws of the parameters and the random effects, their layout, and the Laplace fit the chains started from, numbers bit for bit (#978). [from_json](models.Terms.md#prospicio.models.Terms.from_json) reads it back; `pickle` uses the same document.


##### Returns


`str`  


##### Examples

``` python
>>> import pickle
>>> from prospicio.models import BayesGlmm, BayesGlmmFit, Design
>>> 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 = BayesGlmm(chains=1, tune=60, draws=20).fit(d, {"site": site}, y)
>>> BayesGlmmFit.from_json(fit.to_json()).to_json() == fit.to_json()
```

True

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

True
