[R] FW: lasso regression
David Winsemius
dwinsemius at comcast.net
Tue Jul 12 16:26:35 CEST 2011
On Jul 12, 2011, at 10:12 AM, Heiman, Thomas J. 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
>
It is now clear that you failed to get your data in properly. Since
stringsAsFactors is set to TRUE by default for all of the read.*
functions, all of your columns are now factors. Perhaps you had a
blank line at the beginning of your data? The default for read.csv
(which is just a wrapper with different parameters for read.table) is
to set header =TRUE. You should learn to use str() on your data
immediately after data entry steps.
--
David.
> #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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list