sparseLTS(x, ...)
## S3 method for class 'formula':
sparseLTS(formula, data, ...)
## S3 method for class 'default':
sparseLTS(x, y, lambda,
mode = c("lambda", "fraction"), alpha = 0.75,
intercept = TRUE, nsamp = c(500, 10),
initial = c("sparse", "hyperplane", "random"),
ncstep = 2, use.correction = TRUE,
tol = .Machine$double.eps^0.5,
eps = .Machine$double.eps, use.Gram,
crit = c("BIC", "PE"), splits = foldControl(),
cost = rtmspe, costArgs = list(),
selectBest = c("hastie", "min"), seFactor = 1,
ncores = 1, cl = NULL, seed = NULL, model = TRUE, ...)
as.data.frame
) containing the variables in
the model. If not found in data, the variables are taken
fro"lambda"
, lambda
gives the grid of values for the penalty parameter
directly. If "fraction"
, the smallest value of
the penalty parameter tTRUE
)."sparse"
, the
lasso fit given by three randomly selected data points is
first computed. The corresponding initial subsample is
then formed by the fractiFALSE
. The d"BIC"
for the Bayes
information criterion and "PE"
for
resampling-based prediction error estimation.perryTuning
).perryTuning
for some
requirements). The default is to use the root trimmed
mean squared prediction error (see
cost
.perryTuning
). The default is to use
a one-standard-error rule.NA
, all available processor cores are used. For
prediction error estimation, makeCluster
.
This is preferred over ncores
for prediction error
estimation, in which case ncores<
.Random.seed
). On parallel
Rworker processes for prediction error estimation,
random number streams are used and the seed is set viax
and y
should be added to the return
object. If intercept
is TRUE
, a column of
ones is added to x
to account for the intercept.crit
is "PE"
, an object of class
"perrySparseLTS"
(inheriting from class
"perryTuning"
, see
perryTuning
). It contains
information on the prediction error criterion, and
includes the final model with the optimal tuning paramter
as component finalModel
.
Otherwise an object of class "sparseLTS"
with the
following components:"bicSelect"
containing the BIC values and indicating the final model
(only returned if argument crit
is "BIC"
and argument lambda
contains more than one value
for the penalty parameter).model
is
TRUE
).model
is
TRUE
).coef
,
fitted
,
plot
,
predict
,
residuals
,
wt
, ltsReg
## 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
## fit sparse LTS model for one value of lambda
sparseLTS(x, y, lambda = 0.05, mode = "fraction")
## fit sparse LTS models over a grid of values for lambda
frac <- seq(0.2, 0.05, by = -0.05)
sparseLTS(x, y, lambda = frac, mode = "fraction")
Run the code above in your browser using DataLab