Description Usage Arguments Value Examples
This function estimates coefficients for elastic net and also has function to visualize solution path.
1 | elnet_coord(Y, X, alpha, B)
|
Y |
= response vector |
X |
= covariate matrix |
alpha |
= parameter between [0,1] |
B |
= initial vector |
a matrix with lambda values in the first column, and corresponding coefficient estimates
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.