| set_reference_level | R Documentation |
Relevels a factor so that the selected category becomes the reference
(first) level. By default, the reference level is chosen as the level with
the largest total weight, for example the largest exposure in an insurance
portfolio. Use method = "manual" with reference_level when a specific
business category should be the reference level.
set_reference_level(
x,
weight = NULL,
method = "largest_weight",
reference_level = NULL
)
x |
A factor (unordered). Character vectors should be converted to factor before use. |
weight |
A numeric vector of the same length as |
method |
Character. Method used to choose the reference level.
Supported methods are |
reference_level |
Character string with the level to use as reference
when |
A factor of the same length as x, with the selected reference
level set as the first level.
Martin Haringa
Kaas, Rob & Goovaerts, Marc & Dhaene, Jan & Denuit, Michel. (2008). Modern Actuarial Risk Theory: Using R. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/978-3-540-70998-5")}
## Not run:
library(dplyr)
df <- chickwts |>
mutate(across(where(is.character), as.factor)) |>
mutate(across(where(is.factor), ~set_reference_level(., weight)))
set_reference_level(df$feed, method = "manual", reference_level = "casein")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.