| Title: | Robust and Sparse Methods for High Dimensional Linear, Binary and Multinomial Regression |
|---|---|
| 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>. |
| Authors: | Fatma Sevinc Kurnaz [aut, cre], Irene Hoffmann [aut], Peter Filzmoser [aut] |
| Maintainer: | Fatma Sevinc Kurnaz <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.2.0 |
| Built: | 2026-11-22 01:11:33 UTC |
| Source: | https://github.com/cran/enetLTS |
"enetLTS" fit on test dataPerformance measures, confusion matrix and ROC curve of a fitted
"enetLTS" object on (new) data.
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, ...)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, ...)
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. |
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).
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.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
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
enetLTS, predict.enetLTS, outliers.enetLTS
## 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)## 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)
Simulated data for family = "binomial" with observations and
predictors (), following the simulation design of
Kurnaz, Hoffmann and Filzmoser (2018).
data("BinomialExample")data("BinomialExample")
A list with components
xtraining predictors, a matrix.
ytraining response, a 0/1 vector of length 100.
outliersindices of the contaminated training observations (1, 3, 7, 13).
xtest, ytest
clean test data with 200 observations.
betathe true slope vector (the true intercept is 1).
The first 20 predictors are informative () and correlated with
; the other 180 are uninformative and correlated with
. The response is if with
, and otherwise. The first 10% of the observations of
class 0 (4 observations) are contaminated: their informative predictors are drawn from 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.
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
data("BinomialExample") table(BinomialExample$y) BinomialExample$outliersdata("BinomialExample") table(BinomialExample$y) BinomialExample$outliers
"enetLTS" fitExtracts the estimated coefficients of the reweighted or the raw fit.
## S3 method for class 'enetLTS' coef(object, vers = c("reweighted", "raw"), zeros = TRUE, ...)## S3 method for class 'enetLTS' coef(object, vers = c("reweighted", "raw"), zeros = TRUE, ...)
object |
a fitted object of class |
vers |
a character string: |
zeros |
logical; if |
... |
not used. |
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.
In versions before 1.2.0, zeros = FALSE returned the indices of the nonzero
coefficients; these are now given by nonzeroCoef.enetLTS.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, predict.enetLTS,
nonzeroCoef.enetLTS, print.enetLTS
## 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)## 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)
gridRepeated -fold cross-validation over a grid of and
values, as used inside enetLTS. Returns the selected
pair and, optionally, draws a heat map of the criterion.
cv.enetLTS(index = NULL, family = c("gaussian", "binomial", "multinomial"), xx, yy, alphas, lambdas, nfold = 5, repl = 1, ncores = NA, plot = TRUE)cv.enetLTS(index = NULL, family = c("gaussian", "binomial", "multinomial"), xx, yy, alphas, lambdas, nfold = 5, repl = 1, ncores = NA, plot = TRUE)
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 |
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.
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 |
This function is called by enetLTS; it is exported so that the
tuning parameters can also be chosen for a given set of subsets.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
data("GaussianExample") cv <- cv.enetLTS(family = "gaussian", xx = GaussianExample$x, yy = GaussianExample$y, alphas = c(0.5, 1), ncores = 1) cv[c("alphaopt", "lambdaopt")]data("GaussianExample") cv <- cv.enetLTS(family = "gaussian", xx = GaussianExample$x, yy = GaussianExample$y, alphas = c(0.5, 1), ncores = 1) cv[c("alphaopt", "lambdaopt")]
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 observations on which the classical elastic net
is fitted, and a reweighting step improves its efficiency.
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)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)
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 |
The estimator applies the classical elastic net (glmnet) to subsets of the
data only. For one pair the search starts from
nsamp[1] elemental subsets and improves them by C-steps; the C-steps keep the
observations with the smallest squared residuals ("gaussian") or
negative log-likelihood contributions ("binomial", within each class). For
"multinomial" they keep, within each class , the
hsize 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 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.
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. |
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
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.
print.enetLTS, coef.enetLTS,
predict.enetLTS, outliers.enetLTS,
assess.enetLTS, plot.enetLTS,
cv.enetLTS, GaussianExample,
BinomialExample, MultinomialExample
## 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## 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
"enetLTS" fitFitted values of the reweighted and/or the raw fit for all observations of xx.
## S3 method for class 'enetLTS' fitted(object, vers = c("reweighted", "raw", "both"), type = c("response", "class"), ...)## S3 method for class 'enetLTS' fitted(object, vers = c("reweighted", "raw", "both"), type = c("response", "class"), ...)
object |
a fitted object of class |
vers |
a character string: |
type |
|
... |
not used. |
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").
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, predict.enetLTS, residuals.enetLTS
## 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)## 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)
Simulated data for family = "gaussian" with observations and
predictors (), following the simulation design of
Kurnaz, Hoffmann and Filzmoser (2018).
data("GaussianExample")data("GaussianExample")
A list with components
xtraining predictors, a matrix.
ytraining response, a numeric vector of length 100.
outliersindices of the contaminated training observations (1 to 10).
xtest, ytest
clean test data with 200 observations.
betathe true slope vector (the true intercept is 1).
The predictors form three independent blocks: two informative blocks of 10 predictors each with
, and 180 uninformative predictors with
. The response is with
, for the 20 informative predictors and 0 otherwise.
The first 10 observations are contaminated: their informative predictors are drawn from
and their errors from , where 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.
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
data("GaussianExample") dim(GaussianExample$x) GaussianExample$outliersdata("GaussianExample") dim(GaussianExample$x) GaussianExample$outliers
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".
lambda00(x, y, normalize = TRUE, intercept = TRUE, const = 2, prob = 0.95, tol = .Machine$double.eps^0.5, eps = .Machine$double.eps, ...)lambda00(x, y, normalize = TRUE, intercept = TRUE, const = 2, prob = 0.95, tol = .Machine$double.eps^0.5, eps = .Machine$double.eps, ...)
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 |
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).
A single positive number.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
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.
data("BinomialExample") lambda00(BinomialExample$x, BinomialExample$y)data("BinomialExample") lambda00(BinomialExample$x, BinomialExample$y)
Simulated data for family = "multinomial" with observations,
predictors () and classes.
data("MultinomialExample")data("MultinomialExample")
A list with components
xtraining predictors, a matrix.
ytraining response, a factor with levels 1, 2, 3.
outliersindices of the contaminated training observations (1 to 15).
xtest, ytest
clean test data with 300 observations.
betathe true matrix of slopes (the true intercepts are 0).
The predictors are independent standard normal. Each class is driven by its own predictors:
(class 1), (class 2),
(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.
data("MultinomialExample") table(MultinomialExample$y)data("MultinomialExample") table(MultinomialExample$y)
"enetLTS" fitReturns the positions of the nonzero coefficients of the reweighted or the raw fit.
nonzeroCoef.enetLTS(object, vers = c("reweighted", "raw"))nonzeroCoef.enetLTS(object, vers = c("reweighted", "raw"))
object |
a fitted object of class |
vers |
a character string: |
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
has position .
For family = "multinomial", a list with one such vector per class (a data
frame if all classes have the same number of nonzero coefficients).
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, coef.enetLTS, predict.enetLTS
## 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)## 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)
"enetLTS" fitReturns, 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.
outliers.enetLTS(object, vers = c("reweighted", "raw")) ## S3 method for class 'outliers.enetLTS' print(x, ...)outliers.enetLTS(object, vers = c("reweighted", "raw")) ## S3 method for class 'outliers.enetLTS' print(x, ...)
object |
a fitted object of class |
vers |
|
x |
an object of class |
... |
not used. |
A data frame of class "outliers.enetLTS" with one row per observation and
the columns index, flagged, loss (absolute residual for
"gaussian", 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".
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, weights.enetLTS, plotResid.enetLTS
## 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)## 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)
"enetLTS" fitDraws the coefficient, residual and diagnostic plots of a fitted "enetLTS" object.
## S3 method for class 'enetLTS' plot(x, method = c("coefficients", "resid", "diagnostic"), vers = c("reweighted", "raw"), ...)## S3 method for class 'enetLTS' plot(x, method = c("coefficients", "resid", "diagnostic"), vers = c("reweighted", "raw"), ...)
x |
a fitted object of class |
method |
the plot to draw: |
vers |
a character string: |
... |
further arguments passed to the plot function, for example |
The object x, invisibly. The plots are drawn as a side effect.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, plotCoef.enetLTS,
plotResid.enetLTS, plotDiagnostic.enetLTS
## 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")## 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")
"enetLTS" fitNeedle plot of the estimated slopes against the predictor index.
plotCoef.enetLTS(object, vers = c("reweighted", "raw"), colors = NULL, ...)plotCoef.enetLTS(object, vers = c("reweighted", "raw"), colors = NULL, ...)
object |
a fitted object of class |
vers |
a character string: |
colors |
not used; kept for compatibility with earlier versions. |
... |
not used. |
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.
The "ggplot" object, invisibly; the plot is drawn as a side effect.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, coef.enetLTS, plot.enetLTS
## 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)## 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)
"enetLTS" fitPlots the response against the linear predictor (gaussian, binomial) or the first two principal components of the linear predictors (multinomial).
plotDiagnostic.enetLTS(object, vers = c("reweighted", "raw"), zoom = TRUE, ...)plotDiagnostic.enetLTS(object, vers = c("reweighted", "raw"), zoom = TRUE, ...)
object |
a fitted object of class |
vers |
a character string: |
zoom |
logical; if |
... |
not used. |
For family = "gaussian" the plot shows against
with the line . For
family = "binomial" it shows the 0/1 response against
with the fitted logistic curve. For family = "multinomial" it shows the
scores of the first two principal components of the 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.
The "ggplot" object, invisibly; the plot is drawn as a side effect.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, plotResid.enetLTS, outliers.enetLTS
## 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)## 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)
"enetLTS" fitPlots the residuals of the reweighted or the raw fit against the observation index and, for the gaussian and binomial families, against the linear predictor.
plotResid.enetLTS(object, vers = c("reweighted", "raw"), zoom = TRUE, ...)plotResid.enetLTS(object, vers = c("reweighted", "raw"), zoom = TRUE, ...)
object |
a fitted object of class |
vers |
a character string: |
zoom |
logical; if |
... |
not used. |
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 qnorm(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.
A list of the drawn "ggplot" objects (two for the gaussian and binomial
families, one for the multinomial family), invisibly.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, residuals.enetLTS,
plotDiagnostic.enetLTS, outliers.enetLTS
## 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)## 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)
"enetLTS" fitLinear predictors, fitted values or probabilities, class labels, coefficients or the
indices of the nonzero coefficients from a fitted "enetLTS" object.
## S3 method for class 'enetLTS' predict(object, newX, vers = c("reweighted", "raw"), type = c("link", "response", "coefficients", "nonzero", "class"), ...)## S3 method for class 'enetLTS' predict(object, newX, vers = c("reweighted", "raw"), type = c("link", "response", "coefficients", "nonzero", "class"), ...)
object |
a fitted object of class |
newX |
a numeric matrix (or an object that |
vers |
a character string: |
type |
|
... |
not used. |
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.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, coef.enetLTS, fitted.enetLTS,
assess.enetLTS
## 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]## 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]
"enetLTS" fitPrints a short summary of a fitted "enetLTS" object.
## S3 method for class 'enetLTS' print(x, vers = c("reweighted", "raw"), digits = max(3, getOption("digits") - 3), maxprint = 20, ...)## S3 method for class 'enetLTS' print(x, vers = c("reweighted", "raw"), digits = max(3, getOption("digits") - 3), maxprint = 20, ...)
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. |
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.
The object x, invisibly.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, coef.enetLTS, outliers.enetLTS
## 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## 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
"enetLTS" fitResiduals of the reweighted and/or the raw fit for all observations of xx.
## S3 method for class 'enetLTS' residuals(object, vers = c("reweighted", "raw", "both"), ...)## S3 method for class 'enetLTS' residuals(object, vers = c("reweighted", "raw", "both"), ...)
object |
a fitted object of class |
vers |
a character string: |
... |
not used. |
For family = "gaussian" the residuals are .
For family = "binomial" and "multinomial" they are the negative
log-likelihood contributions of the observations,
and ,
respectively ( is the linear predictor and the
fitted probability of the observed class).
A list with the component residuals (vers = "reweighted"),
raw.residuals (vers = "raw") or both (vers = "both"); each is
a numeric vector.
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
enetLTS, fitted.enetLTS, plotResid.enetLTS,
outliers.enetLTS
## 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)## 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)
"enetLTS" fitExtracts the 0/1 weights that mark the outliers of the reweighted and/or the raw fit.
## S3 method for class 'enetLTS' weights(object, vers = c("reweighted", "raw", "both"), index = FALSE, ...)## S3 method for class 'enetLTS' weights(object, vers = c("reweighted", "raw", "both"), index = FALSE, ...)
object |
a fitted object of class |
vers |
a character string: |
index |
logical; if |
... |
not used. |
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:
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.
Pearson residuals larger than qnorm(1 - del) in absolute
value get weight 0.
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 (see crossfit in enetLTS); with
crossfit = FALSE it 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 by screen = TRUE
have weight 0 in both vectors.
A list with the component wt (vers = "reweighted"), raw.wt
(vers = "raw") or both (vers = "both"); each is an integer vector of
length .
Fatma Sevinc Kurnaz, Irene Hoffmann, Peter Filzmoser
Maintainer: Fatma Sevinc Kurnaz <[email protected]>
## 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)## 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)