Session Ready
Exercise

Using the recursive partitioning model architecture

In the previous exercise, you used the linear modeling architecture to construct a model of a runner's time as a function of age and sex. There are many different model architectures available. In this exercise, you'll build models using the recursive partitioning architecture and the same Runners data frame as in the previous question. The model-building function to use is rpart(), which is analogous to lm() for linear models.

The recursive partitioning architecture has a parameter, cp, that allows you to dial up or down the complexity of the model being built. Without worrying about the details just yet, you can set this parameter as a named argument to rpart(). In later chapters, you'll work with tools for determining a good value for cp. (If you're really curious about the nitty-gritty details of cp, check out ?rpart.control.)

Instructions
100 XP
  • Load the rpart package
  • Using the rpart() function (from the rpart package) construct a model of net running time versus age and sex. Set the complexity parameter cp = 0.002. Store the result as model_2.
  • Use the command provided to examine a graph of the model.