# # 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(29) head.injury$clinically.important.brain.injury = as.factor(head.injury$clinically.important.brain.injury) # Part (a): # m = rpart( clinically.important.brain.injury ~ ., data=head.injury, method="class" ) # Part (b-c): # if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter11/prob_1_plot.eps", onefile=FALSE, horizontal=FALSE) } m = rpart( clinically.important.brain.injury ~ ., data=head.injury, method="class", cp=0.0001 ) plotcp(m) if( save_plots ){ dev.off() } # Pick the tree of size 4 by pruning using that trees value of cp # m = prune( m, cp=0.022 ) # Display the tree: plot(m); text(m, digits=3)