\Header{residuals.rpart}{Residuals From a Fitted Rpart Object}
\keyword{tree}{residuals.rpart}
\begin{Description}\relax
Method for \code{residuals} for an \code{rpart} object.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'rpart':
residuals(object, type = c("usual", "pearson", "deviance"), ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] fitted model object of class \code{"rpart"}.

\item[\code{type}] Indicates the type of residual desired.

For regression or \code{anova} trees all three residual
definitions reduce to \code{y - fitted}.  This is the residual returned for
\code{user} method trees as well.

For classification trees the \code{usual} residuals
are the missclassification losses L(actual, predicted) where L is the
loss matrix.  With default losses this residual is
0/1 for correct/incorrect classification.
The \code{pearson} residual is 
(1-fitted)/sqrt(fitted(1-fitted)) and the \code{deviance} residual is 
sqrt(minus twice logarithm of fitted).

For \code{poisson} and \code{exp}
(or survival) trees, the \code{usual} residual
is the observed - expected number of events.
The \code{pearson} and \code{deviance} residuals are as defined in
McCullagh and Nelder.

\item[\code{...}] further arguments passed to or from other methods.
\end{ldescription}
\end{Arguments}
\begin{Value}
vector of residuals of type \code{type} from a fitted \code{rpart} object.
\end{Value}
\begin{References}\relax
McCullagh P. and Nelder, J. A. (1989)
\emph{Generalized Linear Models}.
London: Chapman and Hall.
\end{References}
\begin{Examples}
\begin{ExampleCode}
data(solder)
fit <- rpart(skips ~ Opening + Solder + Mask + PadType + Panel,
       data=solder, method='anova')
summary(residuals(fit))
plot(predict(fit),residuals(fit))
\end{ExampleCode}
\end{Examples}

