
Extract standardized residuals from a sequence of regression models, such as submodels along a robust or groupwise least angle regression sequence, or sparse least trimmed squares regression models for a grid of values for the penalty parameter.
# S3 method for seqModel
rstandard(model, s = NA, drop = !is.null(s), ...)# S3 method for tslars
rstandard(model, p, ...)
# S3 method for perrySeqModel
rstandard(model, ...)
# S3 method for sparseLTS
rstandard(
model,
s = NA,
fit = c("reweighted", "raw", "both"),
drop = !is.null(s),
...
)
A numeric vector or matrix containing the requested standardized residuals.
the model fit from which to extract standardize residuals.
for the "seqModel"
method, an integer vector giving the
steps of the submodels for which to extract the standardized residuals (the
default is to use the optimal submodel). For the "sparseLTS"
method,
an integer vector giving the indices of the models for which to extract
standardized residuals. If fit
is "both"
, this can be a list
with two components, with the first component giving the indices of the
reweighted fits and the second the indices of the raw fits. The default is
to use the optimal model for each of the requested estimators. Note that
the optimal models may not correspond to the same value of the penalty
parameter for the reweighted and the raw estimator.
a logical indicating whether to reduce the dimension to a vector in case of only one step.
for the "tslars"
method, additional arguments to be
passed down to the "seqModel"
method. For the other methods,
additional arguments are currently ignored.
an integer giving the lag length for which to extract standardized residuals (the default is to use the optimal lag length).
a character string specifying which standardized residuals to
extract. Possible values are "reweighted"
(the default) for the
standardized residuals from the reweighted estimator, "raw"
for the
standardized residuals from the raw estimator, or "both"
for the
standardized residuals from both estimators.
Andreas Alfons
rstandard
, residuals
rlars
, grplars
, rgrplars
,
tslarsP
, rtslarsP
, tslars
,
rtslars
, sparseLTS
## generate data
# example is not high-dimensional to keep computation time low
library("mvtnorm")
set.seed(1234) # for reproducibility
n <- 100 # number of observations
p <- 25 # number of variables
beta <- rep.int(c(1, 0), c(5, p-5)) # coefficients
sigma <- 0.5 # controls signal-to-noise ratio
epsilon <- 0.1 # contamination level
Sigma <- 0.5^t(sapply(1:p, function(i, j) abs(i-j), 1:p))
x <- rmvnorm(n, sigma=Sigma) # predictor matrix
e <- rnorm(n) # error terms
i <- 1:ceiling(epsilon*n) # observations to be contaminated
e[i] <- e[i] + 5 # vertical outliers
y <- c(x %*% beta + sigma * e) # response
x[i,] <- x[i,] + 5 # bad leverage points
## robust LARS
# fit model
fitRlars <- rlars(x, y, sMax = 10)
# extract standardized residuals
rstandard(fitRlars)
head(rstandard(fitRlars, s = 1:5))
## sparse LTS over a grid of values for lambda
# fit model
frac <- seq(0.2, 0.05, by = -0.05)
fitSparseLTS <- sparseLTS(x, y, lambda = frac, mode = "fraction")
# extract standardized residuals
rstandard(fitSparseLTS)
head(rstandard(fitSparseLTS, fit = "both"))
head(rstandard(fitSparseLTS, s = NULL))
head(rstandard(fitSparseLTS, fit = "both", s = NULL))
Run the code above in your browser using DataLab