\Header{xpred.rpart}{Return Cross-Validated Predictions}
\keyword{tree}{xpred.rpart}
\begin{Description}\relax
Gives the predicted values for an \code{rpart} fit, under
cross validation, for a set of complexity parameter values.
\end{Description}
\begin{Usage}
\begin{verbatim}
xpred.rpart(fit, xval=10, cp)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{fit}] a \code{rpart} object. 

\item[\code{xval}] number of cross-validation groups.  This may also be an explicit list of
integers that define the cross-validation groups.

\item[\code{cp}] the desired list of complexity values.  By default it is taken from the
\code{cptable} component of the fit.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Complexity penalties are actually ranges, not values.  If the
\code{cp} values found in the table were \eqn{.36}{}, \eqn{.28}{},
and \eqn{.13}{}, for instance, this means that the first row of the
table holds for all complexity penalties in the range \eqn{[.36, 1]}{},
the second row for \code{cp} in the range \eqn{[.28, .36)}{} and
the third row for \eqn{[.13,.28)}{}.  By default, the geometric mean
of each interval is used for cross validation.
\end{Details}
\begin{Value}
a matrix with one row for each observation and one column for each complexity
value.
\end{Value}
\begin{SeeAlso}\relax
\code{\Link{rpart}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(car.test.frame)
fit <- rpart(Mileage ~ Weight, car.test.frame)
xmat <- xpred.rpart(fit)
xerr <- (xmat - car.test.frame$Mileage)^2
apply(xerr, 2, sum)   # cross-validated error estimate

# approx same result as rel. error from printcp(fit)
apply(xerr, 2, sum)/var(car.test.frame$Mileage) 
printcp(fit)
\end{ExampleCode}
\end{Examples}

