Learn R Programming

itree (version 0.1)

estNodeRisk: Estimates risk at a each leaf node in a tree.

Description

Takes point-wise estimates of loss at each observation used to fit a tree and aggregates them over the leaf nodes in the tree.

Usage

estNodeRisk(tree.obj,est_observation_loss)

Arguments

Value

List with elements: est.risk is a vector of length equal to number of leaf nodes in tree.obj, each element is an estimate of out-of-sample risk at a particular node in tree.obj. This is computed by averaging the OOB losses over observations in that node. The order of est.risk is such that its first element corresponds to the first row that is a leaf node in tree.obj$frame. est.risk[2] corresponds to the second row that is a leaf node in tree.obj$frame, and so on. sd.loss = sd of the estimated losses for observations belonging to each node. In the same order as est.risk.

Examples

Run this code
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:
#don't run because of time to do bootstrap sampling...
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)

Run the code above in your browser using DataLab