Place Text on a Dendrogram

Description

Labels the current plot of the tree dendrogram with text. Extends text.rpart to also print itree's node risk estimate along with the fitted values.

Usage

1
2
3
4
## S3 method for class 'itree'
text(x, splits=TRUE, label, FUN=text, all=FALSE,
     pretty=NULL, digits=getOption("digits") - 3, use.n=FALSE,
     fancy=FALSE, fwidth=0.8, fheight=0.8, est_node_risk = NULL,use_sd=FALSE, ...)

Arguments

x

fitted model object of class itree. This is assumed to be the result of some function that produces an object with the same named components as that returned by the itree function.

splits

logical flag. If TRUE (default), then the splits in the tree are labeled with the criterion for the split.

label

For compatibility with itree2, ignored in this version (with a warning).

FUN

the name of a labeling function, e.g. text.

all

Logical. If TRUE, all nodes are labeled, otherwise just terminal nodes.

pretty

an integer denoting the extent to which factor levels in split labels will be abbreviated. A value of (0) signifies no abbreviation. A NULL, the default, signifies using elements of letters to represent the different factor levels.

digits

number of significant digits to include in numerical labels.

use.n

Logical. If TRUE, adds to label (\#events level1/ \#events level2/etc. for class, n for anova, and \#events/n for poisson and exp).

fancy

Logical. If TRUE, nodes are represented by ellipses (interior nodes) and rectangles (leaves) and labeled by yval. The edges connecting the nodes are labeled by left and right splits.

fwidth

Relates to option fancy and the width of the ellipses and rectangles. If fwidth < 1 then it is a scaling factor (default = 0.8). If fwidth > 1 then it represents the number of character widths (for current graphical device) to use.

fheight

Relates to option fancy and the height of the ellipses and rectangles. If fheight <1 then it is a scaling factor (default = 0.8). If fheight > 1 then it represents the number of character heights (for current graphical device) to use.

est_node_risk

If not NULL, an object of class estNodeRisk giving the risk estimates to print at each node.

use_sd

If TRUE, prints sd of the average losses for each node. Default is FALSE.

...

Graphical parameters may also be supplied as arguments to this function (see par). As labels often extend outside the plot region it can be helpful to specify xpd = TRUE.

Side Effects

the current plot of a tree dendrogram is labeled.

See Also

text, plot.itree, itree, post.itree, abbreviate

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# from rpart:
freen.tr <- itree(y ~ ., freeny)
plot(freen.tr)
text(freen.tr, use.n=TRUE, all=TRUE)

###unique to itree, plotting node risk:
require(mlbench); data(BostonHousing)
#fit a tree:
cart <- itree(medv~.,BostonHousing,minsplit=25,minbucket=25,cp=0)

#generate theta-hat values by computing average out-of-bag loss:
## Not run: 
#don't run it because of time to do the bootstrap...
theta_hats <- getOOBLoss(model_tree.obj=cart.bh,data=bh,nboot=100)

# Then for each leaf we estimate local risk by the mean in-node theta-hat.
lre <- estNodeRisk(tree.obj=cart.bh,est_observation_loss=theta_hats$avgOOBloss)

# to add the lre to the plot:
plot(cart.bh, do_node_re= TRUE, uniform=TRUE)
text(cart.bh, est_node_risk = lre)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.