insurancerating provides actuarial building blocks for insurance
pricing in R. Use them alongside standard modelling functions such as
glm() to analyse portfolio experience, interpret fitted effects, turn
them into implementable tariffs and validate predictions. The package
also supports risk-factor structuring, large-loss treatment and
preparation of large portfolios.
The building blocks can be used independently or combined to suit the portfolio. The examples illustrate choices, not a prescribed methodology.
Install the CRAN version, or install the development version from GitHub:
install.packages("insurancerating") # install.packages("remotes") remotes::install_github("MHaringa/insurancerating")
factor_analysis() summarises observed experience and the exposure
supporting each level of a rating factor. These unadjusted portfolio
patterns are useful before modelling, but should not be interpreted as
conditional tariff relativities. Compare an apparent difference with the
exposure and claim count behind it.
library(insurancerating) portfolio <- as.data.frame(MTPL) portfolio$zip <- factor(portfolio$zip) zip_analysis <- factor_analysis( portfolio, risk_factors = "zip", claim_count = "nclaims", exposure = "exposure", claim_amount = "amount" ) autoplot( zip_analysis, metrics = c("frequency", "average_severity", "risk_premium") )
An age-band GLM estimates one relativity per band. Here we use age decades where practical and pool ages 80 and above. A spline smooths the fitted effects, which are then translated into new tariff bands.
age_breaks <- c(18, 29, 39, 49, 59, 69, 79, 95) portfolio$age_band <- cut(portfolio$age_policyholder, age_breaks, include.lowest = TRUE) frequency_model <- glm( nclaims ~ age_band + offset(log(exposure)), family = poisson(), data = portfolio ) tariff_breaks <- c(18, 24, 30, 40, 55, 70, 79, 95) proposal <- frequency_model |> prepare_refinement(data = portfolio) |> add_smoothing( "age_band", "age_policyholder", breaks = tariff_breaks, smoothing = "spline", k = 6, weights = "exposure" ) tariff <- refit(proposal, intercept_only = TRUE) autoplot(proposal)
The blue steps are the original GLM estimates. The dashed curve is the smoothing proposal; the orange steps are the resulting tariff bands.
In this sample, the fitted frequency rises from 9.1 to 12.3 claims per 100 policy-years between ages 70–79 and 80+. The oldest band contains 36 claims, so treat the rise as a feature of this example rather than a general age effect.
refit() holds those band effects fixed and re-estimates the base claim
rate, so their relativities do not move again. See the refinement
example
for how to inspect the fitted result.
| Pricing task | Main tools |
|---|---|
| Explore portfolio experience | factor_analysis(), outlier_histogram() |
| Structure continuous risk factors | risk_factor_gam(), derive_tariff_segments() |
| Interpret fitted model effects | rating_table(), add_factor_experience() |
| Refine tariff structures | prepare_refinement(), add_smoothing(), add_restriction(), refit() |
| Validate fit, calibration and risk ranking | model_performance(), calibration_analysis(), discrimination_analysis(), validate_performance() |
| Treat large losses | assess_excess_threshold(), redistribute_excess_loss() |
| Reduce portfolio data locally | rating_grid(), merge_date_ranges() |
| Reduce portfolios in a database | rating_grid_db(), merge_date_ranges_db() |
-
Getting Started Follow one portfolio through risk-factor analysis, modelling, technical risk premium, interpretation, validation and refinement.
-
Pricing workflow and package building blocks See how the main actuarial pricing tasks and package components fit together.
-
Motor insurance case study Compare a fitted frequency model and candidate tariffs on a multi-year synthetic portfolio, including individual impact and a held-out year.
-
Refinement building blocks Translate estimated model effects into an explicit, reviewable and implementable tariff structure.
-
Model validation Assess model fit, stability and tariff plausibility, compare observed with expected claims, and evaluate predictions on later periods. Start with the quick start.
-
Large Portfolios Reduce production-sized portfolios with model-point aggregation and database-backed workflows.
- Package website
- CRAN package
- Issue tracker
- Citation information is available with
citation("insurancerating"). - The package is distributed under the GPL (>= 2) licence.


