Learn R Programming

robustHD (version 0.3.0)

coefPlot: Coefficient plot of a sequence of regression models

Description

Produce a plot of the coefficients from a sequence of regression models, such as submodels along a robust least angle regression sequence, or sparse least trimmed squares regression models for a grid of values for the penalty parameter.

Usage

coefPlot(x, ...)

  ## S3 method for class 'seqModel':
coefPlot(x,
    abscissa = c("step", "df"), zeros = FALSE,
    size = c(0.5, 2, 4), labels, offset = 1, ...)

  ## S3 method for class 'sparseLTS':
coefPlot(x,
    fit = c("reweighted", "raw", "both"),
    abscissa = c("step", "df"), zeros = FALSE,
    size = c(0.5, 2, 4), labels, offset = 1, ...)

Arguments

x
the model fit to be plotted.
fit
a character string specifying for which estimator to produce the plot. Possible values are "reweighted" (the default) for the reweighted fits, "raw" for the raw fits, or "both" for both estimators.
abscissa
a character string specifying what to plot on the $x$-axis. Possible values are "step" for the step number (the default), or "df" for the degrees of freedom.
zeros
a logical indicating whether predictors that never enter the model and thus have zero coefficients should be included in the plot (TRUE) or omitted (FALSE, the default). This is useful if the number of predictors is
size
a numeric vector of length three giving the line width, the point size and the label size, respectively.
labels
an optional character vector containing labels for the predictors. Plotting labels can be suppressed by setting this to NULL.
offset
an integer giving the offset of the labels from the corresponding coefficient values from the last step (i.e., the number of blank characters to be prepended to the label).
...
for the generic function, additional arguments to be passed down to methods. For the "seqModel" and "sparseLTS" methods, additional arguments to be passed down to geom_l

Value

  • An object of class "ggplot" (see ggplot).

See Also

ggplot, rlars, sparseLTS

Examples

Run this code
## generate data
# example is not high-dimensional to keep computation time low
library("mvtnorm")
set.seed(1234)  # for reproducibility
n <- 100  # number of observations
p <- 25   # number of variables
beta <- rep.int(c(1, 0), c(5, p-5))  # coefficients
sigma <- 0.5      # controls signal-to-noise ratio
epsilon <- 0.1    # contamination level
Sigma <- 0.5^t(sapply(1:p, function(i, j) abs(i-j), 1:p))
x <- rmvnorm(n, sigma=Sigma)    # predictor matrix
e <- rnorm(n)                   # error terms
i <- 1:ceiling(epsilon*n)       # observations to be contaminated
e[i] <- e[i] + 5                # vertical outliers
y <- c(x %*% beta + sigma * e)  # response
x[i,] <- x[i,] + 5              # bad leverage points


## robust LARS
# fit model
fitRlars <- rlars(x, y, sMax = 10)
# create plot
coefPlot(fitRlars)


## sparse LTS over a grid of values for lambda
# fit model
frac <- seq(0.2, 0.05, by = -0.05)
fitSparseLTS <- sparseLTS(x, y, lambda = frac, mode = "fraction")
# create plot
coefPlot(fitSparseLTS)
coefPlot(fitSparseLTS, fit = "both")

Run the code above in your browser using DataLab