## reserving.ApcGlm


The age-period-cohort (APC) reserving GLM: \`\`log mu_ij = delta +


Usage

``` python
reserving.ApcGlm()
```


alpha_i + beta_j + gamma\_(i+j)`on the increments of a full triangle, with the over-dispersed Poisson error (or the gamma or Tweedie of`OdpGlm`). The calendar index is the sum of the accident and development indices, so the effects are identified only up to linear trends. The fit uses the canonical parameters of Kuang, Nielsen and Nielsen (2008a): a level, two slopes and the second differences of each effect,`3k - 3`parameters on a`k`by`k\`\` triangle. Fitted values and the deviance do not depend on the identification.

The future cells need the calendar effect past the latest diagonal. [extrapolation](reserving.ApcGlm.md#prospicio.reserving.ApcGlm.extrapolation) chooses one of the three rules of R `apc`, each independent of the identification: `"I2"` sets the future second differences to 0 (the last calendar trend continues), `"I1"` continues with the mean of the fitted first differences (the first left out, as R `apc` does), and `"I0"` (R `apc`'s default, at least 4 origins) puts the future effects on the least-squares line through the effects of the periods from the third on. The rules are linear in the fitted second differences, so the prediction error covers the extrapolated effect.

The sub-models drop one effect: `"AP"` (development and calendar, Taylor's separation model as a GLM), `"AC"` (accident and development, the chain ladder, where the extrapolation does not apply) and `"PC"` (accident and calendar).

The triangle must be full: as many ages as origins, the origin grain equal to the development grain, no hole.


## Parameters


`effects: (APC, AP, AC, PC) = ``"APC"`  
The effects in the model, as Python and R `apc` name them; any case.

`extrapolation: (I0, I1, I2) = ``"I0"`  
The rule for the calendar effect past the latest diagonal; any case.

`family: (poisson, gamma, tweedie) = ``"poisson"`  
The error distribution, with the log link and Pearson's dispersion.

`power: float`  
The Tweedie power, in (1, 2); needed for, and only for, `"tweedie"`.

`tolerance: float = ``1e-10`  
IRLS convergence tolerance, as `OdpGlm`'s.

`max_iterations: int = ``100`  
Maximum IRLS iterations, as `OdpGlm`'s.


## Raises


`ValueError`  
For an unknown [effects](reserving.ApcGlm.md#prospicio.reserving.ApcGlm.effects), [extrapolation](reserving.ApcGlm.md#prospicio.reserving.ApcGlm.extrapolation) or [family](risk.Distortion.md#prospicio.risk.Distortion.family), a [power](reserving.ApcGlm.md#prospicio.reserving.ApcGlm.power) given for a family other than the Tweedie, or a Tweedie power missing or outside (1, 2).


## Examples

``` python
>>> from prospicio.reserving import ApcGlm, Triangle
>>> rows = [[100.0, 60.0, 20.0, 5.0], [110.0, 70.0, 24.0], [125.0, 75.0], [140.0]]
>>> tri = Triangle.from_long(
...     [2001 + i for i, row in enumerate(rows) for _ in row],
...     [12 * (j + 1) for row in rows for j in range(len(row))],
...     {"paid": [v for row in rows for v in row]},
...     cumulative=False,
... )
>>> fit = ApcGlm(extrapolation="i1").fit(tri, "paid")
>>> fit.effects, fit.extrapolation
```

('APC', 'I1')

``` python
>>> len(fit.names), fit.names[:4]
```

(9, \['level', 'slope_age', 'slope_accident', 'dd_age\[2\]'\])


## Attributes

| Name | Description |
|----|----|
| [effects](#effects) | `"APC"`, `"AP"`, `"AC"` or `"PC"`. |
| [extrapolation](#extrapolation) | `"I0"`, `"I1"` or `"I2"`. |
| [family](#family) | The error distribution: `"poisson"`, `"gamma"` or `"tweedie"`. |
| [max_iterations](#max_iterations) | Maximum IRLS iterations. |
| [power](#power) | The Tweedie power, or `None` for the other families. |
| [tolerance](#tolerance) | IRLS convergence tolerance. |

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


#### effects


`"APC"`, `"AP"`, `"AC"` or `"PC"`.


`effects: str`


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


#### extrapolation


`"I0"`, `"I1"` or `"I2"`.


`extrapolation: str`


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


#### family


The error distribution: `"poisson"`, `"gamma"` or `"tweedie"`.


`family: str`


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


#### max_iterations


Maximum IRLS iterations.


`max_iterations: int`


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


#### power


The Tweedie power, or `None` for the other families.


`power: float | None`


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


#### tolerance


IRLS convergence tolerance.


`tolerance: float`


## Methods

| Name | Description |
|----|----|
| [fit()](#fit) | Fits [column](models.Design.md#prospicio.models.Design.column) of a single-segment triangle and projects the cells |

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


#### fit()


Fits [column](models.Design.md#prospicio.models.Design.column) of a single-segment triangle and projects the cells


Usage

``` python
fit(triangle, column)
```


below the latest diagonal.


##### Parameters


`triangle: Triangle`  

`column: str`  


##### Returns


`ApcGlmFit`  


##### Raises


`ValueError`  
For an unknown column, a triangle with several segments (fit one at a time), a triangle that is not full, fewer than 3 origins (4 for `"I0"` with a calendar effect), a tolerance that is not finite and positive, no iterations, an increment the family cannot fit, or an IRLS that does not converge.
