vs.rfsrc: rfsrc variable selection

View source: R/stat.R

vs.rfsrcR Documentation

rfsrc variable selection

Description

Drop least relevant variables from a rfsrc model with optional diagnostics.

Usage

vs.rfsrc(
  formula,
  data,
  nvar = -1L,
  depth = NULL,
  verbose = FALSE,
  plot = verbose,
  refit = TRUE,
  ...
)

Arguments

formula, data

a formula and data frame containing the response and all potential predictor variables

nvar

number of variables desired in final model (if positive) or the number of variables to drop (if negative)

depth

logical or a numeric value (if NULL, variables will be selected via nvar); if TRUE, variables will be selected using first-order depths and the threshold value returned by max.subtree; alternatively, a numeric value to be used as the threshold

verbose, plot

logical; if TRUE, an updated formula and/or variable importance figures are printed after each step

refit

logical; if TRUE (default), model is re-fit after each variable is dropped; otherwise, all variables to be dropped will be done in one step which could give significant performance gains for some models such as survival models (note the final model may be different than if refit = TRUE)

...

additional parameters passed to rfsrc

Value

The formula of the final model.

See Also

vs.glmnet

Examples

set.seed(1)
vs.rfsrc(iris)
vs.rfsrc(I(Species == 'setosa') ~ ., iris)


## select variables based on first-order depth
f <- formula(rev(iris))
vs.rfsrc(f, iris, depth = TRUE, verbose = TRUE, plot = FALSE, ntree = 10)

## keep only most relevant 2 variables
vs.rfsrc(f, iris, nvar = 2)

## drop 2 least relevant variables
vs.rfsrc(f, iris, nvar = -2)
vs.rfsrc(f, iris, nvar = -2, refit = FALSE)


library('survival')
f <- Surv(time, status == 0) ~ rx + sex + age + obstruct + adhere + nodes
vs.rfsrc(f, colon, nvar = 4, ntree = 5)
# vs.rfsrc(f, colon, nvar = -2, ntree = 5) ## same

## for slower models, refit = FALSE may improve performance
vs.rfsrc(f, colon, nvar = 4, ntree = 5, refit = FALSE, plot = TRUE)


raredd/rawr documentation built on April 29, 2024, 10:29 a.m.