Learn R Programming

maptree (version 1.4-9)

clip.rpart: Prunes an Rpart Classification or Regression Tree

Description

Reduces a prediction tree produced by rpart to a smaller tree by specifying either a cost-complexity parameter, or a number of nodes to which to prune.

Usage

clip.rpart (tree, cp=NULL, best=NULL)

Value

Pruned tree object of class rpart.

Arguments

tree

object of class rpart.

cp

cost-complexity parameter.

best

number of nodes to which to prune.

If both cp and best are not NULL, then

cp is used.

Author

Denis White

Details

A minor enhancement of the existing prune.rpart to incorporate the parameter best as it is used in the (now defunct) prune.tree function in the old tree package. See example.

See Also

Examples

Run this code
  library (rpart)
  data (oregon.env.vars, oregon.border, oregon.grid)

  draw.tree (clip.rpart (rpart (oregon.env.vars), best=7), 
    nodeinfo=TRUE, units="species", cases="cells", digits=0)

  group <- group.tree (clip.rpart (rpart (oregon.env.vars), best=7))
  names(group) <- row.names(oregon.env.vars)
  map.groups (oregon.grid, group)
  lines (oregon.border)
  map.key (0.05, 0.65, labels=as.character(seq(6)), 
    size=1, new=FALSE, sep=0.5, pch=19, head="node")

Run the code above in your browser using DataLab