interaction: Create variable interaction

View source: R/interaction.R

interactionR Documentation

Create variable interaction

Description

Create variable interaction

Usage

interaction(x, y, z = NULL)

Arguments

x

Unquoted symbol. One of the variables for interaction.

y

Unquoted symbol. One of the variables for interaction.

z

Unquoted symbol. One of the variables for interaction.

Value

Vector of newly created interaction

Examples

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

setup <- setup(
  data_train = bc_train,
  target = 'bc',
  weight = 'exposure',
  family = 'tweedie',
  tweedie_p = 1.5,
  keep_cols = c('pol_nbr', 'premium')
)

modeling <- setup %>%
  factor_add(pol_yr) %>%
  factor_add(agecat) %>%
  factor_add(gender) %>%
  model_fit() %>%
  model_save("model1") %>%
  factor_modify(agecat_X_gender = interaction(agecat, gender)) %>%
  factor_add(agecat_X_gender) %>%
  model_fit() %>%
  model_save("model2") %>%
  # modification of 'agecat' will simplify the base level of interaction (agecat_X_gender_F)
  factor_modify(agecat = variate(agecat, type = "non_prop", mapping = 1:6)) %>%
  # all other non-base levels need to be simplified separately
  factor_modify(agecat_X_gender_M = variate(agecat_X_gender_M, type = "non_prop", mapping = 1:6, degree = 2)) %>%
  model_fit()


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