Learn R Programming

pense (version 2.2.2)

residuals.pense_fit: Extract Residuals

Description

Extract residuals from a PENSE (or LS-EN) regularization path fitted by pense(), regmest() or elnet().

Usage

# S3 method for pense_fit
residuals(
  object,
  alpha = NULL,
  lambda,
  exact = deprecated(),
  correction = deprecated(),
  ...
)

Value

a numeric vector of residuals for the given penalization level.

Arguments

object

PENSE regularization path to extract residuals from.

alpha

Either a single number or NULL (default). If given, only fits with the given alpha value are considered. If object was fit with multiple alpha values, and no value is provided, the first value in object$alpha is used with a warning.

lambda

a single number for the penalty level.

exact

defunct Always gives a warning if lambda is not part of the fitted sequence and coefficients need to be interpolated.

correction

defunct.

...

currently not used.

See Also

Other functions for extracting components: coef.pense_cvfit(), coef.pense_fit(), predict.pense_cvfit(), predict.pense_fit(), residuals.pense_cvfit()

Examples

Run this code
# Compute the LS-EN regularization path for Freeny's revenue data
# (see ?freeny)
data(freeny)
x <- as.matrix(freeny[ , 2:5])

regpath <- elnet(x, freeny$y, alpha = 0.75)

# Predict the response using a specific penalization level
predict(regpath, newdata = freeny[1:5, 2:5],
        lambda = regpath$lambda[[1]][[10]])

# Extract the residuals at a certain penalization level
residuals(regpath, lambda = regpath$lambda[[1]][[5]])

# Select penalization level via cross-validation
set.seed(123)
cv_results <- elnet_cv(x, freeny$y, alpha = 0.5,
                       cv_repl = 10, cv_k = 4)

# Predict the response using the "best" penalization level
predict(cv_results, newdata = freeny[1:5, 2:5])

# Extract the residuals at the "best" penalization level
residuals(cv_results)
# Extract the residuals at a more parsimonious penalization level
residuals(cv_results, lambda = "1.5-se")

Run the code above in your browser using DataLab