Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

SFSI (version 1.2.0)

Methods_LASSO: LASSO methods

Description

Predicted values for a provided matrix of predictors X

Usage

# S3 method for LASSO
coef(object, ..., i=NULL)

# S3 method for LASSO fitted(object, ...)

Value

Method coef returns a matrix that contains, for each value of lambda (in columns), the predicted values corresponding to each row of the matrix X.

Method fitted returns fitted values Xβ

Arguments

object

An object of the class 'LASSO' returned either by the function 'LARS' or 'solveEN'

...

Other arguments: X (numeric matrix) scores for as many predictors there are in ncol(object$beta) (in columns) for a desired number n of observations (in rows)

i

(integer vector) Index columns of matrix 'Gamma' to be considered

Author

Marco Lopez-Cruz (maraloc@gmail.com) and Gustavo de los Campos

Examples

Run this code
  require(SFSI)
  data(wheatHTP)
  
  y = as.vector(Y[,"E1"])  # Response variable
  X = scale(X_E1)          # Predictors
  
  # Training and testing sets
  tst = which(Y$trial %in% 1:10)
  trn = seq_along(y)[-tst]

  # Calculate covariances in training set
  XtX = var(X[trn,])
  Xty = cov(X[trn,],y[trn])
  
  # Run the penalized regression
  fm = solveEN(XtX,Xty,alpha=0.5)   
  
  # Regression coefficients
  B = coef(fm)
  
  # Predicted values
  yHat1 = fitted(fm, X=X[trn,])  # training data
  yHat2 = fitted(fm, X=X[tst,])  # testing data
  
  # Penalization vs correlation
  plot(-log(fm$lambda[-1]),cor(y[trn],yHat1[,-1]), main="training")
  plot(-log(fm$lambda[-1]),cor(y[tst],yHat2[,-1]), main="testing")

Run the code above in your browser using DataLab