rpart_wrapper: rpart_wrapper

View source: R/parse_rpart.R

rpart_wrapperR Documentation

rpart_wrapper

Description

A wrapper function to rpart.

Usage

rpart_wrapper(
  response,
  response_type = NULL,
  covariates = NULL,
  tree_builder_parameters = NULL,
  prune = FALSE
)

Arguments

response

Response variable to use in rpart model.

response_type

Class of response variable.

covariates

Covariates to use in rpart model.

tree_builder_parameters

A named list of parameters to pass to rpart. This includes all input parameters that rpart can take.

prune

Logical variable indicating whether the tree shold be pruned to the subtree with the smallest cross-validation error. Defaults to FALSE.

Details

This function provides a wrapper to rpart that provides a convenient interface for specifying the response variable and covariates for the rpart model. The user may indicate whether the tree should be pruned to the size that yields the smallest cross-validation error. An rpart.object is returned.

Value

An object of class rpart.

See Also

rpart, rpart.object, Surv

Examples

## Generate example data containing response, treatment, and covariates
N <- 100
continuous_response = runif( min = 0, max = 20, n = N )
trt <- sample( c('Control','Experimental'), size = N, prob = c(0.4,0.6), replace = TRUE )
X1 <- runif( N, min = 0, max = 1 )
X2 <- runif( N, min = 0, max = 1 )
X3 <- sample( c(0,1), size = N, prob = c(0.2,0.8), replace = TRUE )
X4 <- sample( c('A','B','C'), size = N, prob = c(0.6,0.3,0.1), replace = TRUE )
covariates <- data.frame( trt )
names( covariates ) <- "trt"
covariates$X1 <- X1
covariates$X2 <- X2
covariates$X3 <- X3
covariates$X4 <- X4
## Fit an rpart model
ex1 <- rpart_wrapper( response = continuous_response, covariates = covariates )
ex1

TSDT documentation built on April 7, 2022, 1:07 a.m.

Related to rpart_wrapper in TSDT...