residuals.pense_cvfit {pense} | R Documentation |
Extract Residuals
Description
Extract residuals from a PENSE (or LS-EN) regularization path with hyper-parameters chosen by cross-validation.
Usage
## S3 method for class 'pense_cvfit'
residuals(
object,
alpha = NULL,
lambda = "min",
se_mult = 1,
exact = deprecated(),
correction = deprecated(),
...
)
Arguments
object |
PENSE with cross-validated hyper-parameters to extract coefficients from. |
alpha |
Either a single number or |
lambda |
either a string specifying which penalty level to use
( |
se_mult |
If |
exact |
deprecated. Always gives a warning if |
correction |
defunct. |
... |
currently not used. |
Value
a numeric vector of residuals for the given penalization level.
Hyper-parameters
If lambda = "{m}-se"
and object
contains fitted estimates for every penalization
level in the sequence, use the fit the most parsimonious model with prediction performance
statistically indistinguishable from the best model.
This is determined to be the model with prediction performance within m * cv_se
from the best model.
If lambda = "se"
, the multiplier m is taken from se_mult
.
By default all alpha hyper-parameters available in the fitted object are considered.
This can be overridden by supplying one or multiple values in parameter alpha
.
For example, if lambda = "1-se"
and alpha
contains two values, the "1-SE" rule is applied
individually for each alpha
value, and the fit with the better prediction error is considered.
In case lambda
is a number and object
was fit for several alpha hyper-parameters,
alpha
must also be given, or the first value in object$alpha
is used with a warning.
See Also
Other functions for extracting components:
coef.pense_cvfit()
,
coef.pense_fit()
,
predict.pense_cvfit()
,
predict.pense_fit()
,
residuals.pense_fit()
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")