light_scatter: Scatter

View source: R/light_scatter.R

light_scatterR Documentation

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, ...)

## Default S3 method:
light_scatter(x, ...)

## S3 method for class '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,
  ...
)

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

Arguments

x

An object of class "flashlight" or "multiflashlight".

...

Further arguments passed from or to other methods.

v

The variable name 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

An object of class "light_scatter" with the following elements:

  • data: A tibble with results. Can be used to build fully customized visualizations. Column names can be controlled by options(flashlight.column_name).

  • by: Same as input by.

  • v: The variable evaluated.

  • type: Same as input type. For information only.

Methods (by class)

  • light_scatter(default): Default method not implemented yet.

  • light_scatter(flashlight): Variable profile for a flashlight.

  • light_scatter(multiflashlight): light_scatter for a multiflashlight.

See Also

plot.light_scatter()

Examples

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
)

flashlight documentation built on May 31, 2023, 6:19 p.m.