Description Usage Arguments Details Value See Also Examples
Gives the predicted values for an rpart
fit, under
cross validation, for a set of complexity parameter values.
1  xpred.rpart(fit, xval = 10, cp, return.all = FALSE)

fit 
a object of class 
xval 
number of crossvalidation groups. This may also be an explicit list of integers that define the crossvalidation groups. 
cp 
the desired list of complexity values. By default it is taken from the

return.all 
if FALSE return only the first element of the prediction 
Complexity penalties are actually ranges, not values. If the
cp
values found in the table were .36, .28,
and .13, for instance, this means that the first row of the
table holds for all complexity penalties in the range [.36, 1],
the second row for cp
in the range [.28, .36) and
the third row for [.13,.28). By default, the geometric mean
of each interval is used for cross validation.
A matrix with one row for each observation and one column for each complexity
value. If return.all
is TRUE and the prediction for each node
is a vector, then the result will be an array containing all of the
predictions. When the response is categorical, for instance, the
result contains the predicted class followed by the class
probabilities of the selected terminal node;
result[1,,]
will be the matrix of predicted classes,
result[2,,]
the matrix of class 1 probabilities, etc.
1 2 3 4 5 6 7 8  fit < rpart(Mileage ~ Weight, car.test.frame)
xmat < xpred.rpart(fit)
xerr < (xmat  car.test.frame$Mileage)^2
apply(xerr, 2, sum) # crossvalidated error estimate
# approx same result as rel. error from printcp(fit)
apply(xerr, 2, sum)/var(car.test.frame$Mileage)
printcp(fit)

0.79767456 0.28300396 0.04154257 0.01132626
1427.9444 749.0734 552.4648 547.0883
0.79767456 0.28300396 0.04154257 0.01132626
62.19530 32.62651 24.06306 23.82888
Regression tree:
rpart(formula = Mileage ~ Weight, data = car.test.frame)
Variables actually used in tree construction:
[1] Weight
Root node error: 1354.6/60 = 22.576
n= 60
CP nsplit rel error xerror xstd
1 0.595349 0 1.00000 1.04140 0.178724
2 0.134528 1 0.40465 0.51297 0.079626
3 0.012828 2 0.27012 0.35773 0.064566
4 0.010000 3 0.25729 0.35815 0.064450
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.