We will run our rpart algorithm as a regression tree. Recall that a regression tree is used when the output variable is in numerical form, rather than nominal form. Before we do that, we need to map our frisked=Y/N to frisked=1/0 and specify method="anova" in the call.
The last line of code (fit) will print out the decision rules to the console as text.
The height, sex, age, and city parameters appear as the primary splits:
set.seed(123) library(rpart) dflocal$frisked_bin <- ifelse(dflocal$frisked=="Y",1,0) fit <- rpart(frisked_bin ~ sex + age + weight + height + perstop + city , method="anova", maxdepth=3, cp=.001, data=dflocal) fit