rpart_wrapper: rpart_wrapper

Description Usage Arguments Details Value See Also Examples

View source: R/parse_rpart.R

Description

A wrapper function to rpart.

Usage

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## 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 May 2, 2019, 6:40 a.m.