Nodes and Splits in an rpart Tree
Node.Rd
The rpart
result object has a complex and compact design. This can make practical use tedious for occasional users as it is difficult to figure out how to access some specific information. The function Node()
is designed as accessor to the most important properties of a node, being a 'split' or a 'leaf' (aka. 'endnode'). It also serves as base for further convenience functions as e.g. LeafRates()
.
Usage
Node(x, node = NULL, type = c("all", "split", "leaf"), digits = 3)
Details
Node()
returns detailed information for a single node in the tree. It reports all the data in the summary of a node, but with the option to provide a nodelist. The structure of the result is organised as a list.
Value
A list containing:
- id
int, id of the node
- vname
character, one out of
'leaf'
or'split'
- isleaf
logical,
TRUE
for leavesFALSE
else- nobs
integer, number of observation in the node
- group
character, the predicted class for the node
- ycount
numeric, the number of observation per class in the node
- yprob
numeric, the relative frequencies for the each class
- nodeprob
the global probability for an observation to fall in the node
- complexity
numeric, the complexity parameter for the node
- tprint
character, the text to be printed
Examples
r.rpart <- FitMod(Species ~ ., data=iris, fitfn="rpart")
# return Node nr. 3
Node(r.rpart, node=3)
#>
#> Node number 3: 100 observations, complexity param=0.44
#> predicted class=versicolor expected loss=0.5 P(node) =0.667
#> class counts: 0 50 50
#> probabilities: 0.000 0.500 0.500
#> left son=6 (54 obs) right son=7 (46 obs)
#> Primary splits:
#> Petal.Width < 1.75 to the left, improve=39, (0 missing)
#> Petal.Length < 4.75 to the left, improve=37.4, (0 missing)
#> Sepal.Length < 6.15 to the left, improve=10.7, (0 missing)
#> Sepal.Width < 2.45 to the left, improve=3.56, (0 missing)
#> Surrogate splits:
#> Petal.Length < 4.75 to the left, agree=0.91, adj=0.804, (0 split)
#> Sepal.Length < 6.15 to the left, agree=0.73, adj=0.413, (0 split)
#> Sepal.Width < 2.95 to the left, agree=0.67, adj=0.283, (0 split)
#>
r.rp <- FitMod(Type ~ ., data = d.glass, fitfn="rpart")
# return all the splits
Node(r.rpart, type="split")
#>
#> Node number 1: 150 observations, complexity param=0.5
#> predicted class=setosa expected loss=0.667 P(node) =1
#> class counts: 50 50 50
#> probabilities: 0.333 0.333 0.333
#> left son=2 (50 obs) right son=3 (100 obs)
#> Primary splits:
#> Petal.Length < 2.45 to the left, improve=50, (0 missing)
#> Petal.Width < 0.8 to the left, improve=50, (0 missing)
#> Sepal.Length < 5.45 to the left, improve=34.2, (0 missing)
#> Sepal.Width < 3.35 to the right, improve=19, (0 missing)
#> Surrogate splits:
#> Petal.Width < 0.8 to the left, agree=1, adj=1, (0 split)
#> Sepal.Length < 5.45 to the left, agree=0.92, adj=0.76, (0 split)
#> Sepal.Width < 3.35 to the right, agree=0.833, adj=0.5, (0 split)
#>
#>
#> Node number 3: 100 observations, complexity param=0.44
#> predicted class=versicolor expected loss=0.5 P(node) =0.667
#> class counts: 0 50 50
#> probabilities: 0.000 0.500 0.500
#> left son=6 (54 obs) right son=7 (46 obs)
#> Primary splits:
#> Petal.Width < 1.75 to the left, improve=39, (0 missing)
#> Petal.Length < 4.75 to the left, improve=37.4, (0 missing)
#> Sepal.Length < 6.15 to the left, improve=10.7, (0 missing)
#> Sepal.Width < 2.45 to the left, improve=3.56, (0 missing)
#> Surrogate splits:
#> Petal.Length < 4.75 to the left, agree=0.91, adj=0.804, (0 split)
#> Sepal.Length < 6.15 to the left, agree=0.73, adj=0.413, (0 split)
#> Sepal.Width < 2.95 to the left, agree=0.67, adj=0.283, (0 split)
#>