Apply smoothing on the risk factors used in the model. smooth_coef()
must always be followed by update_glm()
.
smooth_coef(model, x_cut, x_org, degree = NULL, breaks = NULL)
object of class glm/smooth
column name with breaks/cut
column name where x_cut is based on
order of polynomial
numerical vector with new clusters for x
Object of class smooth
Although smoothing could be applied either to the frequency or the severity model, it is more appropriate to impose the smoothing on the premium model. This can be achieved by calculating the pure premium for each record (i.e. expected number of claims times the expected claim amount), then fitting an "unrestricted" Gamma GLM to the pure premium, and then imposing the restrictions in a final "restricted" Gamma GLM.
update_glm()
for refitting the smoothed model,
and autoplot.smooth()
.
Other update_glm:
restrict_coef()
if (FALSE) {
library(insurancerating)
library(dplyr)
# Fit GAM for claim frequency
age_policyholder_frequency <- fit_gam(data = MTPL,
nclaims = nclaims,
x = age_policyholder,
exposure = exposure)
# Determine clusters
clusters_freq <- construct_tariff_classes(age_policyholder_frequency)
# Add clusters to MTPL portfolio
dat <- MTPL %>%
mutate(age_policyholder_freq_cat = clusters_freq$tariff_classes) %>%
mutate(across(where(is.character), as.factor)) %>%
mutate(across(where(is.factor), ~biggest_reference(., exposure)))
# Fit frequency and severity model
freq <- glm(nclaims ~ bm + age_policyholder_freq_cat, offset = log(exposure),
family = poisson(), data = dat)
sev <- glm(amount ~ bm + zip, weights = nclaims,
family = Gamma(link = "log"), data = dat %>% filter(amount > 0))
# Add predictions for freq and sev to data, and calculate premium
premium_df <- dat %>%
add_prediction(freq, sev) %>%
mutate(premium = pred_nclaims_freq * pred_amount_sev)
# Fit unrestricted model
burn_unrestricted <- glm(premium ~ zip + bm + age_policyholder_freq_cat,
weights = exposure,
family = Gamma(link = "log"),
data = premium_df)
# Impose smoothing and create figure
burn_unrestricted %>%
smooth_coef(x_cut = "age_policyholder_freq_cat",
x_org = "age_policyholder",
breaks = seq(18, 95, 5)) %>%
autoplot()
# Impose smoothing and refit model
burn_restricted <- burn_unrestricted %>%
smooth_coef(x_cut = "age_policyholder_freq_cat",
x_org = "age_policyholder",
breaks = seq(18, 95, 5)) %>%
update_glm()
# Show new rating factors
rating_factors(burn_restricted)
}