Learn R Programming

insurancerating (version 0.7.5)

biggest_reference: Set reference group to the group with largest exposure

Description

This function specifies the first level of a factor to the level with the largest exposure. Levels of factors are sorted using an alphabetic ordering. If the factor is used in a regression context, then the first level will be the reference. For insurance applications it is common to specify the reference level to the level with the largest exposure.

Usage

biggest_reference(x, weight)

Value

a factor of the same length as x

Arguments

x

an unordered factor

weight

a vector containing weights (e.g. exposure). Should be numeric.

Author

Martin Haringa

References

Kaas, Rob & Goovaerts, Marc & Dhaene, Jan & Denuit, Michel. (2008). Modern Actuarial Risk Theory: Using R. doi:10.1007/978-3-540-70998-5.

Examples

Run this code
if (FALSE) {
library(dplyr)
df <- chickwts |>
mutate(across(where(is.character), as.factor)) |>
mutate(across(where(is.factor), ~biggest_reference(., weight)))
}

Run the code above in your browser using DataLab