## models.actual_vs_expected()


Actual against expected by period for a stored model's predictions on


Usage


``` python
models.actual_vs_expected(
    periods,
    family,
    y,
    mu,
    weights=None,
    dispersion=1.0,
    theta=None,
    power=None
)
```


new data, with each period's z-score under the model and a test for drift.

`A = sum(w * y)` and `E = sum(w * mu)` per period; the z-score is `(A - E) / sqrt(dispersion * sum(w * V(mu)))` with the family's variance function `V`, about standard normal while the model holds. [trend](reserving.CapeCod.md#prospicio.reserving.CapeCod.trend) is the slope of `A / E - 1` per period step (periods in sorted order), weighted by each period's precision.


## Parameters


`periods: list of int or str`  
One period label per row.

`family: str`  

`y: list of float`  
Actuals.

`mu: list of float`  
The model's predicted means.

`weights: list of float = None`  
Prior weights as fitted (exposure for a rate); leave out for counts with exposure in the offset.

`dispersion: float = ``1.0`  

`theta: float = None`  
Negative binomial [theta](reserving.ClarkFit.md#prospicio.reserving.ClarkFit.theta), Tweedie [power](distributions.Tweedie.md#prospicio.distributions.Tweedie.power).

`power: float = None`  
Negative binomial [theta](reserving.ClarkFit.md#prospicio.reserving.ClarkFit.theta), Tweedie [power](distributions.Tweedie.md#prospicio.distributions.Tweedie.power).


## Returns


`dict`  
`periods` (a list of dicts with `period`, [n](distributions.Binomial.md#prospicio.distributions.Binomial.n), `weight`, `actual`, `expected`, `ratio`, `std_dev` and `z`), [total](risk.Allocation.md#prospicio.risk.Allocation.total) (the same without `period`), [trend](reserving.CapeCod.md#prospicio.reserving.CapeCod.trend), `trend_std_error` and `trend_z`.


## Examples

``` python
>>> from prospicio.models import actual_vs_expected
>>> m = actual_vs_expected([2023, 2023, 2024, 2024], "poisson",
...                        [1.0, 3.0, 2.0, 6.0], [2.0, 2.0, 2.0, 2.0])
>>> m["periods"][1]["ratio"], m["periods"][1]["z"]
```

(2.0, 2.0)
