Generate a SHAP summary plot to visualize the distribution, direction, and magnitude of SHAP values for the top contributing features in a spatial transcriptomics model.
Details
The function selects the top `n` features ranked by mean absolute SHAP value, and displays a scatter plot of their SHAP contributions. Each point is colored by the corresponding feature value, allowing joint interpretation of importance and directionality.
Examples
if (FALSE) { # \dontrun{
data("osmFISH_metadata_cellType")
data("osmFISH_bulk_decon")
data("osmFISH_bulk_pheno")
data("osmFISH_bulk_coordinate")
PhenoResult <- SpatialPhenoMap(
bulk_decon = osmFISH_bulk_decon,
bulk_pheno = osmFISH_bulk_pheno,
family = "binomial",
coord = osmFISH_bulk_coordinate,
resolution = "single_cell",
sample_information_cellType = osmFISH_metadata_cellType
)
pred_result <- PhenoResult$pred_score
phenoPlus <- row.names(pred_result[pred_result$label %in% "phenotype+", ])
model <- PhenoResult$model
X <- as.data.frame(PhenoResult$cell_type_distribution[phenoPlus, ])
# This step took a very long time
shap_test_plus <- compute_shap_spatial(
model = model,
X_bulk = as.data.frame(osmFISH_bulk_decon),
y_bulk = osmFISH_bulk_pheno,
X_spatial = X)
SpaPheno_SHAP_summary_plot(shap_test_plus, top_n = 31)
} # }