Learn R Programming

flashlight (version 0.7.5)

light_scatter: Scatter

Description

This function prepares values for drawing a scatter plot of predicted values, responses, residuals, or SHAP values against a selected variable.

Usage

light_scatter(x, ...)

# S3 method for default light_scatter(x, ...)

# S3 method for flashlight light_scatter( x, v, data = x$data, by = x$by, type = c("predicted", "response", "residual", "shap"), use_linkinv = TRUE, n_max = 400, seed = NULL, value_name = "value", label_name = "label", type_name = "type", ... )

# S3 method for multiflashlight light_scatter(x, ...)

Arguments

x

An object of class flashlight or multiflashlight.

...

Further arguments passed from or to other methods.

v

The variable to be shown on the x-axis.

data

An optional data.frame. Not relevant for type = "shap".

by

An optional vector of column names used to additionally group the results.

type

Type of the profile: Either "predicted", "response", "residual", or "shap".

use_linkinv

Should retransformation function be applied? Default is TRUE. Not used for type = "shap".

n_max

Maximum number of data rows to select. Will be randomly picked from the relevant data.

seed

An integer random seed used for subsampling.

value_name

Column name in resulting data containing the values belonging to type. Defaults to "value".

label_name

Column name in resulting data containing the label of the flashlight. Defaults to "label".

type_name

Column name in the resulting data with the plot type.

Value

An object of class light_scatter, light (and a list) with the following elements.

  • data A tibble with results. Can be used to build fully customized visualizations.

  • by Same as input by.

  • v The variable evaluated.

  • type Same as input type. For information only.

  • value_name Same as input value_name.

  • label_name Same as input label_name.

  • type_name Same as input type_name.

Methods (by class)

  • default: Default method not implemented yet.

  • flashlight: Variable profile for a flashlight.

  • multiflashlight: light_scatter for a multiflashlight.

See Also

plot.light_scatter.

Examples

Run this code
# NOT RUN {
fit_a <- lm(Sepal.Length ~ . -Petal.Length, data = iris)
fit_b <- lm(Sepal.Length ~ ., data = iris)
fl_a <- flashlight(model = fit_a, label = "without Petal.Length")
fl_b <- flashlight(model = fit_b, label = "all")
fls <- multiflashlight(list(fl_a, fl_b), data = iris, y = "Sepal.Length")
pr <- light_scatter(fls, v = "Petal.Length")
plot(light_scatter(fls, "Petal.Length", by = "Species", type = "residual"), alpha = 0.2)
# }

Run the code above in your browser using DataLab