Creates or updates a "flashlight" object. If a flashlight is to be created, all arguments are optional except label. If a flashlight is to be updated, all arguments are optional up to x (the flashlight to be updated).

flashlight(x, ...)

# Default S3 method
flashlight(
  x,
  model = NULL,
  data = NULL,
  y = NULL,
  predict_function = stats::predict,
  linkinv = function(z) z,
  w = NULL,
  by = NULL,
  metrics = list(rmse = MetricsWeighted::rmse),
  label = NULL,
  shap = NULL,
  ...
)

# S3 method for class 'flashlight'
flashlight(x, check = TRUE, ...)

Arguments

x

An object of class "flashlight". If not provided, a new flashlight is created based on further input. Otherwise, x is updated based on further input.

...

Arguments passed from or to other functions.

model

A fitted model of any type. Most models require a customized predict_function.

data

A data.frame or tibble used as basis for calculations.

y

Variable name of response.

predict_function

A real valued function with two arguments: A model and a data of the same structure as data. Only the order of the two arguments matter, not their names.

linkinv

An inverse transformation function applied after predict_function.

w

A variable name of case weights.

by

A character vector with names of grouping variables.

metrics

A named list of metrics. Here, a metric is a function with exactly four arguments: actual, predicted, w (case weights) and ... like those in package MetricsWeighted.

label

Name of the flashlight. Required.

shap

An optional shap object. Typically added by calling add_shap().

check

When updating the flashlight: Should internal checks be performed? Default is TRUE.

Value

An object of class "flashlight" (and list) containing each input (except x) as element.

Methods (by class)

  • flashlight(default): Used to create a flashlight object. No x has to be passed in this case.

  • flashlight(flashlight): Used to update an existing flashlight object.

Examples

fit <- lm(Sepal.Length ~ ., data = iris)
(fl <- flashlight(model = fit, data = iris, y = "Sepal.Length", label = "ols"))
#> 
#> Flashlight ols 
#> 
#> Model:			 Yes
#> y:			 Sepal.Length
#> w:			 No
#> by:			 No
#> data dim:		 150 5
#> metrics:		 rmse
(fl_updated <- flashlight(fl, linkinv = exp))
#> 
#> Flashlight ols 
#> 
#> Model:			 Yes
#> y:			 Sepal.Length
#> w:			 No
#> by:			 No
#> data dim:		 150 5
#> metrics:		 rmse