TeachingDemos (version 2.12)

tree.demo: Interactively demonstrate regression trees

Description

Interactively recursively partition a dataset to demonstrate regression trees.

Usage

tree.demo(x, y)

Value

A vector with the x-values of the cut points that you selected (sorted).

Arguments

x

The predictor variable.

y

The response variable.

Author

Greg Snow 538280@gmail.com

Details

This function first creates a scatterplot of x and y and shows the residual sum of squares from fitting a horizontal line to the y-values.

Clicking anywhere on the graph will show an updated graph where the data is partitioned into 2 groups based on the x-value where you clicked with a horizontal line fit to each group (including showing the updated residual sum of squares). Clicking again will move the partitioning value based on the new click.

When you have found a good partitioning (reduces the RSS), right click and choose 'stop' and that partition will become fixed. Now you can click to do a second set of partions (breaking the data into 3 groups).

To finish the demo, right click and choose 'stop', then right click again and choose 'stop' again.

See Also

The rpart and tree packages

Examples

Run this code
if(interactive()){
data('ethanol', package='lattice')
print(with(ethanol, tree.demo(E,NOx)))
}

Run the code above in your browser using DataCamp Workspace