plot.shapley {ShapleyOutlier}R Documentation

Barplot of Shapley values

Description

Barplot of Shapley values

Usage

## S3 method for class 'shapley'
plot(
  x,
  subset = NULL,
  chi2.q = 0.99,
  abbrev.var = 3,
  abbrev.obs = 10,
  sort.var = FALSE,
  sort.obs = FALSE,
  plot_md = TRUE,
  md_squared = TRUE,
  rotate_x = TRUE,
  ...
)

Arguments

x

A list of class shapley.

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

chi2.q

Quantile, only used if subset == "chi2".

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.

plot_md

Logical. If TRUE (default), the Mahalanobis distance will be included in the plot.

md_squared

Logical. If TRUE (default), the squared Mahalanobis distance is plotted otherwise the (not-squared) Mahalanobis distance.

rotate_x

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

...

Optional arguments passed to methods.

Value

Returns a barplot that 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).

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_clean <- X
X[sample(1:(n*p), 100, FALSE)] <- rep(c(-5,5),50)
call_shapley <- shapley(X, mu, Sigma)
plot(call_shapley, subset = 1:20)
plot(call_shapley, subset = 5, rotate_x = FALSE)
plot(call_shapley, subset = 5, md_squared = FALSE, rotate_x = FALSE)

[Package ShapleyOutlier version 0.1.1 Index]