Select and fit sparse linear model with LASSO
The purpose of this function is to make the process of LASSO modelling as simple as possible.
This is a simple wrapper on two glmnet functions which, when given input matrix X and response vector y, and a criterion for model selection, will estimate the lambda parameter, and return the LASSO results as a glmnet model. This model can then be used to find coefficients and predictions.
easyLASSO(X, y, criterion = "lambda.1se")
Predictor matrix, nXp, with n observations and p features.
Response vector, or column or row matrix. Must have length n.
String describing which lambda criterion to use in selecting a LASSO model. Choices currently are c("lambda.1se","lambda.min").
a glmnet model
1 2 3 4 5 6 7 8 9 10 11
set.seed(1) nObs <- 100 X <- distMat(nObs,6) A <- cbind(c(1,0,-1,rep(0,3))) # Y will only depend on X[,1] and X[,3] Y <- X %*% A + 0.1*rnorm(nObs) lassoObj <- easyLASSO(X=X,y=Y) # LASSO fitting Yhat <- predict(lassoObj,newx=X) yyHatPlot(Y,Yhat) coef( lassoObj ) # Sparse coefficients coefPlot( lassoObj )
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.