tree: Create a Tree-based Model

View source: R/tree.R

treeR Documentation

Create a Tree-based Model

Description

Create either a classification or regression tree model.

Usage

tree(x, data, cp = 0.01, minsplit = 20, ...)

Arguments

x

Formula. An expression of the form y ~ x | z where x is the variable we want on the x-axis, y is the variable we want on the y-axis and z is an optional variable we would like to use for faceting.

data

Data frame. The data where the variables can be found.

cp

Number. Stands for complexity parameter, which determins how simple or complex to build the model. Default value is 0.01. Smaller values result in more complex models.

minsplit

Integer. The minimum number of data points that need to be categorized into a node before the algorithm decides to split the node into a pair of branches.

Examples

m1 <- tree(survived ~ age + embarked + class, data = titanic)
treeplot(m1)

# For a more complex model
m2 <- tree(survived ~ age + embarked + class, data = titanic, cp = 0.001, minsplit = 5)
treeplot(m2)


mobilizingcs/mobilizr documentation built on Feb. 17, 2024, 7:49 p.m.