# # EPage 374 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- save_plots = F library(DAAG) library(rpart) set.seed(0) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter11/prob_3_plot.eps", onefile=FALSE, horizontal=FALSE) } # Overfit our tree model and then prune: m = rpart( re78 ~ ., data=nswpsid1, method="anova", cp=0.002 ) plotcp(m) if( save_plots ){ dev.off() } cp_opt = 0.5 * ( 0.022 + 0.01 ) m = prune( m, cp=cp_opt ) plotcp(m) # Print the final tree: if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter11/prob_3_final_tree_plot.eps", onefile=FALSE, horizontal=FALSE) } plot(m); text(m) if( save_plots ){ dev.off() }