
Add derived tariff segments to portfolio data
Source:R/gam_construct_tariff_classes.R
add_tariff_segments.RdAdds the tariff segments derived by derive_tariff_segments() as a new factor
column to a portfolio data set. The stored boundaries are applied to the
original continuous risk-factor column, so the result does not depend on the
row order used when the GAM was fitted.
The helper does not re-estimate the GAM or derive new boundaries. It can be used after filtering or reordering the original portfolio and on new data whose risk-factor values remain within the range used to derive the segmentation.
Arguments
- data
A data frame to which the tariff segments should be added.
- segments
Object of class
"tariff_segments", produced byderive_tariff_segments(). Old"tariff_classes"objects are accepted for backward compatibility.- name
Character string. Name of the new output column. If
NULL, the name is based on the risk factor name, for example"age_policyholder_segment".- overwrite
Logical. If
FALSE, the function stops whennamealready exists indata.
Details
The risk-factor name and optional rounding increment are taken from
segments. The risk-factor column in data must be numeric and contain only
finite, non-missing values. Values outside the original segmentation range
produce an error because their tariff treatment has not been supported by
the fitted GAM. The resulting factor can be used in a GLM or retained as a
candidate grouping for further actuarial review.
Examples
if (FALSE) { # \dontrun{
age_segments <- risk_factor_gam(
MTPL,
risk_factor = "age_policyholder",
claim_count = "nclaims",
exposure = "exposure"
) |>
derive_tariff_segments()
MTPL |>
add_tariff_segments(age_segments, name = "age_policyholder_segment")
} # }