Decision Tree via rpart. Predicts response variables or brushed set of rows from predictor variables, using one CART (Classification And Regression Tree).

decisionTree(
  dataset = cs.in.dataset(),
  preds = cs.in.predictors(),
  resps = cs.in.responses(),
  brush = cs.in.brushed(),
  scriptvars = cs.in.scriptvars(),
  return.results = FALSE,
  ...
)

Arguments

dataset

[data.frame]
Dataset with named columns. The names correspond to predictors and responses.

preds

[character]
Character vector of predictor variables.

resps

[character]
Character vector of response variables.

brush

[logical]
Logical vector of length nrow(dataset). Flags brushed rows in Cornerstone.

scriptvars

[list]
Named list of script variables set via the Cornerstone "Script Variables" menu. For details see below.

return.results

[logical(1)]
If FALSE the function returns TRUE invisibly. If TRUE, it returns a list of results. Default is FALSE.

...

[ANY]
Additional arguments to be passed to rpart . Please consider possible script variables (scriptvars) to prevent duplicates.

Value

Logical [TRUE] invisibly and outputs to Cornerstone or, if return.results = TRUE, list of resulting data.frame objects:

statistics

General statistics about the CART.

predictions

Dataset to brush with predicted values for dataset. The original input and other columns can be added to this dataset through the menu Columns -> Add from Parent ....

confusion

For categorical response variables or brush state only. A table with counts of each distinct combination of predicted and actual values.

rgobjects

List of rpart.object objects with fitted CART.

Details

The following script variables are summarized in scriptvars list:

brush.pred

[logical(1)]
Use brush vector as additional predictor.
Default is FALSE.

use.rows

[character(1)]
Rows to use in model fit. Possible values are all, non-brushed, or brushed.
Default is all.

split.cr

[character(1)]
Splitting criterion (for classification only). Possible values are Gini or Information. For details, check rpart.
Default is Gini.

min.split

[integer(1)]
Natural number for minimal node size. For details, check rpart.control
Default is 20.

prune

[logical(1)]
Automatic pruning of the tree by choosing the model with the lowest cross-validated error. For details, check prune.rpart.
Default is FALSE.

graph.width

[integer(1)]
Graph width for decision tree graph output in Cornerstone.
Default is 700.

graph.height

[integer(1)]
Graph height for decision tree graph output in Cornerstone.
Default is 700.

Examples

# Fit CART to iris data:
res <- decisionTree(iris, c("Sepal.Length", "Sepal.Width", "Petal.Length",
"Petal.Width"), "Species", scriptvars = list(brush.pred = FALSE,
use.rows = "all", split.cr = "Gini", min.split = 20, prune = TRUE, 
graph.width = 700, graph.height = 700),
brush = rep(FALSE, nrow(iris)), return.results = TRUE)

# Show general statistics:
res$statistics
#>                          Statistic          Value
#>                             <char>         <char>
#> 1:                            Type Classification
#> 2:                 Number of Trees              1
#> 3:                     Sample Size            150
#> 4: Number of Independent Variables              4
#> 5:               Minimal Node Size             20
#> 6:                       Splitrule           Gini
#> 7:            Prediction Error [%]              4
#> 8:            Runtime R Script [s]        0.01779
# Prediction
modelPredict(iris[, 1:4], c("Sepal.Length", "Sepal.Width",
                    "Petal.Length", "Petal.Width"), robject = res$rgobjects,
                    scriptvars = list(Output.fmla = FALSE),
                    return.results = TRUE
                    )
#> Loading required namespace: ranger
#> $predictions
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width Pred.Species
#>             <num>       <num>        <num>       <num>       <fctr>
#>   1:          5.1         3.5          1.4         0.2       setosa
#>   2:          4.9         3.0          1.4         0.2       setosa
#>   3:          4.7         3.2          1.3         0.2       setosa
#>   4:          4.6         3.1          1.5         0.2       setosa
#>   5:          5.0         3.6          1.4         0.2       setosa
#>  ---                                                               
#> 146:          6.7         3.0          5.2         2.3    virginica
#> 147:          6.3         2.5          5.0         1.9    virginica
#> 148:          6.5         3.0          5.2         2.0    virginica
#> 149:          6.2         3.4          5.4         2.3    virginica
#> 150:          5.9         3.0          5.1         1.8    virginica
#>