elnet_coord: fits elastic net to data using coordinate descent algorithm

Description Usage Arguments Value Examples

Description

fits elastic net to data using coordinate descent algorithm

Usage

1
elnet_coord(x, y, lambda, alpha, tol)

Arguments

x

independent variable

y

dependent variable

lambda

LASSO tuning

alpha

proportion of usage in l1 penalty comparing with l2

tol

tolerance

Value

estimation of parameter beta in y=beta*x

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
p = 20
n = 100
x=matrix(0,nrow = n, ncol = p)
beta=c(2,0,-2,0,1,0,-1,0,rep(0,12))
x[,1:2] = mvrnorm(n, mu = c(0,0), Sigma = matrix(c(1,0.8,0.8,1), ncol = 2))
x[,5:6] = mvrnorm(n, mu = c(0,0), Sigma = matrix(c(1,0.8,0.8,1), ncol = 2))
x[,3:4] = mvrnorm(n, mu = c(0,0), Sigma = matrix(c(1,0,0,1), ncol = 2))
for(i in 7:p){
    x[,i] = rnorm(n, mean = 0, sd = 1)
}
e = rnorm(n, mean = 0, sd = 1)
y = x%*%beta+e
elnet_coord(x, y, lambda=1, alpha=0.5, tol=1e-6)

xysxu/hwyx documentation built on June 6, 2019, 7:55 a.m.