| Title: | Penalized Elastic Net S/MM-Estimator of Regression |
|---|---|
| Description: | Robust penalized (adaptive) elastic net S and M estimators for linear regression. The adaptive methods are proposed in Kepplinger, D. (2023) <doi:10.1016/j.csda.2023.107730> and the non-adaptive methods in Cohen Freue, G. V., Kepplinger, D., Salibián-Barrera, M., and Smucler, E. (2019) <doi:10.1214/19-AOAS1269>. The package implements robust hyper-parameter selection with robust information sharing cross-validation according to Kepplinger & Wei (2025) <doi:10.1080/00401706.2025.2540970>. |
| Authors: | David Kepplinger [aut, cre], Matías Salibián-Barrera [aut], Gabriela Cohen Freue [aut] |
| Maintainer: | David Kepplinger <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.5.2 |
| Built: | 2026-05-27 07:19:02 UTC |
| Source: | https://github.com/dakep/pense-rpkg |
Set options for the CD algorithm to compute adaptive EN S-estimates.
cd_algorithm_options( max_it = 1000, reset_it = 8, linesearch_steps = 4, linesearch_mult = 0.5 )cd_algorithm_options( max_it = 1000, reset_it = 8, linesearch_steps = 4, linesearch_mult = 0.5 )
max_it |
maximum number of iterations. |
reset_it |
number of iterations after which the residuals are re-computed from scratch, to prevent numerical drifts from incremental updates. |
linesearch_steps |
maximum number of steps used for line search. |
linesearch_mult |
multiplier to adjust the step size in the line search. |
options for the CD algorithm to compute (adaptive) PENSE estimates.
mm_algorithm_options to optimize the non-convex PENSE objective function via a sequence of convex problems.
Other Robust EN algorithms:
mm_algorithm_options()
For cross-validated fits using the RIS-CV strategy, the measure of prediction accuracy can be adjusted post-hoc.
change_cv_measure( x, measure = c("wrmspe", "wmape", "tau_size", "wrmspe_cv", "wmape_cv"), max_solutions = Inf )change_cv_measure( x, measure = c("wrmspe", "wmape", "tau_size", "wrmspe_cv", "wmape_cv"), max_solutions = Inf )
x |
fitted (adaptive) PENSE or M-estimator |
measure |
the measure to use for prediction accuracy |
max_solutions |
consider only this many of the best solutions. If missing, all solutions are considered. |
a pense.cvfit object using the updated measure of prediction accuracy
Other functions to compute robust estimates with CV:
pense_cv(),
regmest_cv()
Extract coefficients from an adaptive PENSE (or LS-EN) regularization path with hyper-parameters chosen by cross-validation.
## S3 method for class 'pense_cvfit' coef( object, alpha = NULL, lambda = "min", se_mult = 1, sparse = NULL, standardized = FALSE, ... )## S3 method for class 'pense_cvfit' coef( object, alpha = NULL, lambda = "min", se_mult = 1, sparse = NULL, standardized = FALSE, ... )
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 |
sparse |
should coefficients be returned as sparse or dense vectors?
Defaults to the sparsity setting of the given |
standardized |
return the standardized coefficients. |
... |
currently not used. |
either a numeric vector or a sparse vector of type
dsparseVector
of size , depending on the sparse argument.
Note: prior to version 2.0.0 sparse coefficients were returned as sparse matrix of
type dgCMatrix.
To get a sparse matrix as in previous versions, use sparse = 'matrix'.
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.
Other functions for extracting components:
coef.pense_fit(),
predict.pense_cvfit(),
predict.pense_fit(),
residuals.pense_cvfit(),
residuals.pense_fit()
# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')
Extract coefficients from an adaptive PENSE (or LS-EN) regularization path fitted by pense()
or elnet().
## S3 method for class 'pense_fit' coef(object, lambda, alpha = NULL, sparse = NULL, standardized = FALSE, ...)## S3 method for class 'pense_fit' coef(object, lambda, alpha = NULL, sparse = NULL, standardized = FALSE, ...)
object |
PENSE regularization path to extract coefficients from. |
lambda |
a single number for the penalty level. |
alpha |
Either a single number or |
sparse |
should coefficients be returned as sparse or dense vectors? Defaults to the
sparsity setting in |
standardized |
return the standardized coefficients. |
... |
currently not used. |
either a numeric vector or a sparse vector of type
dsparseVector
of size , depending on the sparse argument.
Note: prior to version 2.0.0 sparse coefficients were returned as sparse matrix
of type dgCMatrix.
To get a sparse matrix as in previous versions, use sparse = 'matrix'.
coef.pense_cvfit() for extracting coefficients from a PENSE fit with
hyper-parameters chosen by cross-validation
Other functions for extracting components:
coef.pense_cvfit(),
predict.pense_cvfit(),
predict.pense_fit(),
residuals.pense_cvfit(),
residuals.pense_fit()
# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')
Returns the tuning constants required to achieve the desired breakdown point or efficiency under the Normal model.
consistency_const(delta, rho, eps = sqrt(.Machine$double.eps)) efficiency_const(eff, rho, eps = sqrt(.Machine$double.eps))consistency_const(delta, rho, eps = sqrt(.Machine$double.eps)) efficiency_const(eff, rho, eps = sqrt(.Machine$double.eps))
delta |
desired breakdown point (between 0 and 0.5) |
rho |
the name of the chosen |
eps |
numerical tolerance level for equality comparisons |
eff |
desired asymptotic efficiency (between 0.1 and 0.99). |
consistency constant
Other Robustness control options:
mscale_algorithm_options(),
rho_function()
Other Robustness control options:
mscale_algorithm_options(),
rho_function()
Compute least squares EN estimates for linear regression with optional observation weights and penalty loadings.
elnet( x, y, alpha, nlambda = 100, lambda_min_ratio, lambda, penalty_loadings, weights, intercept = TRUE, en_algorithm_opts, sparse = FALSE, eps = 1e-06, standardize = TRUE )elnet( x, y, alpha, nlambda = 100, lambda_min_ratio, lambda, penalty_loadings, weights, intercept = TRUE, en_algorithm_opts, sparse = FALSE, eps = 1e-06, standardize = TRUE )
x |
|
y |
vector of response values of length |
alpha |
elastic net penalty mixing parameter with |
nlambda |
number of penalization levels. |
lambda_min_ratio |
Smallest value of the penalization level as a fraction of the largest
level (i.e., the smallest value for which all coefficients are zero).
The default depends on the sample size relative to the number of variables and |
lambda |
optional user-supplied sequence of penalization levels.
If given and not |
penalty_loadings |
a vector of positive penalty loadings (a.k.a. weights) for different penalization of each coefficient. |
weights |
a vector of positive observation weights. |
intercept |
include an intercept in the model. |
en_algorithm_opts |
options for the EN algorithm. See en_algorithm_options for details. |
sparse |
use sparse coefficient vectors. |
eps |
numerical tolerance. |
standardize |
standardize variables to have unit variance. Coefficients are always returned in original scale. |
The elastic net estimator for the linear regression model solves the optimization problem
with observation weights and penalty loadings .
a list-like object with the following items
alphathe sequence of alpha parameters.
lambdaa list of sequences of penalization levels, one per alpha parameter.
estimatesa list of estimates. Each estimate contains the following information:
interceptintercept estimate.
betabeta (slope) estimate.
lambdapenalization level at which the estimate is computed.
alphaalpha hyper-parameter at which the estimate is computed.
statuscodeif > 0 the algorithm experienced issues when
computing the estimate.
statusoptional status message from the algorithm.
callthe original call.
pense() for an S-estimate of regression with elastic net penalty.
coef.pense_fit() for extracting coefficient estimates.
plot.pense_fit() for plotting the regularization path.
Other functions for computing non-robust estimates:
elnet_cv()
# 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 = c(0.5, 0.75)) plot(regpath) plot(regpath, alpha = 0.75) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[5]], alpha = 0.75) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- elnet_cv(x, freeny$y, alpha = c(0.5, 0.75), cv_repl = 10, cv_k = 4, cv_measure = "tau") plot(cv_results, se_mult = 1.5) plot(cv_results, se_mult = 1.5, what = "coef.path") # Extract the coefficients at the penalization level with # smallest prediction error ... summary(cv_results) coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. summary(cv_results, lambda = "1.5-se") coef(cv_results, lambda = "1.5-se")# 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 = c(0.5, 0.75)) plot(regpath) plot(regpath, alpha = 0.75) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[5]], alpha = 0.75) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- elnet_cv(x, freeny$y, alpha = c(0.5, 0.75), cv_repl = 10, cv_k = 4, cv_measure = "tau") plot(cv_results, se_mult = 1.5) plot(cv_results, se_mult = 1.5, what = "coef.path") # Extract the coefficients at the penalization level with # smallest prediction error ... summary(cv_results) coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. summary(cv_results, lambda = "1.5-se") coef(cv_results, lambda = "1.5-se")
Perform (repeated) K-fold cross-validation for elnet().
elnet_cv( x, y, lambda, cv_k, cv_repl = 1, cv_type = "naive", cv_metric = c("rmspe", "tau_size", "mape", "auroc"), fit_all = TRUE, cl = NULL, ... )elnet_cv( x, y, lambda, cv_k, cv_repl = 1, cv_type = "naive", cv_metric = c("rmspe", "tau_size", "mape", "auroc"), fit_all = TRUE, cl = NULL, ... )
x |
|
y |
vector of response values of length |
lambda |
optional user-supplied sequence of penalization levels.
If given and not |
cv_k |
number of folds per cross-validation. |
cv_repl |
number of cross-validation replications. |
cv_type |
what kind of cross-validation should be performed:
robust information sharing ( |
cv_metric |
only for |
fit_all |
only for |
cl |
a parallel cluster. Can only be used in combination with
|
... |
Arguments passed on to
|
The built-in CV metrics are
"tau_size"-size of the prediction error, computed by
tau_size() (default).
"mape"Median absolute prediction error.
"rmspe"Root mean squared prediction error.
"auroc"Area under the receiver operator characteristic curve (actually 1 - AUROC). Only sensible for binary responses.
a list-like object with the same components as returned by elnet(),
plus the following:
cvresdata frame of average cross-validated performance.
elnet() for computing the LS-EN regularization path without cross-validation.
pense_cv() for cross-validation of S-estimates of regression with elastic net penalty.
coef.pense_cvfit() for extracting coefficient estimates.
plot.pense_cvfit() for plotting the CV performance or the regularization path.
Other functions for computing non-robust estimates:
elnet()
# 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 = c(0.5, 0.75)) plot(regpath) plot(regpath, alpha = 0.75) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[5]], alpha = 0.75) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- elnet_cv(x, freeny$y, alpha = c(0.5, 0.75), cv_repl = 10, cv_k = 4, cv_measure = "tau") plot(cv_results, se_mult = 1.5) plot(cv_results, se_mult = 1.5, what = "coef.path") # Extract the coefficients at the penalization level with # smallest prediction error ... summary(cv_results) coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. summary(cv_results, lambda = "1.5-se") coef(cv_results, lambda = "1.5-se")# 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 = c(0.5, 0.75)) plot(regpath) plot(regpath, alpha = 0.75) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[5]], alpha = 0.75) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- elnet_cv(x, freeny$y, alpha = c(0.5, 0.75), cv_repl = 10, cv_k = 4, cv_measure = "tau") plot(cv_results, se_mult = 1.5) plot(cv_results, se_mult = 1.5, what = "coef.path") # Extract the coefficients at the penalization level with # smallest prediction error ... summary(cv_results) coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. summary(cv_results, lambda = "1.5-se") coef(cv_results, lambda = "1.5-se")
Use the ADMM Elastic Net Algorithm
en_admm_options(max_it = 1000, step_size, acceleration = 1)en_admm_options(max_it = 1000, step_size, acceleration = 1)
max_it |
maximum number of iterations. |
step_size |
step size for the algorithm. |
acceleration |
acceleration factor for linearized ADMM. |
options for the ADMM EN algorithm.
Other LS-EN algorithm options:
en_algorithm_options,
en_cd_options(),
en_dal_options(),
en_lars_options()
The package supports different algorithms to compute the EN estimate
for weighted LS loss functions.
Each algorithm has certain characteristics that make it useful for some
problems.
To select a specific algorithm and adjust the options, use any of
the en_***_options functions.
en_lars_options(): Use the tuning-free LARS algorithm.
This computes exact (up to numerical errors) solutions to the EN-LS
problem.
It is not iterative and therefore can not benefit from approximate
solutions, but in turn guarantees that a solution will be found.
en_cd_options(): Use an iterative coordinate descent algorithm which
needs operations per iteration and converges sub-linearly.
en_admm_options(): Use an iterative ADMM-type algorithm which needs
operations per iteration and converges sub-linearly.
en_dal_options(): Use the iterative Dual Augmented Lagrangian (DAL)
method.
DAL needs operations per iteration, but converges
exponentially.
Other LS-EN algorithm options:
en_admm_options(),
en_cd_options(),
en_dal_options(),
en_lars_options()
Use Coordinate Descent to Solve Elastic Net Problems
en_cd_options(max_it = 1000, reset_it = 8)en_cd_options(max_it = 1000, reset_it = 8)
max_it |
maximum number of iterations. |
reset_it |
number of iterations after which the residuals are re-computed from scratch, to prevent numerical drifts from incremental updates. |
Other LS-EN algorithm options:
en_admm_options(),
en_algorithm_options,
en_dal_options(),
en_lars_options()
Use the DAL Elastic Net Algorithm
en_dal_options( max_it = 100, max_inner_it = 100, eta_multiplier = 2, eta_start_conservative = 0.01, eta_start_aggressive = 1, lambda_relchange_aggressive = 0.25 )en_dal_options( max_it = 100, max_inner_it = 100, eta_multiplier = 2, eta_start_conservative = 0.01, eta_start_aggressive = 1, lambda_relchange_aggressive = 0.25 )
max_it |
maximum number of (outer) iterations. |
max_inner_it |
maximum number of (inner) iterations in each outer iteration. |
eta_multiplier |
multiplier for the barrier parameter. In each iteration, the barrier must be more restrictive (i.e., the multiplier must be > 1). |
eta_start_conservative |
conservative initial barrier parameter. This is used if the previous penalty is undefined or too far away. |
eta_start_aggressive |
aggressive initial barrier parameter. This is used if the previous penalty is close. |
lambda_relchange_aggressive |
how close must the lambda parameter from the previous penalty term be to use an aggressive initial barrier parameter (i.e., what constitutes "too far"). |
options for the DAL EN algorithm.
Other LS-EN algorithm options:
en_admm_options(),
en_algorithm_options,
en_cd_options(),
en_lars_options()
Use the LARS Elastic Net Algorithm
en_lars_options()en_lars_options()
Other LS-EN algorithm options:
en_admm_options(),
en_algorithm_options,
en_cd_options(),
en_dal_options()
Compute initial estimates for the EN S-estimator using the EN-PY procedure.
enpy_initial_estimates( x, y, alpha, lambda, bdp = 0.25, cc, intercept = TRUE, penalty_loadings, enpy_opts = enpy_options(), mscale_opts = mscale_algorithm_options(), eps = 1e-06, sparse = FALSE, ncores = 1L )enpy_initial_estimates( x, y, alpha, lambda, bdp = 0.25, cc, intercept = TRUE, penalty_loadings, enpy_opts = enpy_options(), mscale_opts = mscale_algorithm_options(), eps = 1e-06, sparse = FALSE, ncores = 1L )
x |
|
y |
vector of response values of length |
alpha |
elastic net penalty mixing parameter with |
lambda |
a vector of positive values of penalization levels. |
bdp |
desired breakdown point of the estimator, between 0.05 and 0.5. The actual breakdown point may be slightly larger/smaller to avoid instabilities of the S-loss. |
cc |
cutoff value for the rho function. By default, chosen to yield a consistent estimate for the Normal distribution. |
intercept |
include an intercept in the model. |
penalty_loadings |
a vector of positive penalty loadings (a.k.a. weights) for different
penalization of each coefficient. Only allowed for |
enpy_opts |
options for the EN-PY algorithm, created with the |
mscale_opts |
options for the M-scale estimation. See |
eps |
numerical tolerance. |
sparse |
use sparse coefficient vectors. |
ncores |
number of CPU cores to use in parallel. By default, only one CPU core is used. Not supported on all platforms, in which case a warning is given. |
If these manually computed initial estimates are intended as starting points for pense(),
they are by default shared for all penalization levels.
To restrict the use of the initial estimates to the penalty level they were computed for, use
as_starting_point(..., specific = TRUE). See as_starting_point() for details.
Cohen Freue, G.V.; Kepplinger, D.; Salibián-Barrera, M.; Smucler, E. Robust elastic net estimators for variable selection and identification of proteomic biomarkers. Ann. Appl. Stat. 13 (2019), no. 4, 2065–2090 doi:10.1214/19-AOAS1269
Other functions for initial estimates:
enpy_options(),
prinsens(),
starting_point()
Additional control options for the elastic net Peña-Yohai procedure.
enpy_options( max_it = 10, keep_psc_proportion = 0.5, en_algorithm_opts, keep_residuals_measure = c("threshold", "proportion"), keep_residuals_proportion = 0.5, keep_residuals_threshold = 2, retain_best_factor = 2, retain_max = 500 )enpy_options( max_it = 10, keep_psc_proportion = 0.5, en_algorithm_opts, keep_residuals_measure = c("threshold", "proportion"), keep_residuals_proportion = 0.5, keep_residuals_threshold = 2, retain_best_factor = 2, retain_max = 500 )
max_it |
maximum number of EN-PY iterations. |
keep_psc_proportion |
how many observations should to keep based on the Principal Sensitivity Components. |
en_algorithm_opts |
options for the LS-EN algorithm. See en_algorithm_options for details. |
keep_residuals_measure |
how to determine what observations to keep, based on their residuals.
If |
keep_residuals_proportion |
proportion of observations to kept based on their residuals. |
keep_residuals_threshold |
only observations with (standardized) residuals less than this threshold are kept. |
retain_best_factor |
only keep candidates that are within this factor of the best candidate. If |
retain_max |
maximum number of candidates, i.e., only the best |
The EN-PY procedure for computing initial estimates iteratively cleans the data of observations with possibly outlying residual or high leverage. Least-squares elastic net (LS-EN) estimates are computed on the possibly clean subsets. At each iteration, the Principal Sensitivity Components are computed to remove observations with potentially high leverage. Among all the LS-EN estimates, the estimate with smallest M-scale of the residuals is selected. Observations with largest residual for the selected estimate are removed and the next iteration is started.
options for the ENPY algorithm.
Other functions for initial estimates:
enpy_initial_estimates(),
prinsens(),
starting_point()
Compute the M-estimate of location using an auxiliary estimate of the scale.
mloc(x, scale, rho = "bisquare", eff = 0.9, cc, max_it = 200, eps = 1e-08)mloc(x, scale, rho = "bisquare", eff = 0.9, cc, max_it = 200, eps = 1e-08)
x |
numeric values. Missing values are verbosely ignored. |
scale |
scale of the |
rho |
the |
eff |
desired efficiency under the Normal model. |
cc |
value of the tuning constant for the chosen |
max_it |
maximum number of iterations. |
eps |
numerical tolerance to check for convergence. |
a single numeric value, the M-estimate of location.
Other functions to compute robust estimates of location and scale:
mlocscale(),
mscale(),
tau_size()
Simultaneous estimation of the location and scale by means of M-estimates.
mlocscale( x, bdp = 0.25, eff = 0.9, scale_cc, location_rho, location_cc, opts = mscale_algorithm_options() )mlocscale( x, bdp = 0.25, eff = 0.9, scale_cc, location_rho, location_cc, opts = mscale_algorithm_options() )
x |
numeric values. Missing values are verbosely ignored. |
bdp |
desired breakdown point (between 0 and 0.5). |
eff |
desired efficiency of the location estimate (between 0.1 and 0.99). |
scale_cc |
tuning constant for the |
location_rho |
|
location_cc |
tuning constant for the location |
opts |
a list of options for the M-scale estimating equations,
See |
a vector with 2 elements, the M-estimate of location and the M-scale estimate.
Other functions to compute robust estimates of location and scale:
mloc(),
mscale(),
tau_size()
Additional options for the MM algorithm to compute EN S- and M-estimates.
mm_algorithm_options( max_it = 500, tightening = c("adaptive", "exponential", "none"), tightening_steps = 2, en_algorithm_opts )mm_algorithm_options( max_it = 500, tightening = c("adaptive", "exponential", "none"), tightening_steps = 2, en_algorithm_opts )
max_it |
maximum number of iterations. |
tightening |
how to make inner iterations more precise as the algorithm approaches a local minimum. |
tightening_steps |
for adaptive tightening strategy, how often to tighten until the desired tolerance is attained. |
en_algorithm_opts |
options for the inner LS-EN algorithm. See en_algorithm_options for details. |
options for the MM algorithm.
cd_algorithm_options for a direct optimization of the non-convex PENSE loss.
Other Robust EN algorithms:
cd_algorithm_options()
Compute the M-scale without centering the values.
mscale(x, bdp = 0.25, cc, opts = mscale_algorithm_options())mscale(x, bdp = 0.25, cc, opts = mscale_algorithm_options())
x |
numeric values. Missing values are verbosely ignored. |
bdp |
desired breakdown point (between 0 and 0.5). |
cc |
tuning parameters for the chosen rho function. By default, chosen to yield a consistent estimate for the Normal distribution. |
opts |
a list of options for the M-scale estimation algorithm,
see |
the M-estimate of scale.
Other functions to compute robust estimates of location and scale:
mloc(),
mlocscale(),
tau_size()
Options for the M-scale Estimation Algorithm
mscale_algorithm_options(rho = "bisquare", max_it = 200, eps = 1e-08)mscale_algorithm_options(rho = "bisquare", max_it = 200, eps = 1e-08)
rho |
the |
max_it |
maximum number of iterations. |
eps |
numerical tolerance to check for convergence. |
options for the M-scale estimation algorithm.
Other Robustness control options:
consistency_const(),
rho_function()
Compute elastic net S-estimates (PENSE estimates) along a grid of penalization levels with optional penalty loadings for adaptive elastic net.
pense( x, y, alpha, nlambda = 50, nlambda_enpy = 10, lambda, lambda_min_ratio, enpy_lambda, penalty_loadings, intercept = TRUE, bdp = 0.25, cc, add_zero_based = TRUE, enpy_specific = FALSE, other_starts, carry_forward = TRUE, eps = 1e-06, explore_solutions = 0, explore_tol = 0.1, explore_it = 5, max_solutions = 5, comparison_tol = sqrt(eps), sparse = FALSE, ncores = 1, standardize = TRUE, algorithm_opts = mm_algorithm_options(), mscale_opts = mscale_algorithm_options(), enpy_opts = enpy_options(), ... )pense( x, y, alpha, nlambda = 50, nlambda_enpy = 10, lambda, lambda_min_ratio, enpy_lambda, penalty_loadings, intercept = TRUE, bdp = 0.25, cc, add_zero_based = TRUE, enpy_specific = FALSE, other_starts, carry_forward = TRUE, eps = 1e-06, explore_solutions = 0, explore_tol = 0.1, explore_it = 5, max_solutions = 5, comparison_tol = sqrt(eps), sparse = FALSE, ncores = 1, standardize = TRUE, algorithm_opts = mm_algorithm_options(), mscale_opts = mscale_algorithm_options(), enpy_opts = enpy_options(), ... )
x |
|
y |
vector of response values of length |
alpha |
elastic net penalty mixing parameter with |
nlambda |
number of penalization levels. |
nlambda_enpy |
number of penalization levels where the EN-PY initial estimate is computed. |
lambda |
optional user-supplied sequence of penalization levels. If given and not |
lambda_min_ratio |
Smallest value of the penalization level as a fraction of the largest
level (i.e., the smallest value for which all coefficients are zero). The default depends on
the sample size relative to the number of variables and |
enpy_lambda |
optional user-supplied sequence of penalization levels at which EN-PY
initial estimates are computed. If given and not |
penalty_loadings |
a vector of positive penalty loadings (a.k.a. weights) for different
penalization of each coefficient. Only allowed for |
intercept |
include an intercept in the model. |
bdp |
desired breakdown point of the estimator, between 0.05 and 0.5. The actual breakdown point may be slightly larger/smaller to avoid instabilities of the S-loss. |
cc |
tuning constant for the S-estimator. Default is chosen based on the breakdown
point |
add_zero_based |
also consider the 0-based regularization path. See details for a description. |
enpy_specific |
use the EN-PY initial estimates only at the penalization level they are computed for. See details for a description. |
other_starts |
a list of other staring points, created by |
carry_forward |
carry the best solutions forward to the next penalty level. |
eps |
numerical tolerance. |
explore_solutions |
number of solutions to keep after the exploration step.
The best |
explore_tol, explore_it
|
numerical tolerance and maximum number of iterations for
exploring possible solutions. The tolerance should be (much) looser than |
max_solutions |
retain only up to |
comparison_tol |
numeric tolerance to determine if two solutions are equal.
The comparison is first done on the absolute difference in the value of the objective
function at the solution. If this is less than |
sparse |
use sparse coefficient vectors. |
ncores |
number of CPU cores to use in parallel. By default, only one CPU core is used. Not supported on all platforms, in which case a warning is given. |
standardize |
logical flag to standardize the |
algorithm_opts |
options for the MM algorithm to compute the estimates.
See |
mscale_opts |
options for the M-scale estimation. See |
enpy_opts |
options for the ENPY initial estimates, created with the
|
... |
ignored. |
a list-like object with the following items
alphathe sequence of alpha parameters.
lambdaa list of sequences of penalization levels, one per alpha parameter.
estimatesa list of estimates. Each estimate contains the following information:
interceptintercept estimate.
betabeta (slope) estimate.
lambdapenalization level at which the estimate is computed.
alphaalpha hyper-parameter at which the estimate is computed.
bdpchosen breakdown-point.
objf_valuevalue of the objective function at the solution.
statuscodeif > 0 the algorithm experienced issues when
computing the estimate.
statusoptional status message from the algorithm.
bdpthe actual breakdown point used.
callthe original call.
The function supports several different strategies to compute, and use the provided starting points for optimizing the PENSE objective function.
Starting points are computed internally but can also be supplied via other_starts.
By default, starting points are computed internally by the EN-PY procedure for penalization
levels supplied in enpy_lambda (or the automatically generated grid of length nlambda_enpy).
By default, starting points computed by the EN-PY procedure are shared for all penalization
levels in lambda (or the automatically generated grid of length nlambda).
If the starting points should be specific to the penalization level the starting points'
penalization level, set the enpy_specific argument to TRUE.
In addition to EN-PY initial estimates, the algorithm can also use the "0-based" strategy if
add_zero_based = TRUE (by default). Here, the 0-vector is used to start the optimization at
the largest penalization level in lambda. At subsequent penalization levels, the solution at
the previous penalization level is also used as starting point.
At every penalization level, all starting points are explored using the loose numerical
tolerance explore_tol. Only the best explore_solutions are computed to the stringent
numerical tolerance eps.
Finally, only the best max_solutions are retained and carried forward as starting points for
the subsequent penalization level.
pense_cv() for selecting hyper-parameters via cross-validation.
coef.pense_fit() for extracting coefficient estimates.
plot.pense_fit() for plotting the regularization path.
Other functions to compute robust estimates:
regmest()
# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')
Perform (repeated) K-fold cross-validation for pense().
adapense_cv() is a convenience wrapper to compute adaptive
PENSE estimates.
pense_cv( x, y, standardize = TRUE, lambda, cv_k, cv_repl = 1, cv_type = c("ris", "naive"), cv_metric = c("tau_size", "mape", "rmspe", "auroc"), ris_min_similarity = 0.5, fit_all = TRUE, fold_starts = c("full", "enpy", "both"), cv_algorithm_opts, cl = NULL, ... ) adapense_cv(x, y, alpha, alpha_preliminary = 0, exponent = 1, ...)pense_cv( x, y, standardize = TRUE, lambda, cv_k, cv_repl = 1, cv_type = c("ris", "naive"), cv_metric = c("tau_size", "mape", "rmspe", "auroc"), ris_min_similarity = 0.5, fit_all = TRUE, fold_starts = c("full", "enpy", "both"), cv_algorithm_opts, cl = NULL, ... ) adapense_cv(x, y, alpha, alpha_preliminary = 0, exponent = 1, ...)
x |
|
y |
vector of response values of length |
standardize |
whether to standardize the |
lambda |
optional user-supplied sequence of penalization levels. If given and not |
cv_k |
number of folds per cross-validation. |
cv_repl |
number of cross-validation replications. |
cv_type |
what kind of cross-validation should be performed:
robust information sharing ( |
cv_metric |
only for |
ris_min_similarity |
minimum average similarity of the CV solutions to be considered (between 0 and 1). If no CV solution satisfies this lower bound, the best CV solution will be used regardless of similarity. |
fit_all |
only for |
fold_starts |
how to determine starting values in the
cross-validation folds. If |
cv_algorithm_opts |
Override algorithm options for the CV iterations. This is usually not necessary, unless the user wants to change the number of solutions retained for the CV training data. |
cl |
a parallel cluster. Can only be used in combination with
|
... |
Arguments passed on to
|
alpha |
elastic net penalty mixing parameter with |
alpha_preliminary |
|
exponent |
the exponent for computing the penalty loadings based on the preliminary estimate. |
The built-in CV metrics are
"tau_size"-size of the prediction error, computed by
tau_size() (default).
"mape"Median absolute prediction error.
"rmspe"Root mean squared prediction error.
"auroc"Area under the receiver operator characteristic curve (actually 1 - AUROC). Only sensible for binary responses.
adapense_cv() is a convenience wrapper which performs 3 steps:
compute preliminary estimates via
pense_cv(..., alpha = alpha_preliminary),
computes the penalty loadings from the estimate beta with best
prediction performance by
adapense_loadings = 1 / abs(beta)^exponent, and
compute the adaptive PENSE estimates via
pense_cv(..., penalty_loadings = adapense_loadings).
a list-like object with the same components as returned by pense(),
plus the following:
cvresdata frame of average cross-validated performance.
a list-like object as returned by pense_cv() plus the following
preliminarythe CV results for the preliminary estimate.
exponentexponent used to compute the penalty loadings.
penalty_loadingspenalty loadings used for the adaptive PENSE estimate.
pense() for computing regularized S-estimates without
cross-validation.
coef.pense_cvfit() for extracting coefficient estimates.
plot.pense_cvfit() for plotting the CV performance or the
regularization path.
Other functions to compute robust estimates with CV:
change_cv_measure(),
regmest_cv()
Other functions to compute robust estimates with CV:
change_cv_measure(),
regmest_cv()
# Compute the adaptive PENSE regularization path for Freeny's # revenue data (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) ## Either use the convenience function directly ... set.seed(123) ada_convenience <- adapense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) ## ... or compute the steps manually: # Step 1: Compute preliminary estimates with CV set.seed(123) preliminary_estimate <- pense_cv(x, freeny$y, alpha = 0, cv_repl = 2, cv_k = 4) plot(preliminary_estimate, se_mult = 1) # Step 2: Use the coefficients with best prediction performance # to define the penalty loadings: prelim_coefs <- coef(preliminary_estimate, lambda = 'min') pen_loadings <- 1 / abs(prelim_coefs[-1]) # Step 3: Compute the adaptive PENSE estimates and estimate # their prediction performance. set.seed(123) ada_manual <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4, penalty_loadings = pen_loadings) # Visualize the prediction performance and coefficient path of # the adaptive PENSE estimates (manual vs. automatic) def.par <- par(no.readonly = TRUE) layout(matrix(1:4, ncol = 2, byrow = TRUE)) plot(ada_convenience$preliminary) plot(preliminary_estimate) plot(ada_convenience) plot(ada_manual) par(def.par)# Compute the adaptive PENSE regularization path for Freeny's # revenue data (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) ## Either use the convenience function directly ... set.seed(123) ada_convenience <- adapense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) ## ... or compute the steps manually: # Step 1: Compute preliminary estimates with CV set.seed(123) preliminary_estimate <- pense_cv(x, freeny$y, alpha = 0, cv_repl = 2, cv_k = 4) plot(preliminary_estimate, se_mult = 1) # Step 2: Use the coefficients with best prediction performance # to define the penalty loadings: prelim_coefs <- coef(preliminary_estimate, lambda = 'min') pen_loadings <- 1 / abs(prelim_coefs[-1]) # Step 3: Compute the adaptive PENSE estimates and estimate # their prediction performance. set.seed(123) ada_manual <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4, penalty_loadings = pen_loadings) # Visualize the prediction performance and coefficient path of # the adaptive PENSE estimates (manual vs. automatic) def.par <- par(no.readonly = TRUE) layout(matrix(1:4, ncol = 2, byrow = TRUE)) plot(ada_convenience$preliminary) plot(preliminary_estimate) plot(ada_convenience) plot(ada_manual) par(def.par)
Plot the cross-validation performance or the coefficient path for fitted penalized elastic net S- or LS-estimates of regression.
## S3 method for class 'pense_cvfit' plot(x, what = c("cv", "coef.path"), alpha = NULL, se_mult = 1, ...)## S3 method for class 'pense_cvfit' plot(x, what = c("cv", "coef.path"), alpha = NULL, se_mult = 1, ...)
x |
fitted estimates with cross-validation information. |
what |
plot either the CV performance or the coefficient path. |
alpha |
If |
se_mult |
if plotting CV performance, multiplier of the estimated SE. |
... |
currently ignored. |
Other functions for plotting and printing:
plot.pense_fit(),
prediction_performance(),
summary.pense_cvfit()
# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')
Plot the coefficient path for fitted penalized elastic net S- or LS-estimates of regression.
## S3 method for class 'pense_fit' plot(x, alpha, ...)## S3 method for class 'pense_fit' plot(x, alpha, ...)
x |
fitted estimates. |
alpha |
Plot the coefficient path for the fit with the given hyper-parameter value.
If missing of |
... |
currently ignored. |
Other functions for plotting and printing:
plot.pense_cvfit(),
prediction_performance(),
summary.pense_cvfit()
# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- pense(x, freeny$y, alpha = 0.5) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, lambda = regpath$lambda[[1]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- pense_cv(x, freeny$y, alpha = 0.5, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')
Predict response values using a PENSE (or LS-EN) regularization path with hyper-parameters chosen by cross-validation.
## S3 method for class 'pense_cvfit' predict(object, newdata, alpha = NULL, lambda = "min", se_mult = 1, ...)## S3 method for class 'pense_cvfit' predict(object, newdata, alpha = NULL, lambda = "min", se_mult = 1, ...)
object |
PENSE with cross-validated hyper-parameters to extract coefficients from. |
newdata |
an optional matrix of new predictor values. If missing, the fitted values are computed. |
alpha |
Either a single number or |
lambda |
either a string specifying which penalty level to use
( |
se_mult |
If |
... |
currently not used. |
a numeric vector of residuals for the given penalization level.
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.
Other functions for extracting components:
coef.pense_cvfit(),
coef.pense_fit(),
predict.pense_fit(),
residuals.pense_cvfit(),
residuals.pense_fit()
# 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")# 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")
Predict response values using a PENSE (or LS-EN) regularization path fitted by
pense(), regmest() or elnet().
## S3 method for class 'pense_fit' predict(object, newdata, alpha = NULL, lambda, ...)## S3 method for class 'pense_fit' predict(object, newdata, alpha = NULL, lambda, ...)
object |
PENSE regularization path to extract residuals from. |
newdata |
an optional matrix of new predictor values. If missing, the fitted values are computed. |
alpha |
Either a single number or |
lambda |
a single number for the penalty level. |
... |
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(),
residuals.pense_cvfit(),
residuals.pense_fit()
# 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")# 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")
Extract the prediction performance of one or more (adaptive) PENSE fits.
prediction_performance(..., alpha = NULL, lambda = "min", se_mult = 1) ## S3 method for class 'pense_pred_perf' print(x, ...)prediction_performance(..., alpha = NULL, lambda = "min", se_mult = 1) ## S3 method for class 'pense_pred_perf' print(x, ...)
... |
one or more (adaptive) PENSE fits with cross-validation information. |
alpha |
Either a numeric vector or |
lambda |
either a string specifying which penalty level to use
( |
se_mult |
If |
x |
an object with information on prediction performance created with |
If lambda = "se" and the cross-validation was performed with multiple replications, use the penalty level whit
prediction performance within se_mult of the best prediction performance.
a data frame with details about the prediction performance of the given PENSE fits. The data frame has a custom print method summarizing the prediction performances.
summary.pense_cvfit() for a summary of the fitted model.
Other functions for plotting and printing:
plot.pense_cvfit(),
plot.pense_fit(),
summary.pense_cvfit()
Compute Principal Sensitivity Components for Elastic Net Regression
prinsens( x, y, alpha, lambda, intercept = TRUE, penalty_loadings, en_algorithm_opts, eps = 1e-06, sparse = FALSE, ncores = 1L )prinsens( x, y, alpha, lambda, intercept = TRUE, penalty_loadings, en_algorithm_opts, eps = 1e-06, sparse = FALSE, ncores = 1L )
x |
|
y |
vector of response values of length |
alpha |
elastic net penalty mixing parameter with |
lambda |
optional user-supplied sequence of penalization levels. If given and not |
intercept |
include an intercept in the model. |
penalty_loadings |
a vector of positive penalty loadings (a.k.a. weights) for different
penalization of each coefficient. Only allowed for |
en_algorithm_opts |
options for the LS-EN algorithm. See en_algorithm_options for details. |
eps |
numerical tolerance. |
sparse |
use sparse coefficient vectors. |
ncores |
number of CPU cores to use in parallel. By default, only one CPU core is used. Not supported on all platforms, in which case a warning is given. |
a list of principal sensitivity components, one per element in lambda. Each PSC is itself a list
with items lambda, alpha, and pscs.
Cohen Freue, G.V.; Kepplinger, D.; Salibián-Barrera, M.; Smucler, E. Robust elastic net estimators for variable selection and identification of proteomic biomarkers. Ann. Appl. Stat. 13 (2019), no. 4, 2065–2090 doi:10.1214/19-AOAS1269
Pena, D., and Yohai, V.J. A Fast Procedure for Outlier Diagnostics in Large Regression Problems. J. Amer. Statist. Assoc. 94 (1999). no. 446, 434–445. doi:10.2307/2670164
Other functions for initial estimates:
enpy_initial_estimates(),
enpy_options(),
starting_point()
Compute elastic net M-estimates along a grid of penalization levels with optional penalty loadings for adaptive elastic net.
regmest( x, y, alpha, nlambda = 50, lambda, lambda_min_ratio, scale, starting_points, penalty_loadings, intercept = TRUE, eff = 0.9, rho = "mopt", cc, eps = 1e-06, explore_solutions = 10, explore_tol = 0.1, max_solutions = 1, comparison_tol = sqrt(eps), sparse = FALSE, ncores = 1, standardize = TRUE, algorithm_opts = mm_algorithm_options(), add_zero_based = TRUE, mscale_bdp = 0.25, mscale_opts = mscale_algorithm_options() )regmest( x, y, alpha, nlambda = 50, lambda, lambda_min_ratio, scale, starting_points, penalty_loadings, intercept = TRUE, eff = 0.9, rho = "mopt", cc, eps = 1e-06, explore_solutions = 10, explore_tol = 0.1, max_solutions = 1, comparison_tol = sqrt(eps), sparse = FALSE, ncores = 1, standardize = TRUE, algorithm_opts = mm_algorithm_options(), add_zero_based = TRUE, mscale_bdp = 0.25, mscale_opts = mscale_algorithm_options() )
x |
|
y |
vector of response values of length |
alpha |
elastic net penalty mixing parameter with |
nlambda |
number of penalization levels. |
lambda |
optional user-supplied sequence of penalization levels.
If given and not |
lambda_min_ratio |
Smallest value of the penalization level as a fraction of the
largest level (i.e., the smallest value for which all coefficients are zero).
The default depends on the sample size relative to the number of variables and |
scale |
fixed scale of the residuals. |
starting_points |
a list of staring points, created by |
penalty_loadings |
a vector of positive penalty loadings (a.k.a. weights)
for different penalization of each coefficient. Only allowed for |
intercept |
include an intercept in the model. |
eff |
the desired asymptotic efficiency of the M-estimator under the Normal model. |
rho |
which |
cc |
manually specified cutoff constant for the chosen |
eps |
numerical tolerance. |
explore_solutions |
number of solutions to compute up to the desired precision |
explore_tol |
numerical tolerance for exploring possible solutions.
Should be (much) looser than |
max_solutions |
only retain up to |
comparison_tol |
numeric tolerance to determine if two solutions are equal.
The comparison is first done on the absolute difference in the value of the objective
function at the solution.
If this is less than |
sparse |
use sparse coefficient vectors. |
ncores |
number of CPU cores to use in parallel. By default, only one CPU core is used. Not supported on all platforms, in which case a warning is given. |
standardize |
logical flag to standardize the |
algorithm_opts |
options for the MM algorithm to compute estimates.
See |
add_zero_based |
also consider the 0-based regularization path in addition to the given starting points. |
mscale_bdp, mscale_opts
|
options for the M-scale estimate used to standardize
the predictors (if |
a list-like object with the following items
alphathe sequence of alpha parameters.
lambdaa list of sequences of penalization levels, one per alpha parameter.
scalethe used scale of the residuals.
estimatesa list of estimates. Each estimate contains the following information:
interceptintercept estimate.
betabeta (slope) estimate.
lambdapenalization level at which the estimate is computed.
alphaalpha hyper-parameter at which the estimate is computed.
objf_valuevalue of the objective function at the solution.
statuscodeif > 0 the algorithm experienced issues when
computing the estimate.
statusoptional status message from the algorithm.
callthe original call.
regmest_cv() for selecting hyper-parameters via cross-validation.
coef.pense_fit() for extracting coefficient estimates.
plot.pense_fit() for plotting the regularization path.
Other functions to compute robust estimates:
pense()
# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- regmest(x, freeny$y, alpha = c(0.5, 0.85), scale = 2) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, alpha = 0.85, lambda = regpath$lambda[[2]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- regmest_cv(x, freeny$y, alpha = c(0.5, 0.85), scale = 2, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- regmest(x, freeny$y, alpha = c(0.5, 0.85), scale = 2) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, alpha = 0.85, lambda = regpath$lambda[[2]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- regmest_cv(x, freeny$y, alpha = c(0.5, 0.85), scale = 2, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')
Perform (repeated) K-fold cross-validation for regmest().
adamest_cv() is a convenience wrapper to compute adaptive elastic-net M-estimates.
regmest_cv( x, y, standardize = TRUE, lambda, cv_k, cv_repl = 1, cv_type = "naive", cv_metric = c("tau_size", "mape", "rmspe", "auroc"), fit_all = TRUE, cl = NULL, ... ) adamest_cv(x, y, alpha, alpha_preliminary = 0, exponent = 1, ...)regmest_cv( x, y, standardize = TRUE, lambda, cv_k, cv_repl = 1, cv_type = "naive", cv_metric = c("tau_size", "mape", "rmspe", "auroc"), fit_all = TRUE, cl = NULL, ... ) adamest_cv(x, y, alpha, alpha_preliminary = 0, exponent = 1, ...)
x |
|
y |
vector of response values of length |
standardize |
whether to standardize the |
lambda |
optional user-supplied sequence of penalization levels.
If given and not |
cv_k |
number of folds per cross-validation. |
cv_repl |
number of cross-validation replications. |
cv_type |
what kind of cross-validation should be performed:
robust information sharing ( |
cv_metric |
only for |
fit_all |
only for |
cl |
a parallel cluster. Can only be used in combination with
|
... |
Arguments passed on to
|
alpha |
elastic net penalty mixing parameter with |
alpha_preliminary |
|
exponent |
the exponent for computing the penalty loadings based on the preliminary estimate. |
The built-in CV metrics are
"tau_size"-size of the prediction error, computed by
tau_size() (default).
"mape"Median absolute prediction error.
"rmspe"Root mean squared prediction error.
"auroc"Area under the receiver operator characteristic curve (actually 1 - AUROC). Only sensible for binary responses.
adamest_cv() is a convenience wrapper which performs 3 steps:
compute preliminary estimates via regmest_cv(..., alpha = alpha_preliminary),
computes the penalty loadings from the estimate beta with best prediction performance by
adamest_loadings = 1 / abs(beta)^exponent, and
compute the adaptive PENSE estimates via
regmest_cv(..., penalty_loadings = adamest_loadings).
a list-like object as returned by regmest(), plus the following components:
cvresdata frame of average cross-validated performance.
a list-like object as returned by adamest_cv() plus the following components:
exponentvalue of the exponent.
preliminaryCV results for the preliminary estimate.
penalty_loadingspenalty loadings used for the adaptive elastic net M-estimate.
regmest() for computing regularized S-estimates without cross-validation.
coef.pense_cvfit() for extracting coefficient estimates.
plot.pense_cvfit() for plotting the CV performance or the regularization path.
Other functions to compute robust estimates with CV:
change_cv_measure(),
pense_cv()
Other functions to compute robust estimates with CV:
change_cv_measure(),
pense_cv()
# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- regmest(x, freeny$y, alpha = c(0.5, 0.85), scale = 2) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, alpha = 0.85, lambda = regpath$lambda[[2]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- regmest_cv(x, freeny$y, alpha = c(0.5, 0.85), scale = 2, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')# Compute the PENSE regularization path for Freeny's revenue data # (see ?freeny) data(freeny) x <- as.matrix(freeny[ , 2:5]) regpath <- regmest(x, freeny$y, alpha = c(0.5, 0.85), scale = 2) plot(regpath) # Extract the coefficients at a certain penalization level coef(regpath, alpha = 0.85, lambda = regpath$lambda[[2]][[40]]) # What penalization level leads to good prediction performance? set.seed(123) cv_results <- regmest_cv(x, freeny$y, alpha = c(0.5, 0.85), scale = 2, cv_repl = 2, cv_k = 4) plot(cv_results, se_mult = 1) # Print a summary of the fit and the cross-validation results. summary(cv_results) # Extract the coefficients at the penalization level with # smallest prediction error ... coef(cv_results) # ... or at the penalization level with prediction error # statistically indistinguishable from the minimum. coef(cv_results, lambda = '1-se')
Extract residuals from a PENSE (or LS-EN) regularization path with hyper-parameters chosen by cross-validation.
## S3 method for class 'pense_cvfit' residuals(object, alpha = NULL, lambda = "min", se_mult = 1, ...)## S3 method for class 'pense_cvfit' residuals(object, alpha = NULL, lambda = "min", se_mult = 1, ...)
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 |
... |
currently not used. |
a numeric vector of residuals for the given penalization level.
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.
Other functions for extracting components:
coef.pense_cvfit(),
coef.pense_fit(),
predict.pense_cvfit(),
predict.pense_fit(),
residuals.pense_fit()
# 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")# 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")
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, ...)## S3 method for class 'pense_fit' residuals(object, alpha = NULL, lambda, ...)
object |
PENSE regularization path to extract residuals from. |
alpha |
Either a single number or |
lambda |
a single number for the penalty level. |
... |
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")# 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")
List Available Rho Functions
rho_function(rho, convex_ok = TRUE)rho_function(rho, convex_ok = TRUE)
rho |
the name of the |
convex_ok |
if convex |
if rho is missing returns a vector of supported function names, otherwise
the internal integer representation of the function.
Other Robustness control options:
consistency_const(),
mscale_algorithm_options()
Create a starting point for starting the PENSE algorithm in pense().
Multiple starting points can be created by combining starting points via
c(starting_point_1, starting_point_2, ...).
starting_point(beta, intercept, lambda, alpha) as_starting_point(object, specific = FALSE, ...) ## S3 method for class 'enpy_starting_points' as_starting_point(object, specific = FALSE, ...) ## S3 method for class 'pense_fit' as_starting_point(object, specific = FALSE, alpha, lambda, ...) ## S3 method for class 'pense_cvfit' as_starting_point( object, specific = FALSE, alpha, lambda = c("min", "se"), se_mult = 1, ... )starting_point(beta, intercept, lambda, alpha) as_starting_point(object, specific = FALSE, ...) ## S3 method for class 'enpy_starting_points' as_starting_point(object, specific = FALSE, ...) ## S3 method for class 'pense_fit' as_starting_point(object, specific = FALSE, alpha, lambda, ...) ## S3 method for class 'pense_cvfit' as_starting_point( object, specific = FALSE, alpha, lambda = c("min", "se"), se_mult = 1, ... )
beta |
beta coefficients at the starting point. Can be a numeric vector, a sparse vector of class dsparseVector, or a sparse matrix of class dgCMatrix with a single column. |
intercept |
intercept coefficient at the starting point. |
lambda |
optionally either a string specifying which penalty level to use
( |
alpha |
optional value for the |
object |
an object with estimates to use as starting points. |
specific |
whether the estimates should be used as starting points only at the penalization level they are computed for. Defaults to using the estimates as starting points for all penalization levels. |
... |
further arguments passed to or from other methods. |
se_mult |
If |
A starting points can either be shared, i.e., used for every penalization level PENSE
estimates are computed for, or specific to one penalization level.
To create a specific starting point, provide the penalization parameters lambda and alpha.
If lambda or alpha are missing, a shared starting point is created.
Shared and specific starting points can all be combined into a single list of starting points,
with pense() handling them correctly.
Note that specific starting points will lead to the lambda value being added to the
grid of penalization levels.
See pense() for details.
Starting points computed via enpy_initial_estimates() are by default shared starting points
but can be transformed to specific starting points via
as_starting_point(..., specific = TRUE).
When creating starting points from cross-validated fits, it is possible to extract only the
estimate with best CV performance (lambda = "min"), or the estimate with CV performance
statistically indistinguishable from the best performance (lambda = "se").
This is determined to be the estimate with prediction performance within
se_mult * cv_se from the best model.
an object of type starting_points to be used as starting point for pense().
Other functions for initial estimates:
enpy_initial_estimates(),
enpy_options(),
prinsens()
If lambda = "se" and object contains fitted estimates for every penalization level in the sequence, extract the
coefficients of the most parsimonious model with prediction performance statistically indistinguishable from the best
model. This is determined to be the model with prediction performance within se_mult * cv_se from the best model.
## S3 method for class 'pense_cvfit' summary(object, alpha, lambda = "min", se_mult = 1, ...) ## S3 method for class 'pense_cvfit' print(x, alpha, lambda = "min", se_mult = 1, ...)## S3 method for class 'pense_cvfit' summary(object, alpha, lambda = "min", se_mult = 1, ...) ## S3 method for class 'pense_cvfit' print(x, alpha, lambda = "min", se_mult = 1, ...)
object, x
|
an (adaptive) PENSE fit with cross-validation information. |
alpha |
Either a single number or missing.
If given, only fits with the given |
lambda |
either a string specifying which penalty level to use
( |
se_mult |
If |
... |
ignored. |
prediction_performance() for information about the estimated prediction performance.
coef.pense_cvfit() for extracting only the estimated coefficients.
Other functions for plotting and printing:
plot.pense_cvfit(),
plot.pense_fit(),
prediction_performance()
Compute the -scale without centering the values.
tau_size(x)tau_size(x)
x |
numeric values. Missing values are verbosely ignored. |
the estimate of scale of centered values.
Other functions to compute robust estimates of location and scale:
mloc(),
mlocscale(),
mscale()