plot.shapley_algorithm: Barplot and tileplot of Shapley values.

View source: R/plot_functions.R

plot.shapley_algorithmR Documentation

Barplot and tileplot of Shapley values.

Description

Barplot and tileplot of Shapley values.

Usage

## S3 method for class 'shapley_algorithm'
plot(
  x,
  type = "both",
  subset = NULL,
  abbrev.var = FALSE,
  abbrev.obs = FALSE,
  sort.var = FALSE,
  sort.obs = FALSE,
  n_digits = 2,
  rotate_x = TRUE,
  continuous_rowname = FALSE,
  ...
)

Arguments

x

A list of class shapley_algorithm.

type

Either "both" (default), "bar", or "cell". If "both" (default) a barplot and a tileplot are created, otherwise only the selected plot is created.

subset

Either an integer, "chi2", or NULL (default) to select which rows of phi should be displayed. If NULL, all n rows are displayed, for a single integer the subset rows with the highest Mahalanobis distance are displayed, for an integer vector the subset selected rows are displayed, and for "chi2" all outlying rows are displayed (Mahalanobis distance greater than \sqrt{}qchisq(chi2.q,p)).

abbrev.var

Integer. If abbrev.var > 0, column names are abbreviated using abbreviate with minlenght = abrev.var.

abbrev.obs

Integer. If abbrev.obs > 0, row names are abbreviated using abbreviate with minlenght = abrev.obs.

sort.var

Logical. If TRUE (default), variables are sorted according to the distance

sort.obs

Logical. If TRUE (default), observations are sorted according to their Mahalanobis distance.

n_digits

Integer. If n_digits > 0, the original values of the variables are given in each cell with n_digits decimals places.

rotate_x

Logical. If TRUE (default), the x-axis labels are rotated.

continuous_rowname

Logical. If TRUE, the rownames are converted to a numeric vector.

...

Arguments passed on to plot.shapley.

Value

Returns plots for a list of class shapley_algorithm. If type is "bar", a barplot is generated. It displays the Shapley values (shapley) for each observation and optionally (plot_md = TRUE) includes the squared Mahalanobis distance (black bar) and the corresponding (non-)central chi-square quantile (dotted line). If type is "cell" a tileplot is generated. It displays each cells of the dataset and shows the original value from the observations, color coding indicates whether those values were higher (red) or lower (blue) than the imputed values, and the color intensity is based on the magnitude of the Shapley value. If type is "both", the barplot and the tileplot are generated.

Examples

library(MASS)
set.seed(1)
n <- 100; p <- 10
mu <- rep(0,p)
Sigma <- matrix(0.9, p, p); diag(Sigma) = 1
X <- mvrnorm(n, mu, Sigma)
X[sample(1:(n*p), 100, FALSE)] <- rep(c(-5,5),50)
MOE_X <- MOE(X, mu, Sigma)
plot(MOE_X, subset = 20, n_digits = 0)

ShapleyOutlier documentation built on Oct. 17, 2024, 5:08 p.m.