waterfall_plot {bartXViz} | R Documentation |
Waterfall plot
Description
The waterfall_plot
function is a bar chart that displays the positive and
negative contributions across sequential data points, visualizing how each
variable's contributions change for a single observation.
Usage
waterfall_plot(
object,
obs_num,
title = NULL,
geo.unit = NULL,
geo.id = NULL,
obs_name = NULL
)
Arguments
object |
Enter the name of the object that contains the model's contributions and results obtained using the Explain function. |
obs_num |
observation number (only one) |
title |
plot title |
geo.unit |
The name of the stratum variable in the BARP model as a character. |
geo.id |
Enter a single value of the stratum variable as a character. |
obs_name |
Enter the name of the vector containing observation IDs or names. |
Value
The function returns a waterfall plot.
plot_out |
The waterfall plot of the observation at index |
Examples
## 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 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 )
# Waterfall plot of 100th observation
waterfall_plot(model_exp, obs_num=100)
[Package bartXViz version 1.0.6 Index]