model_compare: Compare two or more insuRglm models

View source: R/model_compare.R

model_compareR Documentation

Compare two or more insuRglm models

Description

Compares multiple insuRglm models with the current (last) model. The comparison models must be saved using model_save.

Usage

model_compare(setup, type = c("rmse", "nested_model_test"), buckets = 10)

Arguments

setup

Setup object. Created at the start of the workflow. Usually piped in from previous step.

type

Character scalar. One of 'nested_model_test' or 'rmse'. 'nested_model_test' will produce nested model test in form of matrix of standard error percentages. 'rmse' will produce a plot comparing RMSE across all models (also separately for train and CV if model_crossval was used)

Value

Either a matrix-like dataframe of nested model test results or a ggplot2 chart.

See Also

model_save, model_crossval

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) %>%
  model_fit() %>%
  model_save('model1') %>%
  factor_add(agecat) %>%
  model_fit() %>%
  model_save('model2') %>%
  factor_modify(agecat = variate(agecat, type = 'non_prop', mapping = c(1, 2, 3, 4, 5, 6))) %>%
  model_fit()

# nested model test of model with and without the agecat
modeling %>%
  model_compare(type = 'nested_model_test')

# compare training RMSE on all models so far
modeling %>%
  model_compare(type = 'rmse')

# compare both training and CV RMSE on all models
modeling_with_cv <- modeling %>%
  model_crossval(cv_folds = 10, stratified = TRUE)

modeling_with_cv %>%
  model_compare(type = 'rmse')


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