admm_enet: Fitting An Elastic Net Model Using ADMM Algorithm

Description Usage Arguments Setting Penalty Parameter Additional Options Model Fitting Author(s) Examples

View source: R/40_admm_enet.R

Description

Elastic Net is an extension to the Lasso model. It seeks a coefficient vector β that minimizes

1/(2n) * ||y - X * β||_2^2 + λ * α * ||β||_1 + 0.5 * λ * (1 - α) * ||β|_2^2|

Here n is the sample size, λ is the regularization parameter for penalty term, and α is the proportion of L1 norm in the penalty part.

This function will not directly conduct the computation, but rather returns an object of class "ADMM_Enet" that contains several memeber functions to actually constructs and fits the model.

Member functions that are callable from this object are listed below:

$penalty() Specify the penalty parameter. See section Setting Penalty Parameter for details.
$opts() Setting additional options. See section Additional Options for details.
$fit() Fit the model and do the actual computation. See section Model Fitting for details.

Usage

1
admm_enet(x, y, intercept = TRUE, standardize = TRUE, ...)

Arguments

x

The data matrix

y

The response vector

intercept

Whether to fit an intercept in the model. Default is TRUE.

standardize

Whether to standardize the explanatory variables before fitting the model. Default is TRUE. Fitted coefficients are always returned on the original scale.

Setting Penalty Parameter

The penalty parameters λ and α can be set through the member function $penalty(), with the usage and parameters given below:

1
2
    model$penalty(lambda = NULL, nlambda = 100, lambda_min_ratio,
                  alpha = 1, ...)
lambda

A user provided sequence of λ. If set to NULL, the program will calculate its own sequence according to nlambda and lambda_min_ratio, which starts from λ_0 (with this λ all coefficients will be zero) and ends at lambda0 * lambda_min_ratio, containing nlambda values equally spaced in the log scale. It is recommended to set this parameter to be NULL (the default).

nlambda

Number of values in the λ sequence. Only used when the program calculates its own λ (by setting lambda = NULL).

lambda_min_ratio

Smallest value in the λ sequence as a fraction of λ_0. See the explanation of the lambda argument. This parameter is only used when the program calculates its own λ (by setting lambda = NULL). The default value is the same as glmnet: 0.0001 if nrow(x) >= ncol(x) and 0.01 otherwise.

alpha

Parameter to control the proportion of L1 norm in the penalty term. alpha = 1 corresponds to Lasso and alpha = 2 is equivalent to Ridge Regression.

This member function will implicitly return the "ADMM_Enet" object itself.

Additional Options

Additional options related to ADMM algorithm can be set through the $opts() member function of an "ADMM_Lasso" object. The usage of this method is

1
2
    model$opts(maxit = 10000, eps_abs = 1e-5, eps_rel = 1e-5,
               rho = NULL)

Here model is the object returned by admm_enet(). Explanation of the arguments is given below:

maxit

Maximum number of iterations.

eps_abs

Absolute tolerance parameter.

eps_rel

Relative tolerance parameter.

rho

ADMM step size parameter. If set to NULL, the program will compute a default one.

This member function will implicitly return the "ADMM_Enet" object itself.

Model Fitting

Model will be fit after calling the $fit() member function. This is no argument that needs to be set. The function will return an object of class "ADMM_Enet_fit", which contains the following fields:

lambda

The sequence of λ to build the solution path.

beta

A sparse matrix containing the estimated coefficient vectors, each column for one λ. Intercepts are in the first row.

niter

Number of ADMM iterations.

Class "ADMM_Enet_fit" also contains a $plot() member function, which plots the coefficient paths with the sequence of λ. See the examples below.

Author(s)

Yixuan Qiu <http://statr.me>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
set.seed(123)
n = 100
p = 20
b = runif(p)
x = matrix(rnorm(n * p, mean = 1.2, sd = 2), n, p)
y = 5 + c(x %*% b) + rnorm(n)

## Directly fit the model
admm_enet(x, y)$penalty(alpha = 0.5)$fit()

## Or, if you want to have more customization:
model = admm_enet(x, y)
print(model)

## Specify the lambda sequence and the alpha parameter
model$penalty(nlambda = 20, lambda_min_ratio = 0.01, alpha = 0.5)

## Lower down precision for faster computation
model$opts(maxit = 100, eps_rel = 0.001)

## Inspect the updated model setting
print(model)

## Fit the model and do the actual computation
res = model$fit()
res$beta

## Create a solution path plot
res$plot()

yixuan/ADMM documentation built on May 4, 2019, 5:28 p.m.