## S3 method for class 'tree':
predict(object, newdata = list(),
type = c("vector", "tree", "class", "where"),
split = FALSE, nwts, eps = 1e-3, ...)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.formula(object) must be present by name in newdata.
If missing, fitted values are returned.split = TRUE cases withnewdata cases, used when predicting a tree.newdata when predicting a tree.type = "vector":
vector of predicted responses or, if the response is a factor, matrix
of predicted class probabilities. This new object is obtained by
dropping newdata down object. For factor predictors, if an
observation contains a level not used to grow the tree, it is left at
the deepest possible node and frame$yval or frame$yprob at that
node is the prediction.
If type = "tree":
an object of class "tree" is returned with new values
for frame$n and frame$dev. If
newdata does not contain a column for the response in the formula
the value of frame$dev will be NA, and if some values in the
response are missing, the some of the deviances will be NA.
If type = "class":
for a classification tree, a factor of the predicted classes (that
with highest posterior probability, with ties split randomly).
If type = "where":
the nodes the cases reach.
predict() for class tree.
It can be invoked by calling predict(x) for an
object x of the appropriate class, or directly by
calling predict.tree(x) regardless of the
class of the object.predict, tree.data(shuttle, package="MASS")
shuttle.tr <- tree(use ~ ., shuttle, subset=1:253,
mindev=1e-6, minsize=2)
shuttle.tr
shuttle1 <- shuttle[254:256, ] # 3 missing cases
predict(shuttle.tr, shuttle1)Run the code above in your browser using DataLab