Learn R Programming

bartXViz (version 1.0.11)

Explain_stats: Numerical summary of Shapley values from an Explain object

Description

Computes global numerical summaries of Shapley values using two averaging criteria: observation-based and posterior-sample-based.

Usage

Explain_stats(
  x,
  probs = 0.95,
  abs = TRUE,
  na.rm = TRUE,
  geo.unit = NULL,
  geo.id = NULL
)

# S3 method for default Explain_stats( x, probs = 0.95, abs = TRUE, na.rm = TRUE, geo.unit = NULL, geo.id = NULL )

# S3 method for Explainbarp Explain_stats( x, probs = 0.95, abs = TRUE, na.rm = TRUE, geo.unit = NULL, geo.id = NULL )

Value

A named list with two elements:

obs

A data.frame containing observation-based numerical summaries of Shapley values for each variable.

post

A data.frame containing posterior-sample-based numerical summaries of Shapley values for each variable.

Arguments

x

An object belonging to the Explain class or its subclasses, containing the Shapley values.

probs

Enter the probability for the quantile interval. Default is 0.95.

abs

Logical. If TRUE, summarizes absolute Shapley values (importance-style).

na.rm

Logical. Remove NA values in summaries. Default is TRUE.

geo.unit

(Explainbarp only) Name of the stratification variable used in post-stratification.

geo.id

(Explainbarp only) One value of interest among the values of the stratification variable.

Examples

Run this code
if (FALSE) {
## Friedman data
set.seed(2025)
n <- 200
p <- 5
X <- data.frame(matrix(runif(n * p), ncol = p))
y <- 10 * sin(pi* X[ ,1] * X[,2]) +20 * (X[,3] -.5)^2 + 10 * X[ ,4] + 5 * X[,5] + rnorm(n)

## Using the dbarts library
model <- dbarts::bart(X,y,keeptrees = TRUE ,  ndpost = 200)

## prediction wrapper function
pfun <- function(object, newdata) {
       predict(object , newdata)
       }
       
## Calculate shapley values
model_exp <-  Explain  ( model, X = X,  pred_wrapper =  pfun )

# Numerical summaries of summarised Shapley values
Explain_stats ( model_exp,  probs = 0.95)
}

Run the code above in your browser using DataLab