### Kyphosis example from help file fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis) fit2 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis, parms=list(prior=c(.65,.35), split='information')) fit3 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis, control=rpart.control(cp=.05)) par(mfrow=c(1,2), xpd=NA) # otherwise on some devices the text is clipped plot(fit) text(fit, use.n=TRUE) plot(fit2) text(fit2, use.n=TRUE) ### Black Bass ID example morph = read.csv("300500morph.csv") names(morph) ### Grow overfit tree, get Summary and Plots tree = rpart(SPP ~ Pyloric + Jaw + Tooth + VL + Dorsal + Spiny + Last + Base + Lateral, data=morph, method="class", control=rpart.control(minsplit=2, cp=.00001)) par(mfrow=c(1,2), xpd=NA) # otherwise on some devices the text is clipped plot(tree) text(tree, use.n=TRUE, all=TRUE, cex=.6) summary(tree) ### Cost-complexity parameter plot printcp(tree) plotcp(tree) ### Prune Tree and get Summary and Plots ptree = prune(tree, cp=.044) summary(ptree) printcp(ptree) par(mfrow=c(1,2), xpd=NA) # otherwise on some devices the text is clipped plot(ptree) text(ptree, use.n=T, all=T, cex=.8) plotcp(ptree)