calculate_SHAP_values: Calculate SHAP Values and Identify Significant Features

View source: R/calculateSHAP.R

calculate_SHAP_valuesR Documentation

Calculate SHAP Values and Identify Significant Features

Description

This function calculates SHAP values for a given dataset using a provided model. It then identifies significant features based on the SHAP values for the specified class. Additionally, it prepares a long-format data frame of individual SHAP values suitable for visualization.

Usage

calculate_SHAP_values(model, data, class_index = 1, shap_std_dev_factor = 0.5)

Arguments

model

The trained model for which SHAP values are to be calculated.

data

A matrix or data frame of input features for SHAP value calculation.

class_index

Index of the class for which to calculate SHAP values. For binary classification (e.g., target 1 = "Right", target 0 = "Left"), this parameter determines the class perspective for SHAP analysis. In the demo_rnaseq_data dataset:

  • If class_index = 1, SHAP values represent feature contributions towards predicting "Right".

  • If class_index = 0, SHAP values represent feature contributions towards predicting "Left". In binary classification, SHAP values for one class are the negative of those for the other class, this reflects how each feature influences the model's output in opposite directions for each class.

shap_std_dev_factor

Factor to determine the cutoff for significant SHAP values. Default is 0.5. For example 0.5 is considered conservative as it means you are selecting features whose mean absolute SHAP values are above the mean plus half of the standard deviation.

Value

A list containing three elements:

  • shap_values: A data frame with SHAP values for each feature.

  • significant_features: A data frame with significant features based on the cutoff.

  • long_shap_data: A long-format data frame of individual SHAP values for each feature.

Examples

shapvals <- calculate_SHAP_values(fitting_results$model, processed_training_data$X_training_mat, class_index = 1, shap_std_dev_factor = 0.5)

tkolisnik/Rf2pval documentation built on Feb. 20, 2024, 5:39 a.m.