# GLMs for insurance rating: Goldburd, Khare, Tevet and Guller with prospicio

Mark Goldburd, Anand Khare, Dan Tevet and Dmitriy Guller wrote *Generalized Linear Models for Insurance Rating* (CAS Monograph 5, second edition, 2025 revision), the CAS text on building a classification rating plan with GLMs: the log link as a multiplicative plan, frequency, severity and Tweedie models, the measures that refine and choose between models, and extensions such as GAMs.

This guide follows that workflow in the prospicio Python API (`prospicio.models`, with `prospicio.distributions` for the Tweedie and the F-test). The PDF does not contain the insurers' data, so the guide does not rerun the monograph's coefficient tables (Tables 4 to 12, Figure 9, Table 14) or its Gini of 56.1%. Where the monograph prints arithmetic that a reader can redo, the tables show the monograph's value beside prospicio's. The rest runs on a portfolio that the repository ships.

This is part 1 (chapters 2 to 6.2: the rating plan, offsets and weights, the choice of distribution, tests of significance). Part 2, [`glm-ratemaking-goldburd-validation.md`](glm-ratemaking-goldburd-validation.md), covers continuous variables, interactions, residuals, validation and regularization (chapters 5.4 to 7 and 10). Section numbers in parentheses are the monograph's.


# 1. The data

`validation/data/glm_policies.csv` is a synthetic portfolio of 600 policies, written by `validation/scripts/statsmodels_glm.py`. It has a driver age (18 to 80), a region (A to D, A the most populous and D the thinnest), an exposure in years and a response for every family. A fixed seed draws them from a known model, so the guide shows what a GLM recovers and what it misses.

