View source: R/residuals-methods.R
residuals.pense_fit | R Documentation |
Extract residuals from a PENSE (or LS-EN) regularization path fitted by
pense()
, regmest()
or elnet()
.
## S3 method for class 'pense_fit' residuals( object, alpha = NULL, lambda, exact = deprecated(), correction = deprecated(), ... )
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. |
a numeric vector of residuals for the given penalization level.
Other functions for extracting components:
coef.pense_cvfit()
,
coef.pense_fit()
,
predict.pense_cvfit()
,
predict.pense_fit()
,
residuals.pense_cvfit()
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.