biggest_reference: Set reference group to the group with largest exposure

View source: R/utils.R

biggest_referenceR Documentation

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)

Arguments

x

an unordered factor

weight

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

Value

a factor of the same length as x

Author(s)

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

## Not run: 
library(dplyr)
df <- chickwts %>%
mutate(across(where(is.character), as.factor)) %>%
mutate(across(where(is.factor), ~biggest_reference(., weight)))

## End(Not run)


insurancerating documentation built on Dec. 28, 2022, 2:53 a.m.