| Type: | Package |
| Title: | Robust and Sparse Methods for High Dimensional Linear, Binary and Multinomial Regression |
| Version: | 1.2.0 |
| Description: | Fully robust versions of the elastic net estimator for linear, binary and multinomial regression, in particular for high dimensional data. The algorithm searches for outlier-free subsets on which the classical elastic net estimator can be applied. A reweighting step is added to improve the statistical efficiency of the estimators. The tuning parameters of the elastic net penalty are selected by cross-validation. The methods are described in Kurnaz, Hoffmann and Filzmoser (2018) <doi:10.1016/j.chemolab.2017.11.017> and in Kurnaz and Filzmoser (2023) <doi:10.1007/s10618-023-00936-6>. |
| Depends: | R (≥ 3.6.0) |
| Imports: | ggplot2 (≥ 3.4.0), glmnet, parallel, stats, robustbase, robustHD, grDevices |
| Suggests: | knitr, rmarkdown |
| VignetteBuilder: | knitr |
| License: | GPL (≥ 3) |
| URL: | https://github.com/fatmasevinck/enetLTS |
| BugReports: | https://github.com/fatmasevinck/enetLTS/issues |
| Encoding: | UTF-8 |
| Language: | en-US |
| LazyData: | true |
| NeedsCompilation: | no |
| Packaged: | 2026-11-18 21:41:52 UTC; root |
| Author: | Fatma Sevinc Kurnaz [aut, cre], Irene Hoffmann [aut], Peter Filzmoser [aut] |
| Maintainer: | Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-21 23:50:15 UTC |
Robust and Sparse Methods for High Dimensional Linear, Binary and Multinomial Regression
Description
Computes the robust elastic net estimator enetLTS for linear regression
(family = "gaussian"), binary logistic regression ("binomial") and
multinomial logistic regression ("multinomial"). The estimator searches for
an outlier-free subset of h observations on which the classical elastic net
is fitted, and a reweighting step improves its efficiency.
Usage
enetLTS(xx, yy, family = c("gaussian", "binomial", "multinomial"),
alphas = seq(0, 1, length = 41), lambdas = NULL, lambdaw = NULL,
intercept = TRUE, scal = TRUE, hsize = 0.75, nsamp = c(500, 10),
nCsteps = 20, nfold = 5, repl = 1, ncores = 1, tol = -1e6,
seed = NULL, del = 0.0125, crit.plot = FALSE, typegrouped = FALSE,
type.response = c("link", "response", "class"),
hgrid = c(0.65, 0.75, 0.85, 0.95), screen = TRUE, crossfit = NULL)
Arguments
xx |
a numeric matrix of predictors, |
yy |
the response. Numeric for |
family |
|
alphas |
the grid of the elastic net mixing parameter
|
lambdas |
the grid of the penalty parameter |
lambdaw |
the penalty of the reweighting step. By default it is chosen by
|
intercept |
logical; whether the model has an intercept (for
|
scal |
logical; if |
hsize |
the proportion of observations in the subset, |
nsamp |
a vector of two integers. Two C-steps are carried out on each of
|
nCsteps |
the largest number of C-steps in one iteration; the C-steps stop earlier when the criterion no longer improves. The default is 20. |
nfold |
the number of folds of the cross-validation. The default is 5. |
repl |
the number of repetitions of the cross-validation. The default is 1. |
ncores |
the number of processor cores (package parallel); |
tol |
not used by the current algorithm; kept for compatibility with earlier versions. |
seed |
an optional seed for the random number generator, set before the
elemental subsets are drawn (and, for |
del |
the tail probability of the reweighting step. For |
crit.plot |
logical; if |
typegrouped |
logical; |
type.response |
the scale of |
hgrid |
the candidate values of |
screen |
logical; |
crossfit |
logical or |
Details
The estimator applies the classical elastic net (glmnet) to subsets of the
data only. For one pair (\alpha, \lambda) the search starts from
nsamp[1] elemental subsets and improves them by C-steps; the C-steps keep the
h observations with the smallest squared residuals ("gaussian") or
negative log-likelihood contributions ("binomial", within each class). For
"multinomial" they keep, within each class k, the
\lfloor n_k \cdothsize+ 1\rfloor observations with the smallest
robust (MCD) distance in the space of the linear predictors.
For "binomial" the start subsets are ranked by the Bianco-Yohai criterion
(Croux and Haesbroeck, 2003), as in Kurnaz et al. (2018). The other grid points
are computed with warm starts. The pair (\alpha, \lambda) is chosen by
repl times repeated nfold-fold cross-validation on the best subsets
(see cv.enetLTS), and the raw fit is the elastic net on the best
subset of the chosen pair.
In the reweighting step the observations with large residuals of the raw fit get
weight 0 (see del and weights.enetLTS), and the elastic net
with penalty lambdaw is fitted to the observations with weight 1; this is
the reweighted fit. The weights wt are then computed from the reweighted
fit with the same rule. With crossfit = TRUE the raw weights come from the
cross-fitted trimming instead, and for "multinomial" wt then equals
raw.wt.
Value
An object of class "enetLTS", a list with components
objective |
the penalized criterion of the raw fit on the final subset
|
raw.rmse, rmse |
|
raw.mae, mae |
mean absolute residual of the raw and the reweighted fit on all
observations; for |
best |
the indices of the best subset of |
raw.wt |
integer 0/1 weights from the raw fit; the observations with weight 1 are used for the reweighted fit. |
wt |
integer 0/1 weights from the reweighted fit (0 = flagged as outlier). |
raw.coefficients, coefficients |
the coefficients of the raw and the
reweighted fit, intercept first (a matrix with one column per class for
|
raw.fitted.values, fitted.values |
the fitted values of the raw and the
reweighted fit, on the scale given by |
raw.residuals, residuals |
the residuals ( |
alpha |
the selected mixing parameter of the reweighted fit. |
alpha.raw |
|
lambda |
the selected penalty of the raw fit. |
lambdaw |
the penalty of the reweighted fit. |
num.nonzerocoef |
the number of nonzero coefficients of the reweighted fit. |
n, p |
the number of observations and of predictors. |
h |
the size of the subsets. |
classnames, classize |
|
screened |
|
hsize.search |
only if |
inputs |
a list with the data and the settings used by the fit. |
call |
the matched call. |
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
References
Kurnaz, F.S. and Filzmoser, P. (2023). enetLTS: Robust and sparse methods for high dimensional linear, binary, and multinomial regression. Journal of Open Source Software, 8(82), 4773. doi:10.21105/joss.04773
Kurnaz, F.S. and Filzmoser, P. (2023). Robust and sparse multinomial regression in high dimensions. Data Mining and Knowledge Discovery, 37(4), 1609–1629. doi:10.1007/s10618-023-00936-6
Kurnaz, F.S., Hoffmann, I. and Filzmoser, P. (2018). Robust and sparse estimation methods for high-dimensional linear and logistic regression. Chemometrics and Intelligent Laboratory Systems, 172, 211–222. doi:10.1016/j.chemolab.2017.11.017
Croux, C. and Haesbroeck, G. (2003). Implementing the Bianco and Yohai estimator for logistic regression. Computational Statistics & Data Analysis, 44, 273–295.
See Also
print.enetLTS, coef.enetLTS,
predict.enetLTS, outliers.enetLTS,
assess.enetLTS, plot.enetLTS,
cv.enetLTS, GaussianExample,
BinomialExample, MultinomialExample
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
fit
which(fit$wt == 0)
fitb
outliers.enetLTS(fitb)
fitm
fitm$screened
Simulated high-dimensional logistic regression data with outliers
Description
Simulated data for family = "binomial" with n = 100 observations and
p = 200 predictors (p > n), following the simulation design of
Kurnaz, Hoffmann and Filzmoser (2018).
Usage
data("BinomialExample")
Format
A list with components
xtraining predictors, a
100 \times 200matrix.ytraining response, a 0/1 vector of length 100.
outliersindices of the contaminated training observations (1, 3, 7, 13).
xtest,ytestclean test data with 200 observations.
betathe true slope vector (the true intercept is 1).
Details
The first 20 predictors are informative (\beta_j = 1) and correlated with
\mathrm{cor}(x_j, x_k) = 0.9^{|j-k|}; the other 180 are uninformative and correlated with
0.5^{|j-k|}. The response is y = 1 if 1 + x^\top\beta + \varepsilon > 0 with
\varepsilon \sim N(0,1), and y = 0 otherwise. The first 10% of the observations of
class 0 (4 observations) are contaminated: their informative predictors are drawn from N(20, 1) while their
label stays 0, so they are bad leverage points. Values are rounded to three decimals. The generating code is in the data-raw directory of the
package repository on GitHub.
References
Kurnaz, F.S., Hoffmann, I. and Filzmoser, P. (2018). Robust and sparse estimation methods for high-dimensional linear and logistic regression. Chemometrics and Intelligent Laboratory Systems, 172, 211–222. doi:10.1016/j.chemolab.2017.11.017
Examples
data("BinomialExample")
table(BinomialExample$y)
BinomialExample$outliers
Simulated high-dimensional linear regression data with outliers
Description
Simulated data for family = "gaussian" with n = 100 observations and
p = 200 predictors (p > n), following the simulation design of
Kurnaz, Hoffmann and Filzmoser (2018).
Usage
data("GaussianExample")
Format
A list with components
xtraining predictors, a
100 \times 200matrix.ytraining response, a numeric vector of length 100.
outliersindices of the contaminated training observations (1 to 10).
xtest,ytestclean test data with 200 observations.
betathe true slope vector (the true intercept is 1).
Details
The predictors form three independent blocks: two informative blocks of 10 predictors each with
\mathrm{cor}(x_j, x_k) = 0.9^{|j-k|}, and 180 uninformative predictors with
0.2^{|j-k|}. The response is y = 1 + x^\top\beta + \varepsilon with
\varepsilon \sim N(0,1), \beta_j = 1 for the 20 informative predictors and 0 otherwise.
The first 10 observations are contaminated: their informative predictors are drawn from
N(20, 1) and their errors from N(20\,\hat\sigma_y, 1), where \hat\sigma_y is the
standard deviation of the clean response, so they are both leverage points and vertical outliers.
Values are rounded to three decimals. The generating code is in the data-raw directory of the
package repository on GitHub.
References
Kurnaz, F.S., Hoffmann, I. and Filzmoser, P. (2018). Robust and sparse estimation methods for high-dimensional linear and logistic regression. Chemometrics and Intelligent Laboratory Systems, 172, 211–222. doi:10.1016/j.chemolab.2017.11.017
Examples
data("GaussianExample")
dim(GaussianExample$x)
GaussianExample$outliers
Simulated high-dimensional multinomial regression data with outliers
Description
Simulated data for family = "multinomial" with n = 150 observations,
p = 200 predictors (p > n) and K = 3 classes.
Usage
data("MultinomialExample")
Format
A list with components
xtraining predictors, a
150 \times 200matrix.ytraining response, a factor with levels 1, 2, 3.
outliersindices of the contaminated training observations (1 to 15).
xtest,ytestclean test data with 300 observations.
betathe true
200 \times 3matrix of slopes (the true intercepts are 0).
Details
The predictors are independent standard normal. Each class is driven by its own predictors:
\beta_{1,1} = \beta_{2,1} = 3 (class 1), \beta_{3,2} = \beta_{4,2} = 3 (class 2),
\beta_{5,3} = \beta_{6,3} = 3 (class 3); the class probabilities follow the multinomial
logistic model. The first 15 observations are contaminated: predictors 1 and 2 are shifted by 5
(far out in the direction of class 1) and the label is set to 3, so they are bad leverage points.
Values are rounded to three decimals. The generating code is in the data-raw directory of the
package repository on GitHub.
Examples
data("MultinomialExample")
table(MultinomialExample$y)
Assess an "enetLTS" fit on test data
Description
Performance measures, confusion matrix and ROC curve of a fitted
"enetLTS" object on (new) data.
Usage
assess.enetLTS(object, newX, newy, vers = c("both", "reweighted", "raw"))
confusion.enetLTS(object, newX, newy, vers = c("reweighted", "raw"))
roc.enetLTS(object, newX, newy, vers = c("reweighted", "raw"), plot = FALSE, ...)
## S3 method for class 'confusion.enetLTS'
print(x, ...)
Arguments
object |
a fitted object of class |
newX |
a numeric matrix with the predictors of the test data. |
newy |
the response of the test data: numeric for |
vers |
which fit to assess: |
plot |
logical; if |
x |
an object of class |
... |
not used. |
Details
The test data should be free of outliers, since they stand for the data on which the model is used.
assess.enetLTS computes the mean squared error mse, its root
rmse and the mean absolute error mae (gaussian); the deviance
deviance, the misclassification rate class, auc, mse
and mae of the predicted probabilities (binomial); and the same without
auc (multinomial; mse and mae are summed over the classes).
As in glmnet::assess.glmnet, deviance is twice the mean negative
log-likelihood. For "binomial" the second class of object$classnames
is the positive class, and an observation is classified as positive if its
probability is larger than 0.5.
confusion.enetLTS and roc.enetLTS are available for the
classification families (roc.enetLTS for "binomial" only).
Value
assess.enetLTS: a list with one element per measure, in the layout of
glmnet::assess.glmnet. Every element is a named vector with one value per
fit (reweighted, raw) and has the attribute "measure" with the
name of the measure.
confusion.enetLTS: an object of class "confusion.enetLTS", a list
with the contingency table table (predicted by true class) and the
proportion of correct classifications correct.
roc.enetLTS: a data frame with the columns FPR and TPR, with
the AUC as attribute "auc", invisibly.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
References
Hastie, T., Qian, J. and Tay, K. (2026). An Introduction to glmnet.
Vignette of the R package glmnet.
https://glmnet.stanford.edu/articles/glmnet.html
See Also
enetLTS, predict.enetLTS, outliers.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
xt <- matrix(rnorm(200 * p), 200, p) # clean test data
yt <- drop(xt %*% beta) + rnorm(200)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
xbt <- matrix(rnorm(200 * p), 200, p) # clean test data
ybt <- rbinom(200, 1, plogis(drop(xbt %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
assess.enetLTS(fit, xt, yt)
assess.enetLTS(fitb, xbt, ybt)
confusion.enetLTS(fitb, xbt, ybt)
roc.enetLTS(fitb, xbt, ybt, plot = TRUE)
Coefficients of an "enetLTS" fit
Description
Extracts the estimated coefficients of the reweighted or the raw fit.
Usage
## S3 method for class 'enetLTS'
coef(object, vers = c("reweighted", "raw"), zeros = TRUE, ...)
Arguments
object |
a fitted object of class |
vers |
a character string: |
zeros |
logical; if |
... |
not used. |
Value
For family = "gaussian" and "binomial", a named numeric vector: the
intercept "(Intercept)" (if intercept = TRUE) followed by the
slopes, named by the column names of xx (x1, x2, ... if
xx has no column names).
For family = "multinomial", a matrix with one row per coefficient (named as
above) and one column per class.
Note
In versions before 1.2.0, zeros = FALSE returned the indices of the nonzero
coefficients; these are now given by nonzeroCoef.enetLTS.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, predict.enetLTS,
nonzeroCoef.enetLTS, print.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
coef(fit, zeros = FALSE)
coef(fit, vers = "raw", zeros = FALSE)
coef(fitb, zeros = FALSE)
coef(fitm, zeros = FALSE)
Cross-validation over the (\alpha, \lambda) grid
Description
Repeated k-fold cross-validation over a grid of \alpha and
\lambda values, as used inside enetLTS. Returns the selected
pair and, optionally, draws a heat map of the criterion.
Usage
cv.enetLTS(index = NULL, family = c("gaussian", "binomial", "multinomial"),
xx, yy, alphas, lambdas, nfold = 5, repl = 1, ncores = NA, plot = TRUE)
Arguments
index |
|
family |
|
xx |
a numeric matrix of predictors. |
yy |
the response: numeric (gaussian), 0/1 (binomial), or class labels or an indicator matrix (multinomial). |
alphas |
the values of the mixing parameter |
lambdas |
the values of the penalty parameter. If missing, the default grid of
|
nfold |
the number of folds. The default is 5. |
repl |
the number of repetitions of the cross-validation; the criterion is averaged over the repetitions. The default is 1. |
ncores |
the number of processor cores; |
plot |
logical; if |
Details
The folds are random for the gaussian family and stratified by class for the
binomial and multinomial families. The criterion is the root mean squared
prediction error (gaussian) or the mean negative log-likelihood (binomial,
multinomial) of the test folds. If index = NULL, the observations are not
trimmed beforehand, so the largest 10% of the test-fold losses are left out of
the mean (labels RTMSPE, TMNLL). For the multinomial family the
largest 10% are always left out, within every class.
Value
A list with components
indexbest |
the subset of the selected pair ( |
evalCrit |
the matrix of the criterion, rows for |
minevalCrit |
the smallest value of the criterion. |
lambdaopt |
the selected |
alphaopt |
the selected |
Note
This function is called by enetLTS; it is exported so that the
tuning parameters can also be chosen for a given set of subsets.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
Examples
data("GaussianExample")
cv <- cv.enetLTS(family = "gaussian", xx = GaussianExample$x,
yy = GaussianExample$y, alphas = c(0.5, 1), ncores = 1)
cv[c("alphaopt", "lambdaopt")]
Fitted values of an "enetLTS" fit
Description
Fitted values of the reweighted and/or the raw fit for all observations of xx.
Usage
## S3 method for class 'enetLTS'
fitted(object, vers = c("reweighted", "raw", "both"),
type = c("response", "class"), ...)
Arguments
object |
a fitted object of class |
vers |
a character string: |
type |
|
... |
not used. |
Value
A list with the component fitted.values (vers = "reweighted"),
raw.fitted.values (vers = "raw") or both (vers = "both").
Each is a one-column matrix (gaussian, binomial), a matrix with one column per
class (multinomial, type = "response") or a vector of class labels
(type = "class").
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, predict.enetLTS, residuals.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
head(fitted(fit)$fitted.values)
table(fitted(fitb, type = "class")$fitted.values, yb)
head(fitted(fitm, vers = "raw")$raw.fitted.values)
Robust upper end of the penalty grid for logistic regression
Description
Robust estimate of the smallest value of the penalty parameter that sets all
slopes of the (lasso-penalized) logistic regression to zero. enetLTS
uses it as the upper end of the default lambdas grid for
family = "binomial".
Usage
lambda00(x, y, normalize = TRUE, intercept = TRUE, const = 2, prob = 0.95,
tol = .Machine$double.eps^0.5, eps = .Machine$double.eps, ...)
Arguments
x |
a numeric matrix of predictors. |
y |
a numeric 0/1 response vector. |
normalize |
logical; whether the winsorized predictors are normalized. The
default is |
intercept |
logical; whether the model has an intercept. The default is
|
const |
tuning constant of the univariate winsorization. The default is 2. |
prob |
probability of the |
tol |
a small positive value used to detect singularity in the computation of the correlations for the bivariate winsorization. |
eps |
a small positive value below which a robust scale estimate is treated as zero. |
... |
further arguments passed to |
Details
The procedure follows lambda0 (Alfons et al., 2013),
which is used for family = "gaussian": the predictors are robustly
standardized and the correlations between the response and each predictor are
computed on winsorized data. For the 0/1 response of logistic regression the
Pearson correlation is replaced by a robustified point-biserial correlation
(Kurnaz et al., 2018).
Value
A single positive number.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
References
Kurnaz, F.S., Hoffmann, I. and Filzmoser, P. (2018). Robust and sparse estimation methods for high-dimensional linear and logistic regression. Chemometrics and Intelligent Laboratory Systems, 172, 211–222. doi:10.1016/j.chemolab.2017.11.017
Alfons, A., Croux, C. and Gelper, S. (2013). Sparse least trimmed squares regression for analyzing high-dimensional large data sets. The Annals of Applied Statistics, 7(1), 226–248.
See Also
Examples
data("BinomialExample")
lambda00(BinomialExample$x, BinomialExample$y)
Indices of the nonzero coefficients of an "enetLTS" fit
Description
Returns the positions of the nonzero coefficients of the reweighted or the raw fit.
Usage
nonzeroCoef.enetLTS(object, vers = c("reweighted", "raw"))
Arguments
object |
a fitted object of class |
vers |
a character string: |
Value
For family = "gaussian" and "binomial", an integer vector with the
positions of the nonzero entries of coef(object, vers = vers). With
intercept = TRUE position 1 is the intercept, so the slope of predictor
j has position j + 1.
For family = "multinomial", a list with one such vector per class (a data
frame if all classes have the same number of nonzero coefficients).
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, coef.enetLTS, predict.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
nonzeroCoef.enetLTS(fit)
nonzeroCoef.enetLTS(fitb, vers = "raw")
nonzeroCoef.enetLTS(fitm)
Observations flagged as outliers by an "enetLTS" fit
Description
Returns, for every training observation, whether it has weight zero, its loss, the observed and the predicted response and a type label. The print method shows only the flagged observations.
Usage
outliers.enetLTS(object, vers = c("reweighted", "raw"))
## S3 method for class 'outliers.enetLTS'
print(x, ...)
Arguments
object |
a fitted object of class |
vers |
|
x |
an object of class |
... |
not used. |
Value
A data frame of class "outliers.enetLTS" with one row per observation and
the columns index, flagged, loss (absolute residual for
"gaussian", -\log \hat{p}_{i,y_i} otherwise), observed,
predicted and type.
For "gaussian", type is "outlier" for flagged observations.
For the classification families it is "leverage point" if a flagged
observation is predicted in its observed class, "possible mislabel / outlier"
if it is predicted in another class, and "leverage point (screened)" or
"bad leverage point (screened)" (predicted in the observed class or not) if
it was removed by the screening step of the multinomial family. Observations that
are not flagged are "regular".
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, weights.enetLTS, plotResid.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
out <- outliers.enetLTS(fit)
out
## compare with the contaminated observations 1, ..., m
table(flagged = out$flagged, contaminated = out$index %in% 1:m)
outliers.enetLTS(fitb)
outliers.enetLTS(fitm)
Plots of an "enetLTS" fit
Description
Draws the coefficient, residual and diagnostic plots of a fitted "enetLTS" object.
Usage
## S3 method for class 'enetLTS'
plot(x, method = c("coefficients", "resid", "diagnostic"),
vers = c("reweighted", "raw"), ...)
Arguments
x |
a fitted object of class |
method |
the plot to draw: |
vers |
a character string: |
... |
further arguments passed to the plot function, for example |
Value
The object x, invisibly. The plots are drawn as a side effect.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, plotCoef.enetLTS,
plotResid.enetLTS, plotDiagnostic.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
plot(fit, method = "resid")
plot(fitb, method = "diagnostic", vers = "raw")
plot(fitm, method = "coefficients")
Coefficient plot of an "enetLTS" fit
Description
Needle plot of the estimated slopes against the predictor index.
Usage
plotCoef.enetLTS(object, vers = c("reweighted", "raw"), colors = NULL, ...)
Arguments
object |
a fitted object of class |
vers |
a character string: |
colors |
not used; kept for compatibility with earlier versions. |
... |
not used. |
Details
Every slope is drawn as a vertical segment from zero, and the nonzero slopes are marked by a point. The intercept (one per class for the multinomial family) is given in the subtitle, together with the number of nonzero slopes. For the multinomial family there is one panel per class.
Value
The "ggplot" object, invisibly; the plot is drawn as a side effect.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, coef.enetLTS, plot.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
plotCoef.enetLTS(fit)
plotCoef.enetLTS(fitb, vers = "raw")
plotCoef.enetLTS(fitm)
Diagnostic plot of an "enetLTS" fit
Description
Plots the response against the linear predictor (gaussian, binomial) or the first two principal components of the linear predictors (multinomial).
Usage
plotDiagnostic.enetLTS(object, vers = c("reweighted", "raw"), zoom = TRUE, ...)
Arguments
object |
a fitted object of class |
vers |
a character string: |
zoom |
logical; if |
... |
not used. |
Details
For family = "gaussian" the plot shows y against
X\hat{\beta} with the line y = X\hat{\beta}. For
family = "binomial" it shows the 0/1 response against X\hat{\beta}
with the fitted logistic curve. For family = "multinomial" it shows the
scores of the first two principal components of the K linear predictors.
Observations are marked as flagged if they have weight 0 in wt
(vers = "reweighted") or if they are not in the best subset best
of the raw fit (vers = "raw"). For the gaussian family regular
observations are blue crosses and flagged ones red triangles. For the binomial
and multinomial families the class is shown by color and shape, and flagged
observations are drawn filled, regular ones open.
Value
The "ggplot" object, invisibly; the plot is drawn as a side effect.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, plotResid.enetLTS, outliers.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
plotDiagnostic.enetLTS(fit)
plotDiagnostic.enetLTS(fitb)
plotDiagnostic.enetLTS(fitm, zoom = FALSE)
Residual plots of an "enetLTS" fit
Description
Plots the residuals of the reweighted or the raw fit against the observation index and, for the gaussian and binomial families, against the linear predictor.
Usage
plotResid.enetLTS(object, vers = c("reweighted", "raw"), zoom = TRUE, ...)
Arguments
object |
a fitted object of class |
vers |
a character string: |
zoom |
logical; if |
... |
not used. |
Details
For family = "gaussian" the residuals are standardized as in the
reweighting step (location and scale from the observations with raw weight 1 for
the reweighted fit, from the best subset for the raw fit), and the horizontal
lines at \pmqnorm(1 - del) are the cut-offs of the reweighting step.
For family = "binomial" and "multinomial" the residuals are the
negative log-likelihood contributions (see residuals.enetLTS).
The multinomial family has only the index plot.
Observations are marked as flagged if they have weight 0 in wt
(vers = "reweighted") or if they are not in the best subset best
of the raw fit (vers = "raw"). For the gaussian family regular
observations are blue crosses and flagged ones red triangles. For the binomial
and multinomial families the class is shown by color and shape, and flagged
observations are drawn filled, regular ones open.
Value
A list of the drawn "ggplot" objects (two for the gaussian and binomial
families, one for the multinomial family), invisibly.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, residuals.enetLTS,
plotDiagnostic.enetLTS, outliers.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
plotResid.enetLTS(fit)
plotResid.enetLTS(fit, vers = "raw", zoom = FALSE)
plotResid.enetLTS(fitb)
plotResid.enetLTS(fitm)
Predictions from an "enetLTS" fit
Description
Linear predictors, fitted values or probabilities, class labels, coefficients or the
indices of the nonzero coefficients from a fitted "enetLTS" object.
Usage
## S3 method for class 'enetLTS'
predict(object, newX, vers = c("reweighted", "raw"),
type = c("link", "response", "coefficients", "nonzero", "class"), ...)
Arguments
object |
a fitted object of class |
newX |
a numeric matrix (or an object that |
vers |
a character string: |
type |
|
... |
not used. |
Value
A list with one component. Its name is link, response,
class, coefficients or nonzeroCoef, with the prefix
raw. for vers = "raw" (for example raw.response). For the
multinomial family, link and response are matrices with one column
per class.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, coef.enetLTS, fitted.enetLTS,
assess.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
xt <- matrix(rnorm(200 * p), 200, p) # clean test data
yt <- drop(xt %*% beta) + rnorm(200)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
xbt <- matrix(rnorm(200 * p), 200, p) # clean test data
ybt <- rbinom(200, 1, plogis(drop(xbt %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
xmt <- matrix(rnorm(200 * p), 200, p) # clean test data
pr <- exp(xmt %*% Bm); pr <- pr / rowSums(pr)
ymt <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
yhat <- predict(fit, xt, type = "response")$response
mean((yt - yhat)^2)
pb <- predict(fitb, xbt, type = "class")$class
table(predicted = pb, observed = ybt)
head(predict(fitm, xmt, type = "response")$response)
predict(fitm, xmt, vers = "raw", type = "class")$raw.class[1:10]
Print an "enetLTS" fit
Description
Prints a short summary of a fitted "enetLTS" object.
Usage
## S3 method for class 'enetLTS'
print(x, vers = c("reweighted", "raw"),
digits = max(3, getOption("digits") - 3), maxprint = 20, ...)
Arguments
x |
a fitted object of class |
vers |
a character string: |
digits |
the number of digits for the coefficients. |
maxprint |
the largest number of nonzero coefficients (for the multinomial
family: rows) that are printed; all are available with |
... |
not used. |
Details
The family and the call are printed, followed by the nonzero coefficients with the
variable names (x1, x2, ... if xx has no column names), the
number of nonzero slopes, the selected alpha, lambda and
lambdaw, and the number of observations flagged as outliers. For the
multinomial family the rows of the coefficient matrix that are nonzero in at least
one class are printed.
Value
The object x, invisibly.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, coef.enetLTS, outliers.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
fit
print(fit, vers = "raw")
fitb
fitm
Residuals of an "enetLTS" fit
Description
Residuals of the reweighted and/or the raw fit for all observations of xx.
Usage
## S3 method for class 'enetLTS'
residuals(object, vers = c("reweighted", "raw", "both"), ...)
Arguments
object |
a fitted object of class |
vers |
a character string: |
... |
not used. |
Details
For family = "gaussian" the residuals are y_i - \hat{y}_i.
For family = "binomial" and "multinomial" they are the negative
log-likelihood contributions of the observations,
-y_i\eta_i + \log(1 + e^{\eta_i}) and -\log \hat{p}_{i,y_i},
respectively (\eta_i is the linear predictor and \hat{p}_{i,y_i} the
fitted probability of the observed class).
Value
A list with the component residuals (vers = "reweighted"),
raw.residuals (vers = "raw") or both (vers = "both"); each is
a numeric vector.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
enetLTS, fitted.enetLTS, plotResid.enetLTS,
outliers.enetLTS
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
head(residuals(fit)$residuals)
str(residuals(fitb, vers = "both"))
summary(residuals(fitm)$residuals)
Binary outlier weights of an "enetLTS" fit
Description
Extracts the 0/1 weights that mark the outliers of the reweighted and/or the raw fit.
Usage
## S3 method for class 'enetLTS'
weights(object, vers = c("reweighted", "raw", "both"), index = FALSE, ...)
Arguments
object |
a fitted object of class |
vers |
a character string: |
index |
logical; if |
... |
not used. |
Details
An observation has weight 1 if it is regular and 0 if it is flagged as an outlier.
The raw weights raw.wt come from the raw fit and define the observations
used for the reweighted fit; the weights wt come from the reweighted fit.
With del the argument of enetLTS, the rules are:
- gaussian
standardized residuals (location and scale estimated from the observations with raw weight 1, with a consistency factor) larger than
qnorm(1 - del)in absolute value get weight 0.- binomial
Pearson residuals larger than
qnorm(1 - del)in absolute value get weight 0.- multinomial
with
crossfit = TRUE(the default) an observation gets weight 0 if its cross-fitted probability of the observed class is below a calibrated cut-off (seecrossfitinenetLTS); withcrossfit = FALSEit gets weight 0 if it is outlying in the space of the linear predictors (class-wise robust distances) or if the fitted probability of its observed class is below 1/6. Observations removed byscreen = TRUEhave weight 0 in both vectors.
Value
A list with the component wt (vers = "reweighted"), raw.wt
(vers = "raw") or both (vers = "both"); each is an integer vector of
length n.
Author(s)
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <fatmasevinckurnaz@gmail.com>
See Also
Examples
## linear regression
set.seed(86)
n <- 100; p <- 25 # observations and variables
beta <- c(rep(1, 6), rep(0, p - 6)) # six nonzero coefficients
x <- matrix(rnorm(n * p), n, p)
y <- drop(x %*% beta) + rnorm(n)
m <- 10 # contaminated observations
y[1:m] <- y[1:m] + 10 # vertical outliers
x[1:m, ] <- x[1:m, ] + 10 # bad leverage points
## logistic regression
set.seed(86)
n <- 100; p <- 25
beta <- c(rep(1, 6), rep(0, p - 6))
xb <- matrix(rnorm(n * p), n, p)
yb <- rbinom(n, 1, plogis(drop(xb %*% beta)))
mb <- 5
i0 <- which(yb == 0)[1:mb] # observations of class 0 ...
xb[i0, ] <- xb[i0, ] + 10 # ... become bad leverage points
## multinomial regression
set.seed(86)
n <- 120; p <- 15; K <- 3 # observations, variables, classes
Bm <- matrix(0, p, K)
Bm[1:2, 1] <- 3; Bm[3:4, 2] <- 3; Bm[5:6, 3] <- 3
xm <- matrix(rnorm(n * p), n, p)
pr <- exp(xm %*% Bm); pr <- pr / rowSums(pr)
ym <- apply(pr, 1, function(q) sample(K, 1, prob = q))
mm <- 10
xm[1:mm, 1:2] <- xm[1:mm, 1:2] + 5 # far out in the predictors of class 1 ...
ym[1:mm] <- 3 # ... but labeled as class 3
fit <- enetLTS(x, y)
fitb <- enetLTS(xb, yb, family = "binomial")
fitm <- enetLTS(xm, ym, family = "multinomial")
which(weights(fit)$wt == 0)
which(weights(fitb)$wt == 0)
w <- weights(fitm, vers = "both")
table(raw = w$raw.wt, reweighted = w$wt)