knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message = FALSE,
  warning = FALSE,
  error = FALSE,
  results = "asis"
)
library(lossrx)
library(dplyr)
library(purrr)
library(knitr)
library(kableExtra)
library(lubridate)
library(dbplyr)
library(janitor)
library(summarytools)

Overview

A lossrun is an insurance/actuarial term for a dataset containing information about a particular insurance coverage or policy's individual claims as of a particular point in time known as the evaluation date.

lossrx provides examples and support functions to aid in the creation, analysis, validation, and proper storage of actuarial lossruns specific to P&C Insurance Coverages.

Coverages

It is important to note the granularity of a particular lossrun with regard to what level of detail its values represent as well as the context in which the data is provided from.

For example, it is common to have separate lossruns by coverage due to the differences in the attributable dimensions associated with the values in those lossruns by coverage.

For example, a Worker's Compensation lossrun will typically split its values for paid, case reserves, and incurred/reported into lower-level spit-outs by:

Whereas, in Automobile Insurance Coverages the claim amounts would be split out between

lossrx supports analysis for the following Property Casualty coverages:

Different coverages have different types of fields in their respective lossruns which is discussed in detail in the coverages vignette.

Typical Lossrun Fields

Each row in a lossrun should correspond to a specific claim at a specific point in time.

The following fields are typical in all lossruns, regardless of coverage of business context:

Example Lossrun

lossrx provides example lossruns in the form of a merged dataset named losses.

loss_data <- losses
dplyr::glimpse(loss_data)

Note that the losses dataset contains r length(unique(loss_data$eval_date)) unique evaluation dates merged together:

analysis_data_wc <- loss_data |>
  filter(coverage == "WC") |>
  group_by(.data$eval_date, .data$devt_age, .data$program_year) |>
  summarise(
    `Total Reported Claim Counts` = n(),
    `Total Paid` = sum(.data$total_paid, na.rm = TRUE),
    `Total Reported` = sum(.data$total_incurred, na.rm = TRUE)
  ) |>
  ungroup() |>
  arrange(program_year, devt_age)

This can easily be translated into triangles like so:

create_triangle <- function(dat, type = c("paid", "reported", "counts")) {

  col <- switch(type,
                "paid" = "Total Paid",
                "reported" = "Total Reported",
                "counts" = "Total Reported Claim Counts")

  dat |>
    dplyr::filter(.data$devt_age %% 12 == 0) |>
    dplyr::select(.data$program_year, .data$devt_age, col) |>
    tidyr::pivot_wider(
      names_from = .data$devt_age,
      values_from = col
    )

}

wc_tris <- purrr::map(c("Paid Triangle" = "paid",
                        "Reported Triangle" = "reported",
                        "Reported Claim Counts Triangle" = "counts"),
                      ~create_triangle(dat = analysis_data_wc, .x))

Triangles

Reported Triangle for Worker's Compensation

wc_tris[["Reported Triangle"]] |>
  rename(`Program Year` = program_year) |>
  mutate_at(vars(2:10), formattable::currency, digits = 0) |>
  kable(
    digits = 0, 
    align = "c", 
    caption = "Reported Loss Triangle - Worker's Compensation",
    format.args = list(big.mark = ",")
  ) |>
  kableExtra::kable_styling()

Paid Triangle for Worker's Compensation

wc_tris[["Paid Triangle"]] |>
  rename(`Program Year` = program_year) |>
  mutate_at(vars(2:10), formattable::currency, digits = 0) |>
  kable(
    digits = 0, 
    align = "c", 
    caption = "Paid Loss Triangle - Worker's Compensation",
    format.args = list(big.mark = ",")
  ) |>
  kableExtra::kable_styling()

Reported Claim Counts Triangle for Worker's Compensation

wc_tris[["Reported Claim Counts Triangle"]] |>
  rename(`Program Year` = program_year) |>
  mutate_at(vars(2:10), formattable::comma, digits = 0) |>
  kable(
    digits = 0, 
    align = "c", 
    caption = "Reported Claim Counts Triangle - Worker's Compensation",
    format.args = list(big.mark = ",")
  ) |>
  kableExtra::kable_styling()


jimbrig/lossrx documentation built on Dec. 20, 2024, 3:46 a.m.