Cross Validation of a Tree Sequence

DESCRIPTION:

Cross validates the tree sequence obtained by either shrinking or pruning a tree by partitioning the original dataset into a number of distinct subsets, fitting subtree sequences to these, and using a subset previously held out to evaluate the sequence.

USAGE:

cv.tree(object, rand, FUN = shrink.tree, ..., big = F) 

REQUIRED ARGUMENTS:

object
fitted model object of class tree. This is assumed to be the result of some function that produces an object with the same named components as that returned by the tree() function.

OPTIONAL ARGUMENTS:

rand
an integer vector of length equal to the number of observations in the root node of tree. All elements of rand are in set 1:K for K-fold cross-validation. An entry of 5, say, in the first position indicates that the first observation will be in the test set in the 5th cross-validated replicate and in the training set for all K-1 remaining replicates. If rand is missing, random 10-fold cross-validation is performed.
FUN
name of a function that produces an object of class tree.sequence. Currently, prune.tree and shrink.tree are the only such functions available.
...
additional arguments to FUN, in particular the argument k, the cost-complexity parameter if FUN is prune.tree or the shrinkage parameter if FUN is shrink.tree. See these functions for details on the use of k.
big
If big is TRUE, object is attached in frame = 1 before deviance is calculated and detached before the value is returned.

VALUE:

an object of class tree.sequence is returned. The object contains the following components:
size
Number of terminal nodes in each tree in the defining sequence
deviance
Total deviance of each tree in the defining sequence
k
The value of the sequencing parameter of each tree in the sequence

DETAILS:

A plot method exists for objects of this class. It displays the value of the deviance for each tree in the sequence. An additional axis displays the values of the sequencing parameter for each tree.

REFERENCES:

Chambers, J.M., and Hastie, T.J. (1991). Statistical Models in S, pp. 393--395 and 409--410

SEE ALSO:

, , .

EXAMPLES:

z.auto <- tree(Mileage ~ Weight, car.test.frame) 
zcv <- cv.tree(z.auto, k=(1:9)/10) 
plot(zcv)