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