\HeaderA{residuals.survreg}{Compute Residuals for `survreg' Objects}{residuals.survreg}
\methaliasA{residuals.survreg.penal}{residuals.survreg}{residuals.survreg.penal}
\keyword{survival}{residuals.survreg}
\begin{Description}\relax
This is a method for the function \code{\LinkA{residuals}{residuals}} for objects
inheriting from class \code{survreg}.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'survreg':
residuals(object, type=c("response", "deviance","dfbeta","dfbetas",
"working","ldcase","ldresp","ldshape", "matrix"), rsigma=TRUE,
collapse=FALSE, weighted=FALSE, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] an object inheriting from class \code{survreg}.

\item[\code{type}] type of residuals, with choices of \code{"response"}, \code{"deviance"},
\code{"dfbeta"}, \code{"dfbetas"}, \code{"working"}, \code{"ldcase"}, \code{"lsresp"},
\code{"ldshape"}, and \code{"matrix"}.  See the LaTeX documentation
(\code{survival/doc/survival.ps.gz}) for more
detail.

\item[\code{rsigma}] include the scale parameters in the variance matrix, when doing computations.
(I can think of no good reason not to).

\item[\code{collapse}] optional vector of subject groups.  If given, this must be of the same
length as the residuals, and causes the result to be per group residuals.

\item[\code{weighted}] give weighted residuals?  Normally residuals are unweighted.

\item[\code{...}] other unused arguments
\end{ldescription}
\end{Arguments}
\begin{Value}
A vector or matrix of residuals is returned.
Response residuals are on the scale of the original data,
working residuals are on the scale of the linear predictor,
and deviance residuals are on log-likelihood scale.
The dfbeta residuals are a matrix, where the ith row gives the
approximate change in the coefficients due to the addition of subject i.
The dfbetas matrix contains the dfbeta residuals, with each column
scaled by the standard deviation of that coefficient.


The matrix type produces a matrix based on derivatives of the log-likelihood
function.  Let \eqn{L}{} be the log-likelihood, \eqn{p}{} be the linear predictor \eqn{X\beta}{X \%*\% coef},
and \eqn{s}{} be \eqn{\log(\sigma)}{}.  Then the 6 columns of the matrix are
\eqn{L}{}, \eqn{dL/dp}{},\eqn{\partial^2L/\partial p^2}{ddL/(dp dp)},
\eqn{dL/ds}{}, \eqn{\partial^2L/\partial s^2}{ddL/(ds ds)}  and
\eqn{\partial^2L/\partial p\partial s}{ddL/(dp ds)}.  Diagnostics based on these quantities
are discussed in an article by Escobar and Meeker.
The main ones are the likelihood displacement residuals for perturbation
of a case weight (\code{ldcase}), the response value (\code{ldresp}), and the \code{shape}.
\end{Value}
\begin{References}\relax
Escobar, L. A. and Meeker, W. Q. (1992).
Assessing influence in regression analysis with censored data.
\emph{Biometrics}
\bold{48}, 507-528.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{predict.survreg}{predict.survreg}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
fit <- survreg(Surv(time,status) ~x, aml)
rr  <- residuals(fit, type='matrix')
\end{ExampleCode}
\end{Examples}

