I am using rfsrc in Rstudio to run my bioinformatics data (included survival status and time), and I developed my competing risks model. Although I have generated my result with nested cross validation (manually). I got the VIP value, but I am wondering is there a way to figure out the direction of the interaction between these variables. My basic code is here: rfsrc(Surv(time, status) ~ ., data = x) And my competing risks analysis basically have 3 outcomes, so I have 3 different predictions for each outcome.
I plan to use** SHAP **to generate a plot, but as SHAP’s packs are not in the rfsrc’s library, is there anyone could help with this? Appreciate a lot!
The related code I found in stack is attached here, but I could not apply it to the competing risks model.
library(randomForestSRC)
library(kernelshap)
library(shapviz)
df <- mtcars
mod1 <- rfsrc(Multivar(mpg, wt ) ~ ., data = mtcars, importance = TRUE)
x <- c("cyl", "disp", "hp", "drat", "qsec", "vs", "am", "gear", "carb")
pred_fun <- function(m, x) {
pred <- predict(m, newdata=x)$regrOutput
sapply(pred, `[[`, "predicted")
}
pred_fun(mod1, head(mtcars))
shap_values <- kernelshap(
mod1,
X = mtcars[x],
bg_X = mtcars, # Usually small random sample
pred_fun = pred_fun
)
sv <- shapviz(shap_values)
names(sv) <- c("mpg", "wt") # Not yet automatically
sv_importance(sv)
sv_dependence(sv, "cyl")
df <- mtcars
rfsrc(Surv(mpg, vs) ~ ., data = df, importance = TRUE) #Here I put mpg as survival time data and vs as event data
陈德赛 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.