myLasso: myLasso

Description Usage Arguments Value Examples

View source: R/Lasso.R

Description

This function finds the lasso solution path for various values of the regularization parameter lambda using corrdinate descent. Returns a matrix containing the lasso solution vector beta for each regularization parameter.

Usage

1
myLasso(X, Y, lambda_all)

Arguments

X

an n x p matrix of explanatory variables.

Y

n dimensional response vector

lambda_all

vector of regularization parameters

Value

Returns a p+1 x length of lambda_all matrix of regularized betas for each specified level of lambda

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
dim_r=50
dim_c=10
s=7
lam = (100:1)*10
x = matrix(rnorm(dim_r*dim_c), nrow = dim_r)
beta_true = matrix(rep(0,dim_c), nrow = dim_c)
beta_true[1:s] = 1:7
y = x%*%beta_true + rnorm(dim_r)
beta_true <- c(0, beta_true)
lass <- myLasso(x, y, lam)
matplot(t(matrix(rep(1, 11), nrow = 1)%*%abs(lass)), t(lass), type = "l")

stacyste/RegressionPkg documentation built on Nov. 24, 2019, 5:12 p.m.