constrlasso: The function constrlasso

View source: R/constrlasso.R

constrlassoR Documentation

The function constrlasso

Description

This function fits a linearly constrained lasso regression, using a predictor matrix X, a response y and a tuning parameter value lambda. It results in a vector of coefficient estimates. The function corresponds to lsq_constrsparsereg of the SparseReg MATLAB-toolbox by Zhou and Gaines, see the project page. Only the Quadratic Programming Algorithm for ENET is implemented. For more information, see \insertCitegaines2018algorithms;textualconstrlasso.

Usage

constrlasso(
  X,
  y,
  lambda,
  Aeq = NULL,
  beq = NULL,
  A = NULL,
  b = NULL,
  penidx = NULL,
  method = "QP"
)

Arguments

X

an nxp matrix of p regressors with n observations.

y

an nx1 response vector with n observations.

lambda

a tuning parameter value for the lasso penalty. Default value is lambda=0.

Aeq

a cxp equality constraint matrix, containing c constraints for p regressors. Default value is Aeq=NULL, no equality constraints.

beq

a cx1 equality constraint vector. Default value is beq=NULL, no equality constraints.

A

a cxp inequality constraint matrix, containing c constraints for p regressors. Default value is A=NULL, no inequality constraints.

b

a cx1 inequality constraint vector. Default value is b=NULL, no inequality constraints.

penidx

a logical px1 vector, indicating which coefficients are to be penalized. Default value is penidx=NULL and imposes penalty on all p coefficients.

method

a character string, the method to be used. Possible values are "QP" (default) for Quadratic Programming and "CD" for Coordinate Descent. "CD" uses the glmnet package and only works without equality and inequality constraints.

Value

betahat a px1 vector of estimated coefficients.

dual_eq equality duals. The function returns an empty vector for no equality constraints.

dual_neq inequality duals. The function returns an empty vector for no inequality constraints.

Details

The Constrained Lasso as in \insertCitegaines2018algorithms;textualconstrlasso minimizes

0.5||y - X \beta ||^2_2 + \lambda||\beta||_1,

subject to Aeq \beta = beq and A \beta\le b.

References

\insertAllCited

Examples

set.seed(1234)
n <- 200 # number of observations
p <- 150 # number of regressors
real_p <- 50 # number of true predictors
Xmat <- matrix(rnorm(n * p), nrow = n, ncol = p)
yvec <- apply(Xmat[, 1:real_p], 1, sum) + rnorm(n)
results_reg_no_constr <- constrlasso(Xmat, yvec, lambda = 0)


antshi/constrLasso documentation built on April 12, 2025, 9:39 a.m.