Plot the coefficients or relativities stored in a rating_table() object by
risk factor. Multiple fitted models can be compared, exposure can be shown as
background bars, and observed portfolio experience attached with
add_portfolio_experience() can be added as a separate line.
# S3 method for rating_table
autoplot(
object,
risk_factors = NULL,
metric = NULL,
ncol = 1,
legend_position = c("auto", "right", "bottom", "top", "left", "none"),
show_exposure_labels = TRUE,
decimal_mark = ",",
y_label = "Relativity",
bar_fill = NULL,
model_color = NULL,
use_linetype = FALSE,
abbreviate_labels = TRUE,
label_width = 20,
label_abbreviations = NULL,
rotate_angle = NULL,
custom_theme = NULL,
remove_underscores = FALSE,
labels = NULL,
dec.mark = NULL,
ylab = NULL,
fill = NULL,
color = NULL,
linetype = NULL,
...
)A patchwork object containing one ggplot2 panel per selected risk
factor.
A "rating_table" object returned by rating_table().
Optional character vector specifying the risk factors to
plot. If NULL, all available risk factors are shown.
Optional character string. Observed-experience metric to plot
when observed experience has been attached with
add_portfolio_experience(). Common choices are "frequency",
"severity"/"average_severity" and "risk_premium".
Positive integer specifying the number of columns in the patchwork layout.
Character string specifying the legend position.
The default, "auto", hides the legend when only one fitted model is
shown and no observed-experience line is present. It places the legend on
the right when multiple fitted models or an observed-experience comparison
are shown. Use "right", "bottom", "top", "left" or "none" to
override this behaviour.
Logical. If TRUE, print exposure values on the
background bars.
Character string, either "," or ".", controlling
number labels.
Character string for the primary y-axis.
Optional colour for exposure bars. If NULL, the package
palette is used.
Optional single colour overriding the model-line palette.
Logical. If TRUE, distinguish fitted models by line
type as well as colour.
Logical. If TRUE, long risk-factor level labels
are shortened to label_width characters. A shortened label ends in one
period; for example, "Bouwnijverheid" becomes "Bouwn." when
label_width = 6. Only the displayed axis labels are changed.
Positive whole number of at least 2. Maximum number of characters in automatically shortened level labels.
Optional named character vector with explicit
display labels, for example
c("Bouwnijverheid" = "Bouwn.", "Onroerend goed" = "Onr. goed").
Explicit labels take precedence over automatic shortening.
Optional numeric angle for risk-factor level labels.
Optional named list passed to ggplot2::theme().
Logical. If TRUE, replace underscores with spaces
in risk-factor axis labels.
Deprecated alias for show_exposure_labels.
Deprecated alias for decimal_mark.
Deprecated alias for y_label.
Deprecated alias for bar_fill.
Deprecated alias for model_color.
Deprecated alias for use_linetype.
Additional arguments reserved for method compatibility.
Martin Haringa
One panel is produced for each selected risk factor. Model effects use the
primary y-axis. When exposure is available, bars are rescaled to the plotting
range and the original exposure scale is shown on the secondary y-axis.
Panel and level order follow the input rating_table() object. This keeps
the reference level and any explicit actuarial review order consistent
between the data frame, as_gt() and the plot.
Observed experience is plotted only after it has been attached with
add_portfolio_experience(). The selected metric is converted to the
relative scale recorded in that object, using either the model reference
level or the portfolio mean.
The plot supports comparison of fitted tariff effects, portfolio volume and unadjusted observed experience. Differences between the observed and modelled lines may indicate portfolio-mix effects, sparse levels, model smoothing or genuine lack of fit. The chart does not separate these explanations and should be reviewed together with claim counts, residual diagnostics and stability across periods.
When models are compared, the analyst should ensure that response definitions, link functions and relativity scales are sufficiently comparable. Exposure bars provide volume context but are not confidence intervals.
rating_table(), add_portfolio_experience(),
factor_analysis(), as_gt.rating_table()
portfolio <- MTPL
portfolio$zip <- as.factor(portfolio$zip)
frequency <- glm(
nclaims ~ bm + zip + offset(log(exposure)),
family = poisson(),
data = portfolio
)
effects <- rating_table(
frequency,
model_data = portfolio,
exposure = "exposure"
)
autoplot(effects, risk_factors = "zip", show_exposure_labels = FALSE)
Run the code above in your browser using DataLab