elnet_coord: Elastic Net Coordinate Descent

Description Usage Arguments Value Examples

Description

This function estimates coefficients for elastic net and also has function to visualize solution path.

Usage

1
elnet_coord(Y, X, alpha, B)

Arguments

Y

= response vector

X

= covariate matrix

alpha

= parameter between [0,1]

B

= initial vector

Value

a matrix with lambda values in the first column, and corresponding coefficient estimates

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(MASS)
 set.seed(123)
 n <- 100
 mu <- rep(0, 20)
 Sigma <- diag(20)
Sigma[1,2] <- Sigma[2,1] <- Sigma[5,6] <- Sigma[6,5] <- 0.8
TrueBeta <- c(2, 0, -2, 0, 1, 0, -1, 0, rep(0, times=12))
X <- mvrnorm(n, mu, Sigma)
Y <- X%*%TrueBeta + rnorm(n)

require(ggplot2)
require(reshape2)
output <- elnet_coord(Y, X, alpha=0, B=rep(0, times=ncol(X)))
visualize_coord(output)
output <- elnet_coord(Y, X, alpha=0.5, B=rep(0, times=ncol(X)))
visualize_coord(output)
output <- elnet_coord(Y, X, alpha=1, B=rep(0, times=ncol(X)))
visualize_coord(output)

gdeng96/Homework2 documentation built on June 5, 2019, 11:07 p.m.