- [claims](../reference/distributions.SizeOfLoss.md#prospicio.distributions.SizeOfLoss.claims) is Poisson with mean `exposure * exp(-1 - 0.01 (age - 40)) * r`. The region factors are `r = 1.0, 1.2, 0.8, 1.5` for A to D.
- `wavy_claims` is Poisson with a non-linear age effect, `exposure * exp(0.5 + 0.8 sin(age / 8))`.
- `avg_sev` is a gamma average of `n_sev` claims.
- `pure` is a compound Poisson-gamma pure premium.

The portfolio drew 155 claims where the true model expects 134 (1.8 standard deviations more), so fitted base rates run above the true one.


``` python
import csv
import math
from collections import Counter
from pathlib import Path

from prospicio.models import Design, Glm, Terms

rows = list(csv.DictReader(open(Path("../../validation/data/glm_policies.csv"))))
NUMERIC = ["age", "exposure", "claims", "n_sev", "avg_sev", "ig", "nb", "trials", "pure", "wavy_claims"]
data = {k: [float(r[k]) for r in rows] for k in NUMERIC}
data["region"] = [r["region"] for r in rows]
n = len(rows)
log_e = [math.log(e) for e in data["exposure"]]

print(n, "policies,", round(sum(data["exposure"]), 1), "years of exposure,",
      int(sum(data["claims"])), "claims")
print("policies by region:", dict(sorted(Counter(data["region"]).items())))
true_r = {"A": 1.0, "B": 1.2, "C": 0.8, "D": 1.5}
true_mu = [e * math.exp(-1 - 0.01 * (a - 40)) * true_r[g] for e, a, g in zip(data["exposure"], data["age"], data["region"])]
print(f"claims expected under the true model: {sum(true_mu):.1f}")
```


    600 policies, 358.0 years of exposure, 155 claims
    policies by region: {'A': 243, 'B': 163, 'C': 120, 'D': 74}
    claims expected under the true model: 134.0


# 2. The GLM as a multiplicative rating plan (sections 2.1 to 2.4)

A GLM draws the response from an exponential-family distribution with mean [mu](../reference/distributions.Normal.md#prospicio.distributions.Normal.mu) and dispersion [phi](../reference/reserving.PaidIncurredFit.md#prospicio.reserving.PaidIncurredFit.phi), with a link function of the mean linear in the predictors. With the log link, `mu = exp(b0) * exp(b1 x1) * ...`: a base rate times one relativity for each rating variable. Premiums stay positive and a surcharge is a percentage.

Section 2.1.3 uses a gamma severity model with intercept 5.8, a driver-age slope of 0.1, a married coefficient of -0.15 and dispersion 0.3. The variance is `phi * V(mu)`, and for the gamma `V(mu) = mu^2`, so the coefficient of variation is `sqrt(phi)` at any mean. [Gamma.from_mean_cv](../reference/distributions.Gamma.md#prospicio.distributions.Gamma.from_mean_cv) gives the variances of section 2.2:


``` python
import pandas as pd
from great_tables import GT

from prospicio.distributions import Gamma


def book_table(rows, title, subtitle=None, book="monograph"):
    """Rows of (label, prospicio, book, decimals[, signed]) as a table; a missing book value stays blank."""
    frame = pd.DataFrame([r[:3] for r in rows], columns=["item", "prospicio", book])
    table = GT(frame, rowname_col="item").tab_header(title, subtitle)
    for i, row in enumerate(rows):
        table = table.fmt_number(["prospicio", book], rows=[i], decimals=row[3],
                                 force_sign=len(row) > 4 and row[4])
    return table.sub_missing(missing_text="")


b0, b_age, b_married, phi = 5.8, 0.1, -0.15, 0.3
eta = b0 + b_age * 25 + b_married * 1
factors = [round(math.exp(b0), 2), round(math.exp(b_age * 25), 3), round(math.exp(b_married), 3)]
variance = lambda mean: Gamma.from_mean_cv(mean, math.sqrt(phi)).variance() / 1e6
book_table([
    ("linear predictor, 25, married", eta, 8.15, 2),
    ("severity, 25, married", math.exp(eta), 3463.38, 2),
    ("base rate", factors[0], 330.30, 2),
    ("age factor, 25 years", factors[1], 12.182, 3),
    ("married factor", factors[2], 0.861, 3),
    ("product of the rounded factors", math.prod(factors), 3464.42, 2),
    ("severity, 35, unmarried", math.exp(b0 + b_age * 35), 10938, 0),
    ("variance at mean 3,464, millions", variance(3464.0), 3.6, 1),
    ("variance at mean 10,938, millions", variance(10938.0), 35.9, 1),
], "Gamma severity model of section 2.1.3")
```


<style>
#yllgsdoykp table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#yllgsdoykp thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#yllgsdoykp p { margin: 0; padding: 0; }
 #yllgsdoykp .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #yllgsdoykp .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #yllgsdoykp .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #yllgsdoykp .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #yllgsdoykp .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #yllgsdoykp .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #yllgsdoykp .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #yllgsdoykp .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #yllgsdoykp .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #yllgsdoykp .gt_column_spanner_outer:first-child { padding-left: 0; }
 #yllgsdoykp .gt_column_spanner_outer:last-child { padding-right: 0; }
 #yllgsdoykp .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #yllgsdoykp .gt_spanner_row { border-bottom-style: hidden; }
 #yllgsdoykp .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #yllgsdoykp .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #yllgsdoykp .gt_from_md> :first-child { margin-top: 0; }
 #yllgsdoykp .gt_from_md> :last-child { margin-bottom: 0; }
 #yllgsdoykp .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #yllgsdoykp .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #yllgsdoykp .gt_indent_1 { text-indent: 5px; }
 #yllgsdoykp .gt_indent_2 { text-indent: calc(5px * 2); }
 #yllgsdoykp .gt_indent_3 { text-indent: calc(5px * 3); }
 #yllgsdoykp .gt_indent_4 { text-indent: calc(5px * 4); }
 #yllgsdoykp .gt_indent_5 { text-indent: calc(5px * 5); }
 #yllgsdoykp .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #yllgsdoykp .gt_row_group_first td { border-top-width: 2px; }
 #yllgsdoykp .gt_row_group_first th { border-top-width: 2px; }
 #yllgsdoykp .gt_striped { color: #333333; background-color: #F4F4F4; }
 #yllgsdoykp .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #yllgsdoykp .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #yllgsdoykp .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #yllgsdoykp .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #yllgsdoykp .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #yllgsdoykp .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #yllgsdoykp .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #yllgsdoykp .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #yllgsdoykp .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #yllgsdoykp .gt_left { text-align: left; }
 #yllgsdoykp .gt_center { text-align: center; }
 #yllgsdoykp .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #yllgsdoykp .gt_font_normal { font-weight: normal; }
 #yllgsdoykp .gt_font_bold { font-weight: bold; }
 #yllgsdoykp .gt_font_italic { font-style: italic; }
 #yllgsdoykp .gt_super { font-size: 65%; }
 #yllgsdoykp .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #yllgsdoykp .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #yllgsdoykp .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #yllgsdoykp .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #yllgsdoykp .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #yllgsdoykp .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Gamma severity model of section 2.1.3</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="monograph" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">monograph</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">linear predictor, 25, married</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">8.15</td>
<td class="gt_row gt_right" headers="stub-1 monograph">8.15</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">severity, 25, married</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">3,463.38</td>
<td class="gt_row gt_right" headers="stub-2 monograph">3,463.38</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">base rate</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">330.30</td>
<td class="gt_row gt_right" headers="stub-3 monograph">330.30</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">age factor, 25 years</th>
<td class="gt_row gt_right" headers="stub-4 prospicio">12.182</td>
<td class="gt_row gt_right" headers="stub-4 monograph">12.182</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">married factor</th>
<td class="gt_row gt_right" headers="stub-5 prospicio">0.861</td>
<td class="gt_row gt_right" headers="stub-5 monograph">0.861</td>
</tr>
<tr>
<th id="stub-6" class="gt_row gt_left gt_stub" scope="row">product of the rounded factors</th>
<td class="gt_row gt_right" headers="stub-6 prospicio">3,464.42</td>
<td class="gt_row gt_right" headers="stub-6 monograph">3,464.42</td>
</tr>
<tr>
<th id="stub-7" class="gt_row gt_left gt_stub" scope="row">severity, 35, unmarried</th>
<td class="gt_row gt_right" headers="stub-7 prospicio">10,938</td>
<td class="gt_row gt_right" headers="stub-7 monograph">10,938</td>
</tr>
<tr>
<th id="stub-8" class="gt_row gt_left gt_stub" scope="row">variance at mean 3,464, millions</th>
<td class="gt_row gt_right" headers="stub-8 prospicio">3.6</td>
<td class="gt_row gt_right" headers="stub-8 monograph">3.6</td>
</tr>
<tr>
<th id="stub-9" class="gt_row gt_left gt_stub" scope="row">variance at mean 10,938, millions</th>
<td class="gt_row gt_right" headers="stub-9 prospicio">35.9</td>
<td class="gt_row gt_right" headers="stub-9 monograph">35.9</td>
</tr>
</tbody>
</table>


Both monograph figures are right. The value 3,463.38 is the exact mean. The value 3,464.42 is the product of factors rounded to the precision of a rating manual.

A categorical variable enters as one 0/1 column for each level except a base level. Each coefficient is a log relativity to the base, and its exponential is a factor (section 2.4.2: SUV 1.23, truck 0.57, van -0.30 against sedan). To move the base to van (Table 5), subtract the van coefficient from every level. A logged continuous predictor gives a power curve (section 2.4.1): a coefficient of 0.62 on log amount of insurance makes \$200,000 cost `2^0.62` times \$100,000. A logistic coefficient is a log odds ratio (section 2.8): 0.24 means 27% higher odds.


``` python
vtype = {"SUV": 1.23, "truck": 0.57, "van": -0.30}
factor = {k: math.exp(b) for k, b in vtype.items()}
rebased = {"sedan": 0.0 - vtype["van"], "SUV": vtype["SUV"] - vtype["van"], "truck": vtype["truck"] - vtype["van"]}
book_table([
    ("factor, SUV", factor["SUV"], 3.421, 3),
    ("factor, truck", factor["truck"], None, 3),
    ("factor, van", factor["van"], 0.741, 3),
    ("change in %, SUV", 100 * (factor["SUV"] - 1), 242, 0, True),
    ("change in %, van", 100 * (factor["van"] - 1), -25.9, 1, True),
    ("van as base, sedan", rebased["sedan"], 0.30, 2),
    ("van as base, SUV", rebased["SUV"], 1.53, 2),
    ("van as base, truck", rebased["truck"], 0.88, 2),
    ("AOI 200k against 100k", (200 / 100) ** 0.62, 1.54, 2),
    ("odds change in %, coefficient 0.24", 100 * (math.exp(0.24) - 1), 27, 0),
], "Vehicle type, amount of insurance and odds")
```


<style>
#htkaahrizd table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#htkaahrizd thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#htkaahrizd p { margin: 0; padding: 0; }
 #htkaahrizd .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #htkaahrizd .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #htkaahrizd .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #htkaahrizd .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #htkaahrizd .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #htkaahrizd .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #htkaahrizd .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #htkaahrizd .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #htkaahrizd .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #htkaahrizd .gt_column_spanner_outer:first-child { padding-left: 0; }
 #htkaahrizd .gt_column_spanner_outer:last-child { padding-right: 0; }
 #htkaahrizd .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #htkaahrizd .gt_spanner_row { border-bottom-style: hidden; }
 #htkaahrizd .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #htkaahrizd .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #htkaahrizd .gt_from_md> :first-child { margin-top: 0; }
 #htkaahrizd .gt_from_md> :last-child { margin-bottom: 0; }
 #htkaahrizd .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #htkaahrizd .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #htkaahrizd .gt_indent_1 { text-indent: 5px; }
 #htkaahrizd .gt_indent_2 { text-indent: calc(5px * 2); }
 #htkaahrizd .gt_indent_3 { text-indent: calc(5px * 3); }
 #htkaahrizd .gt_indent_4 { text-indent: calc(5px * 4); }
 #htkaahrizd .gt_indent_5 { text-indent: calc(5px * 5); }
 #htkaahrizd .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #htkaahrizd .gt_row_group_first td { border-top-width: 2px; }
 #htkaahrizd .gt_row_group_first th { border-top-width: 2px; }
 #htkaahrizd .gt_striped { color: #333333; background-color: #F4F4F4; }
 #htkaahrizd .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #htkaahrizd .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #htkaahrizd .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #htkaahrizd .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #htkaahrizd .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #htkaahrizd .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #htkaahrizd .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #htkaahrizd .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #htkaahrizd .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #htkaahrizd .gt_left { text-align: left; }
 #htkaahrizd .gt_center { text-align: center; }
 #htkaahrizd .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #htkaahrizd .gt_font_normal { font-weight: normal; }
 #htkaahrizd .gt_font_bold { font-weight: bold; }
 #htkaahrizd .gt_font_italic { font-style: italic; }
 #htkaahrizd .gt_super { font-size: 65%; }
 #htkaahrizd .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #htkaahrizd .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #htkaahrizd .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #htkaahrizd .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #htkaahrizd .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #htkaahrizd .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Vehicle type, amount of insurance and odds</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="monograph" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">monograph</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">factor, SUV</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">3.421</td>
<td class="gt_row gt_right" headers="stub-1 monograph">3.421</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">factor, truck</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">1.768</td>
<td class="gt_row gt_right" headers="stub-2 monograph"></td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">factor, van</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">0.741</td>
<td class="gt_row gt_right" headers="stub-3 monograph">0.741</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">change in %, SUV</th>
<td class="gt_row gt_right" headers="stub-4 prospicio">+242</td>
<td class="gt_row gt_right" headers="stub-4 monograph">+242</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">change in %, van</th>
<td class="gt_row gt_right" headers="stub-5 prospicio">−25.9</td>
<td class="gt_row gt_right" headers="stub-5 monograph">−25.9</td>
</tr>
<tr>
<th id="stub-6" class="gt_row gt_left gt_stub" scope="row">van as base, sedan</th>
<td class="gt_row gt_right" headers="stub-6 prospicio">0.30</td>
<td class="gt_row gt_right" headers="stub-6 monograph">0.30</td>
</tr>
<tr>
<th id="stub-7" class="gt_row gt_left gt_stub" scope="row">van as base, SUV</th>
<td class="gt_row gt_right" headers="stub-7 prospicio">1.53</td>
<td class="gt_row gt_right" headers="stub-7 monograph">1.53</td>
</tr>
<tr>
<th id="stub-8" class="gt_row gt_left gt_stub" scope="row">van as base, truck</th>
<td class="gt_row gt_right" headers="stub-8 prospicio">0.87</td>
<td class="gt_row gt_right" headers="stub-8 monograph">0.88</td>
</tr>
<tr>
<th id="stub-9" class="gt_row gt_left gt_stub" scope="row">AOI 200k against 100k</th>
<td class="gt_row gt_right" headers="stub-9 prospicio">1.54</td>
<td class="gt_row gt_right" headers="stub-9 monograph">1.54</td>
</tr>
<tr>
<th id="stub-10" class="gt_row gt_left gt_stub" scope="row">odds change in %, coefficient 0.24</th>
<td class="gt_row gt_right" headers="stub-10 prospicio">27</td>
<td class="gt_row gt_right" headers="stub-10 monograph">27</td>
</tr>
</tbody>
</table>


The rebased truck coefficient is 0.87 from the two-decimal coefficients of Table 4, and Table 5 prints 0.88. Unrounded estimates of 0.574 and -0.304 would give 0.878. This is rounding, not an error.

The base level changes the standard errors (section 2.4.3). A coefficient measures a level against the base, so a thin base level makes every comparison uncertain. Region D has 74 policies and region A has 243. [Terms](../reference/models.Terms.md#prospicio.models.Terms) takes the reference level as an argument. The claim count model has the log of exposure as its offset (section 2.6, next):


``` python
def coding(*terms, reference=None):
    """Intercept, numeric columns and the region factor with the given base level."""
    t = Terms().intercept()
    for name in terms:
        t = t.numeric(name)
    return t.factor("region", reference=reference).fit(data)


poisson = Glm("poisson", "log")
estimates = {}
for base in ["A", "D"]:
    fit = poisson.fit(coding("age", reference=base).design(data, offset=log_e), data["claims"])
    estimates[base] = {name[-2]: (b, se) for name, b, se in
                       zip(fit.names[2:], fit.coefficients[2:], fit.std_errors[2:])}
nan = float("nan")
by_base = pd.DataFrame({"region": ["A", "B", "C", "D"]})
for base in ["A", "D"]:
    for k, kind in enumerate(["estimate", "std. error"]):
        by_base[f"{kind} {base}"] = [estimates[base].get(g, (nan, nan))[k] for g in by_base["region"]]
(GT(by_base, rowname_col="region")
 .tab_header("Region coefficients by base level", "Poisson claim counts on age and region, log exposure as offset")
 .tab_spanner("Base A", ["estimate A", "std. error A"])
 .tab_spanner("Base D", ["estimate D", "std. error D"])
 .fmt_number(["estimate A", "estimate D"], decimals=3, force_sign=True)
 .fmt_number(["std. error A", "std. error D"], decimals=3)
 .sub_missing(missing_text=""))
```


<style>
#xopzshpljd table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#xopzshpljd thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#xopzshpljd p { margin: 0; padding: 0; }
 #xopzshpljd .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #xopzshpljd .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #xopzshpljd .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #xopzshpljd .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #xopzshpljd .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #xopzshpljd .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #xopzshpljd .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #xopzshpljd .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #xopzshpljd .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #xopzshpljd .gt_column_spanner_outer:first-child { padding-left: 0; }
 #xopzshpljd .gt_column_spanner_outer:last-child { padding-right: 0; }
 #xopzshpljd .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #xopzshpljd .gt_spanner_row { border-bottom-style: hidden; }
 #xopzshpljd .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #xopzshpljd .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #xopzshpljd .gt_from_md> :first-child { margin-top: 0; }
 #xopzshpljd .gt_from_md> :last-child { margin-bottom: 0; }
 #xopzshpljd .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #xopzshpljd .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #xopzshpljd .gt_indent_1 { text-indent: 5px; }
 #xopzshpljd .gt_indent_2 { text-indent: calc(5px * 2); }
 #xopzshpljd .gt_indent_3 { text-indent: calc(5px * 3); }
 #xopzshpljd .gt_indent_4 { text-indent: calc(5px * 4); }
 #xopzshpljd .gt_indent_5 { text-indent: calc(5px * 5); }
 #xopzshpljd .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #xopzshpljd .gt_row_group_first td { border-top-width: 2px; }
 #xopzshpljd .gt_row_group_first th { border-top-width: 2px; }
 #xopzshpljd .gt_striped { color: #333333; background-color: #F4F4F4; }
 #xopzshpljd .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #xopzshpljd .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #xopzshpljd .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #xopzshpljd .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #xopzshpljd .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #xopzshpljd .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #xopzshpljd .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #xopzshpljd .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #xopzshpljd .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #xopzshpljd .gt_left { text-align: left; }
 #xopzshpljd .gt_center { text-align: center; }
 #xopzshpljd .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #xopzshpljd .gt_font_normal { font-weight: normal; }
 #xopzshpljd .gt_font_bold { font-weight: bold; }
 #xopzshpljd .gt_font_italic { font-style: italic; }
 #xopzshpljd .gt_super { font-size: 65%; }
 #xopzshpljd .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #xopzshpljd .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #xopzshpljd .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #xopzshpljd .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #xopzshpljd .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #xopzshpljd .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="5" id="title" class="gt_heading gt_title gt_font_normal">Region coefficients by base level</th>
</tr>
<tr class="gt_heading">
<th colspan="5" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Poisson claim counts on age and region, log exposure as offset</th>
</tr>
<tr class="gt_col_headings gt_spanner_row">
<th rowspan="2" class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th colspan="2" id="Base-A" class="gt_center gt_columns_top_border gt_column_spanner_outer" scope="colgroup">Base A</th>
<th colspan="2" id="Base-D" class="gt_center gt_columns_top_border gt_column_spanner_outer" scope="colgroup">Base D</th>
</tr>
<tr class="gt_col_headings">
<th id="estimate-A" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">estimate A</th>
<th id="std.-error-A" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">std. error A</th>
<th id="estimate-D" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">estimate D</th>
<th id="std.-error-D" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">std. error D</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">A</th>
<td class="gt_row gt_right" headers="stub-1 Base-A estimate-A"></td>
<td class="gt_row gt_right" headers="stub-1 Base-A std.-error-A"></td>
<td class="gt_row gt_right" headers="stub-1 Base-D estimate-D">−0.204</td>
<td class="gt_row gt_right" headers="stub-1 Base-D std.-error-D">0.245</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">B</th>
<td class="gt_row gt_right" headers="stub-2 Base-A estimate-A">+0.078</td>
<td class="gt_row gt_right" headers="stub-2 Base-A std.-error-A">0.192</td>
<td class="gt_row gt_right" headers="stub-2 Base-D estimate-D">−0.126</td>
<td class="gt_row gt_right" headers="stub-2 Base-D std.-error-D">0.253</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">C</th>
<td class="gt_row gt_right" headers="stub-3 Base-A estimate-A">−0.258</td>
<td class="gt_row gt_right" headers="stub-3 Base-A std.-error-A">0.249</td>
<td class="gt_row gt_right" headers="stub-3 Base-D estimate-D">−0.462</td>
<td class="gt_row gt_right" headers="stub-3 Base-D std.-error-D">0.299</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">D</th>
<td class="gt_row gt_right" headers="stub-4 Base-A estimate-A">+0.204</td>
<td class="gt_row gt_right" headers="stub-4 Base-A std.-error-A">0.245</td>
<td class="gt_row gt_right" headers="stub-4 Base-D estimate-D"></td>
<td class="gt_row gt_right" headers="stub-4 Base-D std.-error-D"></td>
</tr>
</tbody>
</table>


The two fits are the same model. With D as the base, every standard error is larger, because every coefficient depends on the thinnest level. The true factors for B, C and D against A are 1.2, 0.8 and 1.5 (log relativities +0.18, -0.22 and +0.41), and with 155 claims the fit pins down none of them. A GLM gives the data full credibility and reports uncertainty only in the standard errors (section 2.10).

The figure shows each log relativity against base A with its 95% interval. The diamond is the true value:


``` python
import matplotlib.pyplot as plt

fit_a = poisson.fit(coding("age").design(data, offset=log_e), data["claims"])
levels = ["B", "C", "D"]
xs = range(len(levels))
fig, ax = plt.subplots()
ax.axhline(0.0, color="0.75")
ax.errorbar([x - 0.06 for x in xs], fit_a.coefficients[2:], yerr=[1.96 * s for s in fit_a.std_errors[2:]],
            fmt="o", capsize=4, label="estimate with 95% interval")
ax.plot([x + 0.06 for x in xs], [math.log(true_r[g]) for g in levels], "D", label="true value")
ax.set_xticks(list(xs), [f"region {g}" for g in levels])
ax.set_ylabel("log relativity against region A")
ax.set_title("Region relativities: every interval covers the truth and zero")
ax.legend()
```


<figure class="p-figure figure">
KICAgIDxnIGlkPSJsaW5lMmRfMzIiPgogICAgIDxnPgogICAgICA8dXNlIGhyZWY9IiNtMzAxNzMyOTRkMyIgeD0iMjY4LjE5ODUxNiIgeT0iMjA1LjUwOTU0NyIgc3R5bGU9ImZpbGw6IHZhcigtLXAtc2VyaWVzLTEpOyBzdHJva2U6IHZhcigtLXAtc2VyaWVzLTEpIiAvPgogICAgIDwvZz4KICAgIDwvZz4KICAgIDxnIGlkPSJ0ZXh0XzE1Ij4KICAgICA8dGV4dCBzdHlsZT0iZm9udC1zaXplOiAxMXB4OyBmb250LWZhbWlseTogdmFyKC0tcC1mb250KTsgdGV4dC1hbmNob3I6IHN0YXJ0OyBmaWxsOiB2YXIoLS1wLWluaykiIHg9IjI4Ny45OTg1MTYiIHk9IjIwOS4zNTk1NDciIHRyYW5zZm9ybT0icm90YXRlKC0wIDI4Ny45OTg1MTYgMjA5LjM1OTU0NykiPmVzdGltYXRlIHdpdGggOTUlIGludGVydmFsPC90ZXh0PgogICAgPC9nPgogICA8L2c+CiAgPC9nPgogPC9nPgogPGRlZnM+CiAgPGNsaXBwYXRoIGlkPSJwMmNkNWIzNDY1MCI+CiAgIDxyZWN0IHg9IjU1LjkxMTk1MyIgeT0iMjIuMzE4MTI1IiB3aWR0aD0iMzkwLjYiIGhlaWdodD0iMTk5LjU4NCIgLz4KICA8L2NsaXBwYXRoPgogPC9kZWZzPgo8L3N2Zz4=" />
</figure>


# 3. Offsets and weights (sections 2.5 and 2.6)

An offset is a predictor with its coefficient fixed at 1: a part of the rating plan that the GLM must respect but not re-estimate, such as deductible factors or territorial base rates. On the log link the offset is the log of the factor, and several offsets add. A weight divides the variance: a row that averages `w` claims has `1/w` of the variance of one claim.


``` python
offsets = [(f"offset, deductible factor {f:.2f}", math.log(f), book, 4)
           for f, book in zip((1.00, 0.95, 0.90), (0.0, -0.0513, -0.1054))]
book_table(offsets + [("log base loss cost 265", math.log(265), 5.5797, 4),
                      ("log loss cost, base 265, factor 0.90", math.log(265) + math.log(0.90), 5.4744, 4)],
           "Offsets of section 2.5")
```


<style>
#estovccqeu table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#estovccqeu thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#estovccqeu p { margin: 0; padding: 0; }
 #estovccqeu .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #estovccqeu .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #estovccqeu .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #estovccqeu .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #estovccqeu .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #estovccqeu .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #estovccqeu .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #estovccqeu .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #estovccqeu .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #estovccqeu .gt_column_spanner_outer:first-child { padding-left: 0; }
 #estovccqeu .gt_column_spanner_outer:last-child { padding-right: 0; }
 #estovccqeu .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #estovccqeu .gt_spanner_row { border-bottom-style: hidden; }
 #estovccqeu .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #estovccqeu .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #estovccqeu .gt_from_md> :first-child { margin-top: 0; }
 #estovccqeu .gt_from_md> :last-child { margin-bottom: 0; }
 #estovccqeu .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #estovccqeu .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #estovccqeu .gt_indent_1 { text-indent: 5px; }
 #estovccqeu .gt_indent_2 { text-indent: calc(5px * 2); }
 #estovccqeu .gt_indent_3 { text-indent: calc(5px * 3); }
 #estovccqeu .gt_indent_4 { text-indent: calc(5px * 4); }
 #estovccqeu .gt_indent_5 { text-indent: calc(5px * 5); }
 #estovccqeu .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #estovccqeu .gt_row_group_first td { border-top-width: 2px; }
 #estovccqeu .gt_row_group_first th { border-top-width: 2px; }
 #estovccqeu .gt_striped { color: #333333; background-color: #F4F4F4; }
 #estovccqeu .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #estovccqeu .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #estovccqeu .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #estovccqeu .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #estovccqeu .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #estovccqeu .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #estovccqeu .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #estovccqeu .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #estovccqeu .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #estovccqeu .gt_left { text-align: left; }
 #estovccqeu .gt_center { text-align: center; }
 #estovccqeu .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #estovccqeu .gt_font_normal { font-weight: normal; }
 #estovccqeu .gt_font_bold { font-weight: bold; }
 #estovccqeu .gt_font_italic { font-style: italic; }
 #estovccqeu .gt_super { font-size: 65%; }
 #estovccqeu .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #estovccqeu .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #estovccqeu .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #estovccqeu .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #estovccqeu .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #estovccqeu .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Offsets of section 2.5</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="monograph" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">monograph</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">offset, deductible factor 1.00</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">0.0000</td>
<td class="gt_row gt_right" headers="stub-1 monograph">0.0000</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">offset, deductible factor 0.95</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">−0.0513</td>
<td class="gt_row gt_right" headers="stub-2 monograph">−0.0513</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">offset, deductible factor 0.90</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">−0.1054</td>
<td class="gt_row gt_right" headers="stub-3 monograph">−0.1054</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">log base loss cost 265</th>
<td class="gt_row gt_right" headers="stub-4 prospicio">5.5797</td>
<td class="gt_row gt_right" headers="stub-4 monograph">5.5797</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">log loss cost, base 265, factor 0.90</th>
<td class="gt_row gt_right" headers="stub-5 prospicio">5.4744</td>
<td class="gt_row gt_right" headers="stub-5 monograph">5.4744</td>
</tr>
</tbody>
</table>


Section 2.6: a Poisson model of the claim count with log exposure as the offset and a Poisson model of the frequency (claims per year) with exposure as the weight give the same coefficients and standard errors. prospicio fits the non-integer frequency as given:


``` python
c = coding("age")
counts = poisson.fit(c.design(data, offset=log_e), data["claims"])
freq = [k / e for k, e in zip(data["claims"], data["exposure"])]
rates = poisson.fit(c.design(data, weights=data["exposure"]), freq)
print("coefficients agree:", max(abs(a - b) for a, b in zip(counts.coefficients, rates.coefficients)) < 1e-9)
print("standard errors agree:", max(abs(a - b) for a, b in zip(counts.std_errors, rates.std_errors)) < 1e-9)
```


    coefficients agree: True
    standard errors agree: True


``` python
(GT(pd.DataFrame({"term": counts.names, "coef, offset": counts.coefficients,
                  "coef, weight": rates.coefficients, "se, offset": counts.std_errors,
                  "se, weight": rates.std_errors}), rowname_col="term")
 .tab_header("Claim counts with an offset, frequency with a weight")
 .fmt_number(decimals=4))
```


<style>
#ntnegvnigs table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#ntnegvnigs thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#ntnegvnigs p { margin: 0; padding: 0; }
 #ntnegvnigs .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #ntnegvnigs .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #ntnegvnigs .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #ntnegvnigs .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #ntnegvnigs .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ntnegvnigs .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ntnegvnigs .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ntnegvnigs .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #ntnegvnigs .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #ntnegvnigs .gt_column_spanner_outer:first-child { padding-left: 0; }
 #ntnegvnigs .gt_column_spanner_outer:last-child { padding-right: 0; }
 #ntnegvnigs .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #ntnegvnigs .gt_spanner_row { border-bottom-style: hidden; }
 #ntnegvnigs .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #ntnegvnigs .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #ntnegvnigs .gt_from_md> :first-child { margin-top: 0; }
 #ntnegvnigs .gt_from_md> :last-child { margin-bottom: 0; }
 #ntnegvnigs .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #ntnegvnigs .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #ntnegvnigs .gt_indent_1 { text-indent: 5px; }
 #ntnegvnigs .gt_indent_2 { text-indent: calc(5px * 2); }
 #ntnegvnigs .gt_indent_3 { text-indent: calc(5px * 3); }
 #ntnegvnigs .gt_indent_4 { text-indent: calc(5px * 4); }
 #ntnegvnigs .gt_indent_5 { text-indent: calc(5px * 5); }
 #ntnegvnigs .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #ntnegvnigs .gt_row_group_first td { border-top-width: 2px; }
 #ntnegvnigs .gt_row_group_first th { border-top-width: 2px; }
 #ntnegvnigs .gt_striped { color: #333333; background-color: #F4F4F4; }
 #ntnegvnigs .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ntnegvnigs .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ntnegvnigs .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #ntnegvnigs .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ntnegvnigs .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ntnegvnigs .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #ntnegvnigs .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #ntnegvnigs .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ntnegvnigs .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ntnegvnigs .gt_left { text-align: left; }
 #ntnegvnigs .gt_center { text-align: center; }
 #ntnegvnigs .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #ntnegvnigs .gt_font_normal { font-weight: normal; }
 #ntnegvnigs .gt_font_bold { font-weight: bold; }
 #ntnegvnigs .gt_font_italic { font-style: italic; }
 #ntnegvnigs .gt_super { font-size: 65%; }
 #ntnegvnigs .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ntnegvnigs .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #ntnegvnigs .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ntnegvnigs .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ntnegvnigs .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #ntnegvnigs .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="5" id="title" class="gt_heading gt_title gt_font_normal">Claim counts with an offset, frequency with a weight</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="coef-offset" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">coef, offset</th>
<th id="coef-weight" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">coef, weight</th>
<th id="se-offset" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">se, offset</th>
<th id="se-weight" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">se, weight</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">(Intercept)</th>
<td class="gt_row gt_right" headers="stub-1 coef-offset">−0.3636</td>
<td class="gt_row gt_right" headers="stub-1 coef-weight">−0.3636</td>
<td class="gt_row gt_right" headers="stub-1 se-offset">0.2394</td>
<td class="gt_row gt_right" headers="stub-1 se-weight">0.2394</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">age</th>
<td class="gt_row gt_right" headers="stub-2 coef-offset">−0.0105</td>
<td class="gt_row gt_right" headers="stub-2 coef-weight">−0.0105</td>
<td class="gt_row gt_right" headers="stub-2 se-offset">0.0045</td>
<td class="gt_row gt_right" headers="stub-2 se-weight">0.0045</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">region[B]</th>
<td class="gt_row gt_right" headers="stub-3 coef-offset">0.0778</td>
<td class="gt_row gt_right" headers="stub-3 coef-weight">0.0778</td>
<td class="gt_row gt_right" headers="stub-3 se-offset">0.1921</td>
<td class="gt_row gt_right" headers="stub-3 se-weight">0.1921</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">region[C]</th>
<td class="gt_row gt_right" headers="stub-4 coef-offset">−0.2581</td>
<td class="gt_row gt_right" headers="stub-4 coef-weight">−0.2581</td>
<td class="gt_row gt_right" headers="stub-4 se-offset">0.2490</td>
<td class="gt_row gt_right" headers="stub-4 se-weight">0.2490</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">region[D]</th>
<td class="gt_row gt_right" headers="stub-5 coef-offset">0.2036</td>
<td class="gt_row gt_right" headers="stub-5 coef-weight">0.2036</td>
<td class="gt_row gt_right" headers="stub-5 se-offset">0.2448</td>
<td class="gt_row gt_right" headers="stub-5 se-weight">0.2448</td>
</tr>
</tbody>
</table>


The age coefficient is close to the true value of -0.01. Footnote 5: the equivalence fails for the negative binomial (section 4).

A fixed external factor works the same way. If the filed region factors are not under review, the offset is `log(exposure) + log(factor)`.


# 4. Choosing the distribution (sections 2.7 and 5.2)

**Frequency.** The Poisson fixes `phi = 1`. The overdispersed Poisson estimates [phi](../reference/reserving.PaidIncurredFit.md#prospicio.reserving.PaidIncurredFit.phi) (prospicio: `dispersion="pearson"`), which keeps the coefficients and scales the standard errors by `sqrt(phi)`. The negative binomial adds a parameter [k](../reference/models.TargetEncoding.md#prospicio.models.TargetEncoding.k) with variance `mu (1 + k mu)`. The `"negative_binomial"` family takes `theta = 1/k` as an input. [NegativeBinomialGlm](../reference/models.NegativeBinomialGlm.md#prospicio.models.NegativeBinomialGlm) estimates [theta](../reference/models.TwoPartFit.md#prospicio.models.TwoPartFit.theta) with the coefficients by maximum likelihood (as R's `MASS::glm.nb` does). The `nb` column was drawn with `theta = 2`:


``` python
from prospicio.models import NegativeBinomialGlm

c = coding("age")
odp = Glm("poisson", "log", dispersion="pearson").fit(c.design(data, offset=log_e), data["claims"])
print(f"overdispersed Poisson: phi {odp.dispersion:.3f}, same coefficients:",
      max(abs(a - b) for a, b in zip(odp.coefficients, counts.coefficients)) < 1e-12,
      f", age se {counts.std_errors[1]:.5f} -> {odp.std_errors[1]:.5f}")
nb = NegativeBinomialGlm().fit(c.design(data, offset=log_e), data["nb"])
print(f"negative binomial: theta {nb.theta:.2f} (se {nb.se_theta:.2f}, drawn with 2),"
      f" log-likelihood {nb.log_likelihood:.1f}")
```


    overdispersed Poisson: phi 0.944, same coefficients: True , age se 0.00452 -> 0.00439
    negative binomial: theta 1.40 (se 0.21, drawn with 2), log-likelihood -899.8


The Poisson data are not overdispersed ([phi](../reference/reserving.PaidIncurredFit.md#prospicio.reserving.PaidIncurredFit.phi) is just under 1). The estimated [theta](../reference/models.TwoPartFit.md#prospicio.models.TwoPartFit.theta) is below the 2 that drew the column: sampling variation in 600 policies. Because the variance contains [theta](../reference/models.TwoPartFit.md#prospicio.models.TwoPartFit.theta), a count model with an offset and a frequency model with a weight estimate it differently (footnote 5).

**Severity.** The gamma (`V = mu^2`) is the usual choice. The inverse Gaussian (`V = mu^3`) suits more skewed data. Section 6.3.1 decides between them with deviance residuals, which look roughly normal if the family is right. A right-skewed histogram means the data are more skewed than the family assumes. `GlmFit.diagnostics(design, y)` returns the residuals, leverages and Cook's distances. The `ig` column was drawn from an inverse Gaussian:


``` python
def skewness(xs):
    m = sum(xs) / len(xs)
    s2 = sum((x - m) ** 2 for x in xs) / len(xs)
    return sum((x - m) ** 3 for x in xs) / len(xs) / s2 ** 1.5


sev_design = coding("age").design(data)
fits = []
for family in ["gamma", "inverse_gaussian"]:
    fit = Glm(family, "log").fit(sev_design, data["ig"])
    r = fit.diagnostics(sev_design, data["ig"])["deviance"]
    fits.append((family, fit.aic, skewness(r)))
(GT(pd.DataFrame(fits, columns=["family", "AIC", "residual skewness"]), rowname_col="family")
 .tab_header("Severity families on the inverse Gaussian column", "Log link, age and region")
 .fmt_number("AIC", decimals=1)
 .fmt_number("residual skewness", decimals=2, force_sign=True))
```


<style>
#iwxwwxgbxb table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#iwxwwxgbxb thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#iwxwwxgbxb p { margin: 0; padding: 0; }
 #iwxwwxgbxb .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #iwxwwxgbxb .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #iwxwwxgbxb .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #iwxwwxgbxb .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #iwxwwxgbxb .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #iwxwwxgbxb .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #iwxwwxgbxb .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #iwxwwxgbxb .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #iwxwwxgbxb .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #iwxwwxgbxb .gt_column_spanner_outer:first-child { padding-left: 0; }
 #iwxwwxgbxb .gt_column_spanner_outer:last-child { padding-right: 0; }
 #iwxwwxgbxb .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #iwxwwxgbxb .gt_spanner_row { border-bottom-style: hidden; }
 #iwxwwxgbxb .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #iwxwwxgbxb .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #iwxwwxgbxb .gt_from_md> :first-child { margin-top: 0; }
 #iwxwwxgbxb .gt_from_md> :last-child { margin-bottom: 0; }
 #iwxwwxgbxb .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #iwxwwxgbxb .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #iwxwwxgbxb .gt_indent_1 { text-indent: 5px; }
 #iwxwwxgbxb .gt_indent_2 { text-indent: calc(5px * 2); }
 #iwxwwxgbxb .gt_indent_3 { text-indent: calc(5px * 3); }
 #iwxwwxgbxb .gt_indent_4 { text-indent: calc(5px * 4); }
 #iwxwwxgbxb .gt_indent_5 { text-indent: calc(5px * 5); }
 #iwxwwxgbxb .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #iwxwwxgbxb .gt_row_group_first td { border-top-width: 2px; }
 #iwxwwxgbxb .gt_row_group_first th { border-top-width: 2px; }
 #iwxwwxgbxb .gt_striped { color: #333333; background-color: #F4F4F4; }
 #iwxwwxgbxb .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #iwxwwxgbxb .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #iwxwwxgbxb .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #iwxwwxgbxb .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #iwxwwxgbxb .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #iwxwwxgbxb .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #iwxwwxgbxb .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #iwxwwxgbxb .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #iwxwwxgbxb .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #iwxwwxgbxb .gt_left { text-align: left; }
 #iwxwwxgbxb .gt_center { text-align: center; }
 #iwxwwxgbxb .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #iwxwwxgbxb .gt_font_normal { font-weight: normal; }
 #iwxwwxgbxb .gt_font_bold { font-weight: bold; }
 #iwxwwxgbxb .gt_font_italic { font-style: italic; }
 #iwxwwxgbxb .gt_super { font-size: 65%; }
 #iwxwwxgbxb .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #iwxwwxgbxb .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #iwxwwxgbxb .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #iwxwwxgbxb .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #iwxwwxgbxb .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #iwxwwxgbxb .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Severity families on the inverse Gaussian column</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Log link, age and region</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="AIC" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">AIC</th>
<th id="residual-skewness" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">residual skewness</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">gamma</th>
<td class="gt_row gt_right" headers="stub-1 AIC">8,240.2</td>
<td class="gt_row gt_right" headers="stub-1 residual-skewness">+0.52</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">inverse_gaussian</th>
<td class="gt_row gt_right" headers="stub-2 AIC">8,196.7</td>
<td class="gt_row gt_right" headers="stub-2 residual-skewness">+0.05</td>
</tr>
</tbody>
</table>


The gamma leaves right-skewed residuals. The inverse Gaussian gives nearly symmetric ones and the lower AIC, the pattern of Figures 16 and 17:


``` python
fig, axes = plt.subplots(1, 2, sharey=True, sharex=True)
for ax, family in zip(axes, ["gamma", "inverse_gaussian"]):
    fit = Glm(family, "log").fit(sev_design, data["ig"])
    r = fit.diagnostics(sev_design, data["ig"])["deviance"]
    sd = (sum(x * x for x in r) / len(r)) ** 0.5
    ax.hist([x / sd for x in r], bins=30)
    ax.set_title(f"{family}: skewness {skewness(r):+.2f}")
    ax.set_xlabel("deviance residual (sd units)")
axes[0].set_ylabel("policies")
```


    Text(0, 0.5, 'policies')


<figure class="p-figure figure">
pOyBzdHJva2U6IHZhcigtLXAtbXV0ZWQpOyBzdHJva2Utd2lkdGg6IDAuOCIgLz4KICAgICAgPC9nPgogICAgIDwvZz4KICAgIDwvZz4KICAgIDxnIGlkPSJ5dGlja18xMCI+CiAgICAgPGcgaWQ9ImxpbmUyZF8zMSI+CiAgICAgIDxwYXRoIGQ9Ik0gMjU2LjI1MjkwNSAxMTguMjIyMTI1IApMIDQzMy43OTgzNTkgMTE4LjIyMjEyNSAKIiBjbGlwLXBhdGg9InVybCgjcGFkZmU4ODZlNGEpIiBzdHlsZT0iZmlsbDogbm9uZTsgc3Ryb2tlOiB2YXIoLS1wLXJ1bGUpOyBzdHJva2Utd2lkdGg6IDAuODsgc3Ryb2tlLWxpbmVjYXA6IHNxdWFyZSIgLz4KICAgICA8L2c+CiAgICAgPGcgaWQ9ImxpbmUyZF8zMiI+CiAgICAgIDxnPgogICAgICAgPHVzZSBocmVmPSIjbWJmOWFhOTZlNTAiIHg9IjI1Ni4yNTI5MDUiIHk9IjExOC4yMjIxMjUiIHN0eWxlPSJmaWxsOiB2YXIoLS1wLW11dGVkKTsgc3Ryb2tlOiB2YXIoLS1wLW11dGVkKTsgc3Ryb2tlLXdpZHRoOiAwLjgiIC8+CiAgICAgIDwvZz4KICAgICA8L2c+CiAgICA8L2c+CiAgICA8ZyBpZD0ieXRpY2tfMTEiPgogICAgIDxnIGlkPSJsaW5lMmRfMzMiPgogICAgICA8cGF0aCBkPSJNIDI1Ni4yNTI5MDUgODMuNjYyMTI1IApMIDQzMy43OTgzNTkgODMuNjYyMTI1IAoiIGNsaXAtcGF0aD0id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c3LjU0NTQ1NSIgaGVpZ2h0PSIxOTkuNTg0IiAvPgogIDwvY2xpcHBhdGg+CiA8L2RlZnM+Cjwvc3ZnPg==" />
</figure>


A severity row that averages several claims carries the claim count as its weight (section 2.5). A gamma fit weighted by `n_sev` recovers the true region factors:


``` python
sev = Glm("gamma", "log").fit(coding("age").design(data, weights=data["n_sev"]), data["avg_sev"])
print(f"weighted gamma dispersion {sev.dispersion:.3f}")
```


    weighted gamma dispersion 0.533


``` python
(GT(pd.DataFrame({"region": ["B", "C", "D"], "true": [true_r[g] for g in "BCD"],
                  "fitted": [math.exp(b) for b in sev.coefficients[2:]]}), rowname_col="region")
 .tab_header("Severity relativities against region A", "Gamma, claim count as weight")
 .fmt_number(["true", "fitted"], decimals=3))
```


<style>
#lewiqcsqtn table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#lewiqcsqtn thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#lewiqcsqtn p { margin: 0; padding: 0; }
 #lewiqcsqtn .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #lewiqcsqtn .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #lewiqcsqtn .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #lewiqcsqtn .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #lewiqcsqtn .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #lewiqcsqtn .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lewiqcsqtn .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #lewiqcsqtn .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #lewiqcsqtn .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #lewiqcsqtn .gt_column_spanner_outer:first-child { padding-left: 0; }
 #lewiqcsqtn .gt_column_spanner_outer:last-child { padding-right: 0; }
 #lewiqcsqtn .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #lewiqcsqtn .gt_spanner_row { border-bottom-style: hidden; }
 #lewiqcsqtn .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #lewiqcsqtn .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #lewiqcsqtn .gt_from_md> :first-child { margin-top: 0; }
 #lewiqcsqtn .gt_from_md> :last-child { margin-bottom: 0; }
 #lewiqcsqtn .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #lewiqcsqtn .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #lewiqcsqtn .gt_indent_1 { text-indent: 5px; }
 #lewiqcsqtn .gt_indent_2 { text-indent: calc(5px * 2); }
 #lewiqcsqtn .gt_indent_3 { text-indent: calc(5px * 3); }
 #lewiqcsqtn .gt_indent_4 { text-indent: calc(5px * 4); }
 #lewiqcsqtn .gt_indent_5 { text-indent: calc(5px * 5); }
 #lewiqcsqtn .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #lewiqcsqtn .gt_row_group_first td { border-top-width: 2px; }
 #lewiqcsqtn .gt_row_group_first th { border-top-width: 2px; }
 #lewiqcsqtn .gt_striped { color: #333333; background-color: #F4F4F4; }
 #lewiqcsqtn .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lewiqcsqtn .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #lewiqcsqtn .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #lewiqcsqtn .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lewiqcsqtn .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #lewiqcsqtn .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #lewiqcsqtn .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #lewiqcsqtn .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lewiqcsqtn .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #lewiqcsqtn .gt_left { text-align: left; }
 #lewiqcsqtn .gt_center { text-align: center; }
 #lewiqcsqtn .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #lewiqcsqtn .gt_font_normal { font-weight: normal; }
 #lewiqcsqtn .gt_font_bold { font-weight: bold; }
 #lewiqcsqtn .gt_font_italic { font-style: italic; }
 #lewiqcsqtn .gt_super { font-size: 65%; }
 #lewiqcsqtn .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lewiqcsqtn .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #lewiqcsqtn .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lewiqcsqtn .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #lewiqcsqtn .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #lewiqcsqtn .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Severity relativities against region A</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Gamma, claim count as weight</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="true" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">true</th>
<th id="fitted" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">fitted</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">B</th>
<td class="gt_row gt_right" headers="stub-1 true">1.200</td>
<td class="gt_row gt_right" headers="stub-1 fitted">1.268</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">C</th>
<td class="gt_row gt_right" headers="stub-2 true">0.800</td>
<td class="gt_row gt_right" headers="stub-2 fitted">0.853</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">D</th>
<td class="gt_row gt_right" headers="stub-3 true">1.500</td>
<td class="gt_row gt_right" headers="stub-3 fitted">1.474</td>
</tr>
</tbody>
</table>


**Pure premium.** The Tweedie with power `1 < p < 2` is a Poisson number of gamma losses, with a point mass at zero. Section 2.7.3 gives its parameters from the Poisson mean `lambda`, the gamma shape [alpha](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.alpha) and the gamma scale [theta](../reference/models.TwoPartFit.md#prospicio.models.TwoPartFit.theta):

- mean: `lambda alpha theta` (equation 7),
- power: `(alpha + 2) / (alpha + 1)` (equation 8),
- dispersion: `lambda^(1-p) (alpha theta)^(2-p) / (2 - p)` (equation 9).

[Tweedie.from_poisson_gamma](../reference/distributions.Tweedie.md#prospicio.distributions.Tweedie.from_poisson_gamma) does the conversion. The `pure` column was drawn with gamma shape 2 and scale 500, so equation 8 gives `p = 4/3`:


``` python
from prospicio.distributions import Tweedie

lam, alpha, scale = 0.4, 2.0, 500.0
tw = Tweedie.from_poisson_gamma(lam, alpha, scale)
p = (alpha + 2) / (alpha + 1)
book_table([
    ("mean", tw.mean(), lam * alpha * scale, 1),
    ("power", tw.power, p, 4),
    ("dispersion", tw.dispersion, lam ** (1 - p) * (alpha * scale) ** (2 - p) / (2 - p), 3),
], "Tweedie parameters from Poisson-gamma parameters", "Lambda 0.4, alpha 2, scale 500", book="equations 7 to 9")
```


<style>
#ftxcwcwfof table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#ftxcwcwfof thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#ftxcwcwfof p { margin: 0; padding: 0; }
 #ftxcwcwfof .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #ftxcwcwfof .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #ftxcwcwfof .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #ftxcwcwfof .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #ftxcwcwfof .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ftxcwcwfof .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ftxcwcwfof .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ftxcwcwfof .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #ftxcwcwfof .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #ftxcwcwfof .gt_column_spanner_outer:first-child { padding-left: 0; }
 #ftxcwcwfof .gt_column_spanner_outer:last-child { padding-right: 0; }
 #ftxcwcwfof .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #ftxcwcwfof .gt_spanner_row { border-bottom-style: hidden; }
 #ftxcwcwfof .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #ftxcwcwfof .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #ftxcwcwfof .gt_from_md> :first-child { margin-top: 0; }
 #ftxcwcwfof .gt_from_md> :last-child { margin-bottom: 0; }
 #ftxcwcwfof .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #ftxcwcwfof .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #ftxcwcwfof .gt_indent_1 { text-indent: 5px; }
 #ftxcwcwfof .gt_indent_2 { text-indent: calc(5px * 2); }
 #ftxcwcwfof .gt_indent_3 { text-indent: calc(5px * 3); }
 #ftxcwcwfof .gt_indent_4 { text-indent: calc(5px * 4); }
 #ftxcwcwfof .gt_indent_5 { text-indent: calc(5px * 5); }
 #ftxcwcwfof .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #ftxcwcwfof .gt_row_group_first td { border-top-width: 2px; }
 #ftxcwcwfof .gt_row_group_first th { border-top-width: 2px; }
 #ftxcwcwfof .gt_striped { color: #333333; background-color: #F4F4F4; }
 #ftxcwcwfof .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ftxcwcwfof .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ftxcwcwfof .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #ftxcwcwfof .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ftxcwcwfof .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ftxcwcwfof .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #ftxcwcwfof .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #ftxcwcwfof .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ftxcwcwfof .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ftxcwcwfof .gt_left { text-align: left; }
 #ftxcwcwfof .gt_center { text-align: center; }
 #ftxcwcwfof .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #ftxcwcwfof .gt_font_normal { font-weight: normal; }
 #ftxcwcwfof .gt_font_bold { font-weight: bold; }
 #ftxcwcwfof .gt_font_italic { font-style: italic; }
 #ftxcwcwfof .gt_super { font-size: 65%; }
 #ftxcwcwfof .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ftxcwcwfof .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #ftxcwcwfof .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ftxcwcwfof .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ftxcwcwfof .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #ftxcwcwfof .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Tweedie parameters from Poisson-gamma parameters</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Lambda 0.4, alpha 2, scale 500</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="equations-7-to-9" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">equations 7 to 9</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">mean</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">400.0</td>
<td class="gt_row gt_right" headers="stub-1 equations-7-to-9">400.0</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">power</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">1.3333</td>
<td class="gt_row gt_right" headers="stub-2 equations-7-to-9">1.3333</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">dispersion</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">203.581</td>
<td class="gt_row gt_right" headers="stub-3 equations-7-to-9">203.581</td>
</tr>
</tbody>
</table>


The monograph picks [p](../reference/models.Elpd.md#prospicio.models.Elpd.p) by estimating it, by comparing candidates on log-likelihood or cross-validation, or by a customary 1.6 to 1.7. [tweedie_profile](../reference/models.tweedie_profile.md#prospicio.models.tweedie_profile) does the first: for each [p](../reference/models.Elpd.md#prospicio.models.Elpd.p) it maximizes the exact Tweedie log-likelihood over [phi](../reference/reserving.PaidIncurredFit.md#prospicio.reserving.PaidIncurredFit.phi) (the Dunn and Smyth series density, with dispersion `phi / w` for exposure weight `w`). [TweedieGlm](../reference/models.TweedieGlm.md#prospicio.models.TweedieGlm) estimates [p](../reference/models.Elpd.md#prospicio.models.Elpd.p) directly, with a 95% profile-likelihood interval:


``` python
from prospicio.models import TweedieGlm, tweedie_profile

pp = coding("age").design(data, weights=data["exposure"])
profile = tweedie_profile(pp, data["pure"], [1.2, 1.3, 1.4, 1.5, 1.6, 1.7])
tw_fit = TweedieGlm().fit(pp, data["pure"])
lo, hi = tw_fit.interval
print(f"estimated p {tw_fit.power:.3f} (95% interval {lo:.3f} to {hi:.3f}), phi {tw_fit.dispersion:.1f}")
```


    estimated p 1.314 (95% interval 1.264 to 1.371), phi 200.1


``` python
profile_table = pd.DataFrame({"p": profile["powers"], "log-likelihood": profile["log_likelihood"],
                              "dispersion phi": profile["dispersion"]})
(GT(profile_table, rowname_col="p")
 .tab_header("Tweedie profile likelihood by power", "Pure premium on age and region, exposure as weight")
 .fmt_number(["log-likelihood", "dispersion phi"], decimals=1))
```


<style>
#klkunbfxmt table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#klkunbfxmt thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#klkunbfxmt p { margin: 0; padding: 0; }
 #klkunbfxmt .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #klkunbfxmt .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #klkunbfxmt .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #klkunbfxmt .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #klkunbfxmt .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #klkunbfxmt .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #klkunbfxmt .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #klkunbfxmt .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #klkunbfxmt .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #klkunbfxmt .gt_column_spanner_outer:first-child { padding-left: 0; }
 #klkunbfxmt .gt_column_spanner_outer:last-child { padding-right: 0; }
 #klkunbfxmt .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #klkunbfxmt .gt_spanner_row { border-bottom-style: hidden; }
 #klkunbfxmt .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #klkunbfxmt .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #klkunbfxmt .gt_from_md> :first-child { margin-top: 0; }
 #klkunbfxmt .gt_from_md> :last-child { margin-bottom: 0; }
 #klkunbfxmt .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #klkunbfxmt .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #klkunbfxmt .gt_indent_1 { text-indent: 5px; }
 #klkunbfxmt .gt_indent_2 { text-indent: calc(5px * 2); }
 #klkunbfxmt .gt_indent_3 { text-indent: calc(5px * 3); }
 #klkunbfxmt .gt_indent_4 { text-indent: calc(5px * 4); }
 #klkunbfxmt .gt_indent_5 { text-indent: calc(5px * 5); }
 #klkunbfxmt .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #klkunbfxmt .gt_row_group_first td { border-top-width: 2px; }
 #klkunbfxmt .gt_row_group_first th { border-top-width: 2px; }
 #klkunbfxmt .gt_striped { color: #333333; background-color: #F4F4F4; }
 #klkunbfxmt .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #klkunbfxmt .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #klkunbfxmt .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #klkunbfxmt .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #klkunbfxmt .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #klkunbfxmt .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #klkunbfxmt .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #klkunbfxmt .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #klkunbfxmt .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #klkunbfxmt .gt_left { text-align: left; }
 #klkunbfxmt .gt_center { text-align: center; }
 #klkunbfxmt .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #klkunbfxmt .gt_font_normal { font-weight: normal; }
 #klkunbfxmt .gt_font_bold { font-weight: bold; }
 #klkunbfxmt .gt_font_italic { font-style: italic; }
 #klkunbfxmt .gt_super { font-size: 65%; }
 #klkunbfxmt .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #klkunbfxmt .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #klkunbfxmt .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #klkunbfxmt .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #klkunbfxmt .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #klkunbfxmt .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Tweedie profile likelihood by power</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Pure premium on age and region, exposure as weight</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="log-likelihood" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">log-likelihood</th>
<th id="dispersion-phi" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">dispersion phi</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">1.2</th>
<td class="gt_row gt_right" headers="stub-1 log-likelihood">−1,430.1</td>
<td class="gt_row gt_right" headers="stub-1 dispersion-phi">329.0</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">1.3</th>
<td class="gt_row gt_right" headers="stub-2 log-likelihood">−1,417.0</td>
<td class="gt_row gt_right" headers="stub-2 dispersion-phi">212.8</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">1.4</th>
<td class="gt_row gt_right" headers="stub-3 log-likelihood">−1,421.0</td>
<td class="gt_row gt_right" headers="stub-3 dispersion-phi">137.0</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">1.5</th>
<td class="gt_row gt_right" headers="stub-4 log-likelihood">−1,433.4</td>
<td class="gt_row gt_right" headers="stub-4 dispersion-phi">89.9</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">1.6</th>
<td class="gt_row gt_right" headers="stub-5 log-likelihood">−1,452.3</td>
<td class="gt_row gt_right" headers="stub-5 dispersion-phi">61.1</td>
</tr>
<tr>
<th id="stub-6" class="gt_row gt_left gt_stub" scope="row">1.7</th>
<td class="gt_row gt_right" headers="stub-6 log-likelihood">−1,479.2</td>
<td class="gt_row gt_right" headers="stub-6 dispersion-phi">44.2</td>
</tr>
</tbody>
</table>


The profile peaks near the true value of 4/3, inside the interval. The monograph advises separate frequency and severity models where the data allow (section 5.1.1), because the Tweedie's constant [phi](../reference/reserving.PaidIncurredFit.md#prospicio.reserving.PaidIncurredFit.phi) assumes that frequency and severity move together. Here region moves frequency only, and a pure premium model cannot tell this from a severity effect.


# 5. Variable significance and comparing models (sections 2.3 and 6.1 to 6.2)

Each coefficient has a standard error and a p-value (prospicio: [std_errors](../reference/models.GlmFit.md#prospicio.models.GlmFit.std_errors), [p_values](../reference/models.GlmFit.md#prospicio.models.GlmFit.p_values)), normal for a fixed dispersion and Student's t for an estimated one. To test a group of parameters, such as all levels of a factor, the monograph uses the F-test on nested models (section 6.2.1). The statistic is the drop in unscaled deviance divided by the number of added parameters times the dispersion of the larger model. It refers to an F distribution with that many numerator degrees of freedom and `n - p` denominator degrees of freedom.

The monograph's example adds a five-level territory (4 parameters) to a 6-parameter model on 972 rows. For two fitted models, [f_test](../reference/models.f_test.md#prospicio.models.f_test) does the whole test (as R's `anova(small, big, test = "F")` does). The monograph prints only the deviances, so the code uses the F distribution function, a regularized incomplete beta, `P(F <= f) = I(d1 f / (d1 f + d2); d1/2, d2/2)`, from [Beta](../reference/distributions.Beta.md#prospicio.distributions.Beta):


``` python
from prospicio.distributions import Beta


def f_cdf(f, d1, d2):
    return Beta(d1 / 2, d2 / 2).cdf(d1 * f / (d1 * f + d2))


F = (365.8 - 352.1) / (4 * 1.42)
print(f"F = {F:.3f}  (monograph 2.412); percentile on F(4, 962): {f_cdf(F, 4, 972 - 10):.1%}  (monograph 95.2%)")
```


    F = 2.412  (monograph 2.412); percentile on F(4, 962): 95.2%  (monograph 95.2%)


The same test asks whether region belongs in the claim frequency model. It uses the overdispersed Poisson, so that [f_test](../reference/models.f_test.md#prospicio.models.f_test) estimates [phi](../reference/reserving.PaidIncurredFit.md#prospicio.reserving.PaidIncurredFit.phi). Section 6.2.2 adds AIC (`-2 loglik + 2p`) and BIC (`-2 loglik + p ln n`), both on [GlmFit](../reference/models.GlmFit.md#prospicio.models.GlmFit):


``` python
from prospicio.models import f_test

quasi = Glm("poisson", "log", dispersion="pearson")
age_only = Terms().intercept().numeric("age").fit(data)
small = quasi.fit(age_only.design(data, offset=log_e), data["claims"])
big = quasi.fit(coding("age").design(data, offset=log_e), data["claims"])
test = f_test(small, big)
print(f"region: F = {test['statistic']:.3f} on ({test['df']:.0f}, {test['df_resid']:.0f}),"
      f" percentile {1 - test['p_value']:.1%}")
```


    region: F = 0.970 on (3, 595), percentile 59.4%


``` python
scores = []
for name, model in [("age", age_only), ("age + region", coding("age"))]:
    fit = poisson.fit(model.design(data, offset=log_e), data["claims"])
    scores.append((name, fit.deviance, fit.aic, fit.bic))
(GT(pd.DataFrame(scores, columns=["model", "deviance", "AIC", "BIC"]), rowname_col="model")
 .tab_header("Claim frequency models", "Poisson, log exposure as offset")
 .fmt_number(["deviance", "AIC", "BIC"], decimals=1))
```


<style>
#fcgracakmq table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#fcgracakmq thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#fcgracakmq p { margin: 0; padding: 0; }
 #fcgracakmq .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #fcgracakmq .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #fcgracakmq .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #fcgracakmq .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #fcgracakmq .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fcgracakmq .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fcgracakmq .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fcgracakmq .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #fcgracakmq .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #fcgracakmq .gt_column_spanner_outer:first-child { padding-left: 0; }
 #fcgracakmq .gt_column_spanner_outer:last-child { padding-right: 0; }
 #fcgracakmq .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #fcgracakmq .gt_spanner_row { border-bottom-style: hidden; }
 #fcgracakmq .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #fcgracakmq .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #fcgracakmq .gt_from_md> :first-child { margin-top: 0; }
 #fcgracakmq .gt_from_md> :last-child { margin-bottom: 0; }
 #fcgracakmq .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #fcgracakmq .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #fcgracakmq .gt_indent_1 { text-indent: 5px; }
 #fcgracakmq .gt_indent_2 { text-indent: calc(5px * 2); }
 #fcgracakmq .gt_indent_3 { text-indent: calc(5px * 3); }
 #fcgracakmq .gt_indent_4 { text-indent: calc(5px * 4); }
 #fcgracakmq .gt_indent_5 { text-indent: calc(5px * 5); }
 #fcgracakmq .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #fcgracakmq .gt_row_group_first td { border-top-width: 2px; }
 #fcgracakmq .gt_row_group_first th { border-top-width: 2px; }
 #fcgracakmq .gt_striped { color: #333333; background-color: #F4F4F4; }
 #fcgracakmq .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fcgracakmq .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fcgracakmq .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #fcgracakmq .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fcgracakmq .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fcgracakmq .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #fcgracakmq .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #fcgracakmq .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fcgracakmq .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fcgracakmq .gt_left { text-align: left; }
 #fcgracakmq .gt_center { text-align: center; }
 #fcgracakmq .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #fcgracakmq .gt_font_normal { font-weight: normal; }
 #fcgracakmq .gt_font_bold { font-weight: bold; }
 #fcgracakmq .gt_font_italic { font-style: italic; }
 #fcgracakmq .gt_super { font-size: 65%; }
 #fcgracakmq .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fcgracakmq .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #fcgracakmq .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fcgracakmq .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fcgracakmq .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #fcgracakmq .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="4" id="title" class="gt_heading gt_title gt_font_normal">Claim frequency models</th>
</tr>
<tr class="gt_heading">
<th colspan="4" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Poisson, log exposure as offset</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="deviance" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">deviance</th>
<th id="AIC" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">AIC</th>
<th id="BIC" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">BIC</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">age</th>
<td class="gt_row gt_right" headers="stub-1 deviance">445.3</td>
<td class="gt_row gt_right" headers="stub-1 AIC">730.0</td>
<td class="gt_row gt_right" headers="stub-1 BIC">738.8</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">age + region</th>
<td class="gt_row gt_right" headers="stub-2 deviance">442.6</td>
<td class="gt_row gt_right" headers="stub-2 AIC">733.3</td>
<td class="gt_row gt_right" headers="stub-2 BIC">755.2</td>
</tr>
</tbody>
</table>


Region has an effect in the true model, but with 155 claims the test cannot see it (the 59th percentile is far short of 95%). Both criteria prefer the smaller model, BIC more strongly. As the monograph cautions, a high p-value is absence of evidence, not evidence of absence, and business knowledge also decides whether to keep a variable.


# 6. Where each step lives in prospicio

The monograph's steps in prospicio, including steps that the guides only mention:

| Monograph step | In prospicio |
|----|----|
| Interactions, polynomials, hinge functions, bins and natural cubic splines as model terms (5.4, 5.6) | [Terms.interaction](../reference/models.Terms.md#prospicio.models.Terms.interaction), [poly](../reference/models.Terms.md#prospicio.models.Terms.poly), [hinges](../reference/models.Terms.md#prospicio.models.Terms.hinges), [bins](../reference/models.Terms.md#prospicio.models.Terms.bins) and [natural_spline](../reference/models.Terms.md#prospicio.models.Terms.natural_spline) (the R binding takes a formula, so [poly](../reference/models.Terms.md#prospicio.models.Terms.poly), `splines::ns` and `a:b` work there) |
| Residuals (deviance, Pearson, working, randomized quantile), hat values, Cook's distance (6.3, 6.4) | [GlmFit.diagnostics](../reference/models.GlmFit.md#prospicio.models.GlmFit.diagnostics) and [GlmFit.quantile_residuals](../reference/models.GlmFit.md#prospicio.models.GlmFit.quantile_residuals) |
| F-test of nested models, BIC, VIF (2.9, 6.2) | [f_test](../reference/models.f_test.md#prospicio.models.f_test), [likelihood_ratio_test](../reference/models.likelihood_ratio_test.md#prospicio.models.likelihood_ratio_test), [GlmFit.bic](../reference/models.GlmFit.md#prospicio.models.GlmFit.bic) and [vif](../reference/models.vif.md#prospicio.models.vif) |
| Negative binomial [k](../reference/models.TargetEncoding.md#prospicio.models.TargetEncoding.k) estimated with the model (2.7.2) | [NegativeBinomialGlm](../reference/models.NegativeBinomialGlm.md#prospicio.models.NegativeBinomialGlm) |
| Tweedie power by profile likelihood (2.7.3) | [TweedieGlm](../reference/models.TweedieGlm.md#prospicio.models.TweedieGlm) and [tweedie_profile](../reference/models.tweedie_profile.md#prospicio.models.tweedie_profile) |
| Double lift chart, loss ratio chart, ROC curve and AUROC (7.2, 7.3) | [double_lift](../reference/models.double_lift.md#prospicio.models.double_lift), [loss_ratio_chart](../reference/models.loss_ratio_chart.md#prospicio.models.loss_ratio_chart), [roc](../reference/models.roc.md#prospicio.models.roc), [confusion_matrix](../reference/models.confusion_matrix.md#prospicio.models.confusion_matrix) and [normalized_gini](../reference/models.normalized_gini.md#prospicio.models.normalized_gini) |
| GLMMs, double GLMs (dispersion modelling), MARS (10.1, 10.2, 10.4) | [Glmm](../reference/models.Glmm.md#prospicio.models.Glmm) (and [BayesGlmm](../reference/models.BayesGlmm.md#prospicio.models.BayesGlmm)), [DoubleGlm](../reference/models.DoubleGlm.md#prospicio.models.DoubleGlm) and [mars](../reference/models.mars.md#prospicio.models.mars) |

prospicio also has GAMs with P-spline, cyclic, monotone and tensor smooths, and elastic nets for every family. It has sandwich standard errors ([GlmFit.robust_std_errors](../reference/models.GlmFit.md#prospicio.models.GlmFit.robust_std_errors)), [predict_distribution](../reference/models.GlmFit.md#prospicio.models.GlmFit.predict_distribution) for the full predictive distribution of a fitted GLM, and JSON artifacts for a fitted rating model.
