Learn R Programming

bartXViz (version 1.0.8)

Explain.barp: Approximate Shapley Values Computed from the BARP Model

Description

This function is implemented to calculate the contribution of each variable in the BARP (Bayesian Additive Regression Tree with post-stratification) model using the permutation method.

Usage

# S3 method for barp
Explain(
  object,
  feature_names = NULL,
  X = NULL,
  nsim = 1,
  pred_wrapper = NULL,
  census = NULL,
  geo.unit = NULL,
  parallel = FALSE,
  ...
)

Value

Returns of class Explainbarp with consisting of a list with the following components:

phis

A list containing the Shapley values for each variable.

newdata

The data used to check the contribution of variables. If a variable has two categories, it is dummy-coded, and if it has three or more categories, categorical variables are one-hot encoded.

fnull

The expected value of the model's predictions.

fx

The prediction value for each observation.

factor_names

The name of the categorical variable. If the data contains only continuous or dummy variables, it is set to NULL.

Arguments

object

A BARP model (Bayesian Additive Regression Tree) estimated using the barps function, a modified version of the barp function from the BARP library with a fixed seed.

feature_names

The name of the variable for which you want to check the contribution. The default value is set to NULL, which means the contribution of all variables in X will be calculated.

X

The dataset containing all independent variables used as input when estimating the BART model. The explanatory variables X included in the model must be converted to factors prior to input.

nsim

The number of Monte Carlo sampling iterations, which is fixed at 1 by default in the case of the BARP model.

pred_wrapper

A function used to estimate the predicted values of the model.

census

Census data containing the names of the X columns. It should also have the same format as X and include a variable named `proportion`, which indicates the number of individuals corresponding to each combination.

geo.unit

Enter the name of the stratification variable used in post stratification.

parallel

The default value is set to FALSE, but it can be changed to TRUE for parallel computation.

...

Additional arguments to be passed