View source: R/model_rating_table.R
| rating_table | R Documentation |
rating_table() extracts model coefficients in tariff-table form. It adds
the reference level for factor variables, can exponentiate GLM coefficients
into relativities, and can add exposure by risk-factor level when the model
data are available.
In pricing work, this function is useful after fitting or refining a GLM. It
turns model output into a table that is easier to inspect, compare and use in
tariff notes. When exponentiate = TRUE, coefficients are shown as
relativities. This is often the most practical scale for multiplicative GLM
tariffs, because each level is expressed relative to the reference level.
rating_table() is intended for fitted models:
plain glm objects
models obtained after refit()
models obtained after refit_glm()
For pre-refit objects (rating_refinement, restricted, smooth) use
print(), summary() and autoplot() instead.
rating_table(
...,
model_data = NULL,
exposure = TRUE,
exposure_output = NULL,
exponentiate = TRUE,
significance = FALSE,
round_exposure = 0,
exposure_name = NULL,
signif_stars = NULL
)
... |
glm object(s) produced by |
model_data |
Optional data.frame used to create the model(s). If |
exposure |
Logical or character. If |
exposure_output |
Optional name for the exposure column in the output.
If |
exponentiate |
Logical. If |
significance |
Logical; if |
round_exposure |
number of digits for exposure (defaults to 0) |
exposure_name |
Deprecated. Use |
signif_stars |
Deprecated. Use |
A rating_table contains one row per model term level. For factor variables,
the reference level is added explicitly with relativity 1 when
exponentiate = TRUE, or coefficient 0 when exponentiate = FALSE.
If exposure is supplied or can be inferred from the model data, exposure is aggregated by risk-factor level. This helps to assess whether fitted relativities are supported by enough portfolio volume.
Multiple models can be supplied to compare fitted effects side by side. This is useful when comparing unrestricted and refined models, or frequency, severity and pure premium models built on the same rating factors.
Object of class "rating_table" and legacy class "riskfactor".
as_gt() for a grouped presentation table and
autoplot.rating_table() for a graphical comparison of fitted effects.
df <- MTPL
df$zip <- as.factor(df$zip)
freq <- glm(
nclaims ~ bm + zip + offset(log(exposure)),
family = poisson(),
data = df
)
# Inspect fitted relativities by risk-factor level
rating_table(freq, model_data = df, exposure = "exposure")
# Keep coefficients on the model scale instead of exponentiating
rating_table(
freq,
model_data = df,
exposure = "exposure",
exponentiate = FALSE
)
# Add significance indicators when reviewing model terms
rating_table(
freq,
model_data = df,
exposure = "exposure",
significance = TRUE
)
# Compare two fitted models side by side
freq_simple <- glm(
nclaims ~ bm + offset(log(exposure)),
family = poisson(),
data = df
)
rating_table(
freq_simple,
freq,
model_data = df,
exposure = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.