Methods_LASSO: LASSO methods

Description Usage Arguments Author(s) Examples

Description

Returns the predicted values for each value of lambda (in columns) for each row of the provided matrix X

Usage

1
2
## S3 method for class 'LASSO'
fitted(object, ...)

Arguments

object

An object of the class 'LASSO' returned either by 'lars2' or 'solveEN' functions

...

Other arguments: a matrix X of predictors with n rows and number of columns equal to ncol(object$beta)

Author(s)

Marco Lopez-Cruz (lopezcru@msu.edu) and Gustavo de los Campos

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  require(SFSI)
  data(wheatHTP)
  y = scale(Y[,"YLD"])         # Response variable
  X = scale(WL)                # Reflectance data

  # Training and testing sets
  tst = sample(seq_along(y),ceiling(0.3*length(y)))
  trn = seq_along(y)[-tst]

  # Calculate covariances in training set
  XtX = var(X[trn,])
  Xty = cov(y[trn],X[trn,])
  
  # Run an Elastic-Net regression
  fm = solveEN(XtX,Xty,alpha=0.5)   
  
  # 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),cor(y[trn],yHat1)[1,], main="training")
  plot(-log(fm$lambda),cor(y[tst],yHat2)[1,], main="testing")

MarcooLopez/SFSI_data documentation built on April 15, 2021, 10:53 a.m.