residuals.pense_fit {pense} | R Documentation |
Extract Residuals
Description
Extract residuals from a PENSE (or LS-EN) regularization path fitted by
pense()
, regmest()
or elnet()
.
Usage
## S3 method for class 'pense_fit'
residuals(
object,
alpha = NULL,
lambda,
exact = deprecated(),
correction = deprecated(),
...
)
Arguments
object |
PENSE regularization path to extract residuals from. |
alpha |
Either a single number or |
lambda |
a single number for the penalty level. |
exact |
defunct Always gives a warning if |
correction |
defunct. |
... |
currently not used. |
Value
a numeric vector of residuals for the given penalization level.
See Also
Other functions for extracting components:
coef.pense_cvfit()
,
coef.pense_fit()
,
predict.pense_cvfit()
,
predict.pense_fit()
,
residuals.pense_cvfit()
Examples
# 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")