Predictions from a Fitted Rpart Object

Usage

predict.rpart(object, newdata=list(), type=c("vector", "tree"))

Arguments

object fitted model object of class rpart. This is assumed to be the result of some function that produces an object with the same named components as that returned by the rpart function.
newdata data frame containing the values at which predictions are required. The predictors referred to in the right side of formula(object) must be present by name in newdata. If missing, the fitted values are returned.
type character string denoting whether the predictions are returned as a vector (default) or as an rpart object.

Description

Returns a vector of predicted responses from a fitted rpart object.

Details

This function is a method for the generic function predict for class rpart. It can be invoked by calling predict for an object of the appropriate class, or directly by calling predict.rpart regardless of the class of the object.

Value

if 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 at the node is the prediction. if type="tree" an object of class rpart is returned with new values for frame$n and frame$yval (and frame$yprob if it exists).

See Also

predict, rpart.object

Examples

data(car.test.frame)
z.auto <- rpart(Mileage ~ Weight, car.test.frame)
predict(z.auto)


[Package Contents]