View source: R/model_rating_table_plot.R
| autoplot.rating_table | R Documentation |
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 class '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,
...
)
object |
A |
risk_factors |
Optional character vector specifying the risk factors to
plot. If |
metric |
Optional character string. Observed-experience metric to plot
when observed experience has been attached with
|
ncol |
Positive integer specifying the number of columns in the patchwork layout. |
legend_position |
Character string specifying the legend position.
The default, |
show_exposure_labels |
Logical. If |
decimal_mark |
Character string, either |
y_label |
Character string for the primary y-axis. |
bar_fill |
Optional colour for exposure bars. If |
model_color |
Optional single colour overriding the model-line palette. |
use_linetype |
Logical. If |
abbreviate_labels |
Logical. If |
label_width |
Positive whole number of at least 2. Maximum number of characters in automatically shortened level labels. |
label_abbreviations |
Optional named character vector with explicit
display labels, for example
|
rotate_angle |
Optional numeric angle for risk-factor level labels. |
custom_theme |
Optional named list passed to |
remove_underscores |
Logical. If |
labels |
Deprecated alias for |
dec.mark |
Deprecated alias for |
ylab |
Deprecated alias for |
fill |
Deprecated alias for |
color |
Deprecated alias for |
linetype |
Deprecated alias for |
... |
Additional arguments reserved for method compatibility. |
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.
A patchwork object containing one ggplot2 panel per selected risk
factor.
Martin Haringa
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.