Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Methods_LASSO

LASSO methods


Description

Predicted values for a provided matrix of predictors X

Usage

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

Arguments

object

An object of the class 'LASSO' returned either by the function 'lars2' 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)

Value

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

Author(s)

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

Examples

require(SFSI)
  data(wheatHTP)
  
  y = as.vector(Y[,"YLD"])  # Response variable
  X = scale(WL)             # Predictors
  
  # Training and testing sets
  tst = 1: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 the penalized 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")

SFSI

Sparse Family and Selection Index

v0.3.0
GPL-3
Authors
Marco Lopez-Cruz [aut, cre], Gustavo de los Campos [aut], Paulino Perez-Rodriguez [ctb]
Initial release
2021-04-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.