k
that optimally shrinks lower nodes
to their parent nodes based upon the magnitude of the difference
between the fitted
values of the lower nodes
and the fitted values of their parent nodes.
shrink.tree(tree, k=(1:10)/(20:11), newdata)
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.
k
.
By default the sequence
(1:10)/(20:11)
(roughly .05 to .91) is used.
newdata
.
If missing, the data used to grow the tree are used.
The response as well as the predictors referred to in the right side
of the formula in
tree
must be present by name in
newdata
.
These data are dropped down each shrunken tree in the sequence and deviances
calculated by comparing the supplied response to the prediction.
k
is supplied and is a scalar, a tree object is returned
that has the same topology as the supplied
tree
but
new values for the
yval/yprob
,
dev
, and
n
components of
tree$frame
.
tree.sequence
is returned.
The object contains the following components:
A
plot
method exists for objects of class
"tree.sequence"
.
It displays the value of the deviance for each shrunken tree in the sequence.
An additional axis displays the values of the shrinkage parameter for each tree.
z.auto <- tree(Mileage ~ Weight, car.test.frame) zs <- shrink.tree(z.auto) # determine the optimal shrinking sequence plot(zs) znew <- shrink.tree(z.auto, k=.4) # select a specific shrunken tree in the sequence