[R] FW: lasso regression

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Jul 12 16:30:58 CEST 2011


Hi,

(i) As David suggested, please use `dput` to provide examples of data!

(ii) The nut of your problem is that you are giving lars an object
that it is not expecting. It wants a *matrix* for its `x` variable, as
you'll see in the help for ?lars.

So, as long as this expression:

R> is.numeric(x) && is.matrix(x)

Evaluates to FALSE for your x, you won't get it to work.

(iii) Consider using glmnet -- you get the lass "for free" when you
set a=1, but you can also see if the "elastic net" is helpful.

-steve



On Tue, Jul 12, 2011 at 10:12 AM, Heiman, Thomas J. <theiman at mitre.org> wrote:
>
> Hi,
>
> Hopefully I got the formatting down.. I am trying to do a lasso regression using the lars package with the following data (the data files is in .csv format):
>
>        V1              V2              V3                      V4                      V5              V6              V7              V8              V9
> 1       FastestTime     WinPercentage   PlacePercentage ShowPercentage  BreakAverage    FinishAverage   Time7Average    Time3Average    Finish
> 2       116.9           0.14285715      0.14285715              0.2857143               4.428571        3.2857144       117.557144      117.76667       5.0
> 3       116.22857       0.2857143       0.42857143              0.14285715              6.142857        2.142857        116.84286       116.8           2.0
> 4       116.41428       0.0             0.14285715              0.2857143               5.714286        3.7142856       117.24286       117.166664      4.0
> 5       115.8           0.5714286       0.0                     0.2857143               2.142857        2.5714285       116.21429       116.53333       6.0
>
> #load Data
> crs<- read.csv("file:///C:/temp/Horse//horseracing.csv<file:///C:\temp\Horse\horseracing.csv>", na.strings=c(",", "NA", "", "?"), encoding="UTF-8")
>
> #    # define x and y
> x= x<-crs[,9]    #predictor variables
> y= y<-crs[1:8,]  #response variable
>
>
> library(lars)
> cv.lars(x, y, K=10, trace=TRUE, plot.it = TRUE,se = TRUE, type="lasso")
>
> and I get:
>
> LASSO sequence
> Error in one %*% x : requires numeric/complex matrix/vector arguments
>
> Any idea on what I am doing wrong?  Thank you!!
>
> Sincerely,
>
> tom
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the R-help mailing list