clip.rpart: Prunes an Rpart Classification or Regression Tree

clip.rpartR Documentation

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)

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.

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.

Value

Pruned tree object of class rpart.

Author(s)

Denis White

See Also

rpart, prune.rpart

Examples

  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")

maptree documentation built on April 6, 2022, 5:09 p.m.

Related to clip.rpart in maptree...