data(mtcars)
# When working with real data, use higher values for the niters and num.trees
# parameters --> here these parameters are set to small values to reduce the
# runtime.
# Function to make sure proper number of cores is specified
safe_num_threads <- function(n) {
available <- parallel::detectCores()
if (n > available) available else n
}
# Standard use
out1 <- shadow_vimp(
data = mtcars, outcome_var = "vs",
niters = c(10, 20, 30), num.trees = 30, num.threads = safe_num_threads(1)
)
# \donttest{
# `num.threads` sets the number of threads for multithreading in
# `ranger::ranger`. By default, the `shadow_vimp` function uses half the
# available CPU threads.
out2 <- shadow_vimp(
data = mtcars, outcome_var = "vs",
niters = c(10, 20, 30), num.threads = safe_num_threads(2),
num.trees = 30
)
# Save variable importance measures only from the final step of the
# procedure
out4 <- shadow_vimp(
data = mtcars, outcome_var = "vs",
niters = c(10, 20, 30), save_vimp_history = "last", num.trees = 30,
num.threads = safe_num_threads(1)
)
# Print unadjusted and FDR-adjusted p-values together with the corresponding
# decisions
out5 <- shadow_vimp(
data = mtcars, outcome_var = "vs",
niters = c(10, 20, 30), to_show = "FDR", num.trees = 30,
num.threads = safe_num_threads(1)
)
# Use per-variable p-values to decide in the final step whether a covariate
# is informative or not. Note that pooled p-values are always used in the
# pre-selection (first two steps).
out6 <- shadow_vimp(
data = mtcars, outcome_var = "vs",
niters = c(10, 20, 30), method = "per_variable", num.trees = 30,
num.threads = safe_num_threads(1)
)
# Perform variable selection in a single step, without a pre-selection phase
out7 <- shadow_vimp(
data = mtcars, outcome_var = "vs", alphas = c(0.05),
niters = c(30), num.trees = 30,
num.threads = safe_num_threads(1)
)
# }
Run the code above in your browser using DataLab