View source: R/model_refinement.R
| edit_smoothing | R Documentation |
Manually adjusts a smoothing step that was previously added with
add_smoothing(). This is intended for actuarial review of a smoothed tariff
curve, for example to flatten an unstable segment, align the end points of an
interval, or add extra control points where expert judgement should guide the
curve.
The adjusted smoothing is applied when refit() is called.
edit_smoothing(
model,
model_variable = NULL,
step = NULL,
from,
to,
from_value = NULL,
to_value = NULL,
control_positions = NULL,
control_values = NULL,
allow_extrapolation = FALSE,
extrapolation_step = NULL
)
model |
Object of class |
model_variable |
Character string. The |
step |
Optional numeric index of the smoothing step to edit. |
from, to |
Numeric values giving the start and end of the source-variable interval to modify. |
from_value, to_value |
Optional numeric values used to override the
smoothed curve value at |
control_positions, control_values |
Optional numeric vectors of equal length. These define additional points that the edited smoothing curve should pass through. |
allow_extrapolation |
Logical. Whether edits may extend beyond the observed source-variable range. |
extrapolation_step |
Optional positive numeric scalar used to set the spacing of extra break points when extrapolation is allowed. |
Use model_variable or step to identify the smoothing step to edit. The
interval from from to to defines the part of the source variable range
that should be changed. from_value and to_value can be used to force the
curve values at the interval boundaries. control_positions and
control_values add additional points that the edited curve should follow
inside the interval.
edit_smoothing() changes the stored smoothing specification; it does not
edit a fitted GLM in place. Keep the rating_refinement object, call
refit() to assess the current specification, edit that same refinement
object, and call refit() again. The previously fitted model remains an
unchanged model result. This separation makes the sequence of actuarial
adjustments reproducible and avoids reconstructing refinement choices from
transformed columns in a refitted model.
Object of class rating_refinement.
Martin Haringa
set.seed(42)
driver_age <- rep(seq(20, 59), each = 4)
exposure <- rep(1, length(driver_age))
age_band <- cut(
driver_age,
breaks = c(18, 30, 40, 50, 60),
include.lowest = TRUE
)
expected_claims <- exp(
-1.7 + 0.018 * (driver_age - 20) + 0.0006 * (driver_age - 40)^2
)
portfolio <- data.frame(
claims = rpois(length(driver_age), exposure * expected_claims),
exposure = exposure,
driver_age = driver_age,
age_band = age_band
)
model <- glm(
claims ~ age_band + offset(log(exposure)),
family = poisson(),
data = portfolio
)
refinement <- prepare_refinement(model, data = portfolio) |>
add_smoothing(
model_variable = "age_band",
source_variable = "driver_age",
breaks = c(18, 30, 40, 50, 60),
degree = 2,
weights = "exposure"
)
# Fit and inspect the initial smoothing specification.
initial_model <- refit(refinement)
# Edit the retained specification and fit it again.
refinement <- refinement |>
edit_smoothing(
model_variable = "age_band",
from = 30,
to = 50,
from_value = 1.00,
to_value = 1.10,
control_positions = c(40),
control_values = c(1.05)
)
refined_model <- refit(refinement)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.