model_visualize: Visualize the insuRglm model

View source: R/model_visualize.R

model_visualizeR Documentation

Visualize the insuRglm model

Description

Visualizes the current (last) GLM model using charts which may contain observed values, fitted values and values derived from model coefficients (predictions at base levels). Scale of the y-axis can be controlled using y_axis and rescaled arguments.

Usage

model_visualize(
  setup,
  factors = "fitted",
  by = NULL,
  y_axis = c("predicted", "linear"),
  rescaled = FALSE,
  ref_models = NULL
)

Arguments

setup

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

factors

Character scalar/vector. Either one of fitted, unfitted, all or a name of one or multiple currently fitted model predictors.

by

Character scalar. A name of one of currently fitted predictors in the model. Will result in two-way chart showing the combination of the main effects (without interaction).

y_axis

Character scalar. Either predicted or linear.

rescaled

Boolean scalar. Whether the y-axis is rescaled compared to the base level predictor at each chart.

ref_models

Character vector. Names of one or multiple reference models created by using model_save

Value

List of ggplot2 charts.

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()

# this is also the default
modeling %>%
  model_visualize(factors = 'fitted', y_axis = 'predicted', rescaled = FALSE)

modeling %>%
  model_visualize(factors = 'fitted', y_axis = 'linear', rescaled = TRUE)

modeling %>%
  model_visualize(factors = 'unfitted')

modeling %>%
  model_visualize(factors = c('pol_yr', 'agecat'))

modeling <- modeling %>%
  factor_add(gender) %>%
  model_fit()

modeling %>%
  model_visualize(factors = 'fitted', by = 'gender')

modeling %>%
  model_visualize(factors = 'agecat', by = 'gender', y_axis = 'linear')

modeling <- modeling %>%
  model_save('model1') %>%
  factor_modify(agecat = variate(agecat, type = 'non_prop', mapping = 1:6, degree = 2)) %>%
  model_fit()

modeling %>%
  model_visualize(ref_models = "model1")

modeling %>%
  model_visualize(y_axis = "linear", ref_models = "model1")


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