View source: R/plot_explainBART.R
plot.ExplainBART | R Documentation |
The plot.ExplainBART
function provides various visualization methods for Shapley values.
It is designed to visualize ExplainBART
class objects, which contain Shapley values computed from models estimated using the bart
function from the dbarts or the wbart
/gbart
functions from BART.
The values and format used in the graph are determined based on the input parameters.
## S3 method for class 'ExplainBART'
plot(
x,
average = NULL,
type = NULL,
num_post = NULL,
plot.flag = TRUE,
adjust = FALSE,
probs = 0.95,
title = NULL,
...
)
x |
An |
average |
Input the reference value for calculating the mean of the object's |
type |
|
num_post |
To check the contribution of variables for a single posterior sample, enter a value within the number of posterior samples. |
plot.flag |
If |
adjust |
The default value is |
probs |
Enter the probability for the quantile interval. The default value is |
title |
The title of the plot, with a default value of |
... |
Additional arguments to be passed |
The plot is returned based on the specified option.:
out |
If average is |
## 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 dbarts
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 )
# Distribution of Shapley values (boxplot)
# computed based on observation and posterior sample criteria
plot(model_exp,average = "both" )
# Barplot based on observation criteria
plot(model_exp,average = "obs",type ="bar",probs = 0.95)
# Barplot based on posterior sample
plot(model_exp,average = "post",type ="bar" )
# Summary plot based on posterior sample
plot(model_exp,average = "post",type ="bees" )
# Summary plot of the 100th posterior sample
plot(model_exp,average = "post",type ="bees",num_post = 100)
# Barplot of the adjusted baseline
plot(model_exp, type ="bar", adjust= TRUE )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.