variate: Simplify to variate

View source: R/variate.R

variateR Documentation

Simplify to variate

Description

Simplifies simple factor to variate, which usually means that monotonic trend is enforced and some of the levels may be merged together. Must be used within factor_modify function. This is usually done with originally continuous variables.

Usage

variate(
  x,
  type = c("prop", "non_prop"),
  prop_log = TRUE,
  mapping = NULL,
  degree = 1
)

Arguments

x

Unquoted symbol. Predictor to be simplified. Must be present in the modeling dataset.

type

Character scalar. One of prop or non_prop, specifying proportional and unproportional variate.

prop_log

Boolean scalar. Whether the proportional variate should be logged (recommended).

mapping

Integer vector. Mapping to use for simplification. Length must be equal to length of unique levels of the predictor.

degree

Integer scalar. Polynomial degree to use.

Value

Original vector with updated attributes.

See Also

factor_modify

Examples

require(dplyr) # for the pipe operator
data('sev_train')

setup <- setup(
  data_train = sev_train,
  target = 'sev',
  weight = 'numclaims',
  family = 'gamma',
  keep_cols = c('pol_nbr', 'exposure', 'premium')
)

modeling <- setup %>%
  factor_add(pol_yr) %>%
  factor_add(agecat) %>%
  model_fit() %>%
  model_save('model1') %>%
  factor_modify(agecat = variate(agecat, type = 'non_prop', mapping = c(1, 2, 3, 4, 5, 6))) %>%
  model_fit()


realgabon/insuRglm documentation built on Jan. 2, 2023, 2:51 a.m.