get_residuals {api2lm} | R Documentation |
Extract residuals from a model
Description
Extracts different types of residuals from a fitted model. The types of residuals are discussed in Details.
Usage
get_residuals(
x,
rtype = c("ordinary", "standardized", "studentized", "jackknife", "loo", "deleted",
"internally studentized", "externally studentized")
)
Arguments
x |
An |
rtype |
The desired residual type. The options are
|
Details
For observations , let:
-
denote the response value for the
th observation.
-
denote the fitted value for the
th observation.
-
denote the leverage value for the
th observation.
We assume that for
and that
is the estimate produced by
sigma(x)
, where x
is the fitted model object.
The ordinary residual for the th
observation is computed as
The variance of the i
th ordinary residual under standard
assumptions is .
The standardized residual for the th observation
is computed as
The standardized residual is also known as the internally studentized residual.
Let denote the predicted value of
for the model fit with all
observations
except observation
. The leave-one-out (LOO) residual for observation
is
computed as
The LOO residual is also known as the deleted or jackknife residual.
The studentized residual for the th observation
is computed as
where is the leave-one-out estimate
of
.
The studentized residual is also known as the externally studentized residual.
Value
A vector of residals.
Examples
lmod <- lm(Girth ~ Height, data = trees)
# ordinary residuals
rord <- get_residuals(lmod)
all.equal(rord, residuals(lmod))
# standardized residuals
rstand <- get_residuals(lmod, "standardized")
all.equal(rstand, rstandard(lmod))
# studentized residuals
rstud <- get_residuals(lmod, "studentized")
all.equal(rstud, rstudent(lmod))
# loo residuals
rl <- get_residuals(lmod, "loo")
all.equal(rl, rloo(lmod))