View source: R/plotCoef.enetLTS.R
| plotCoef.enetLTS | R Documentation |
"enetLTS" fitNeedle plot of the estimated slopes against the predictor index.
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 <fatmasevinckurnaz@gmail.com>
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.