Hi, I am trying to do a lasso regression using the lars package with the following data (see attached): FastestTime WinPercentage PlacePercentage ShowPercentage BreakAverage FinishAverage Time7Average Time3Average Finish 116.90 0.14 0.14 0.29 4.43 3.29 117.56 117.77 5.00 116.23 0.29 0.43 0.14 6.14 2.14 116.84 116.80 2.00 116.41 0.00 0.14 0.29 5.71 3.71 117.24 117.17 4.00 115.80 0.57 0.00 0.29 2.14 2.57 116.21 116.53 6.00 117.76 0.14 0.14 0.43 5.43 3.57 118.57 118.87 3.00 117.69 0.14 0.14 0.00 4.71 4.00 118.69 118.60 6.00 116.46 0.14 0.00 0.00 5.14 5.00 118.50 118.97 5.00 119.77 0.00 0.00 0.14 4.57 4.14 120.74 121.03 4.00 116.81 0.14 0.29 0.00 4.86 3.57 117.63 117.40 5.00 117.66 0.14 0.14 0.14 4.57 4.71 119.19 120.57 7.00 #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
Hi, I am trying to do a lasso regression using the lars package with the following data (see attached): FastestTime WinPercentage PlacePercentage ShowPercentage BreakAverage FinishAverage Time7Average Time3Average Finish 116.90 0.14 0.14 0.29 4.43 3.29 117.56 117.77 5.00 116.23 0.29 0.43 0.14 6.14 2.14 116.84 116.80 2.00 116.41 0.00 0.14 0.29 5.71 3.71 117.24 117.17 4.00 115.80 0.57 0.00 0.29 2.14 2.57 116.21 116.53 6.00 117.76 0.14 0.14 0.43 5.43 3.57 118.57 118.87 3.00 117.69 0.14 0.14 0.00 4.71 4.00 118.69 118.60 6.00 116.46 0.14 0.00 0.00 5.14 5.00 118.50 118.97 5.00 119.77 0.00 0.00 0.14 4.57 4.14 120.74 121.03 4.00 116.81 0.14 0.29 0.00 4.86 3.57 117.63 117.40 5.00 117.66 0.14 0.14 0.14 4.57 4.71 119.19 120.57 7.00 #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 [[alternative HTML version deleted]]
Hi, I am trying to do a lasso regression using the lars package with the following data: FastestTime WinPercentage PlacePercentage ShowPercentage BreakAverage FinishAverage Time7Average Time3Average Finish 116.90 0.14 0.14 0.29 4.43 3.29 117.56 117.77 5.00 116.23 0.29 0.43 0.14 6.14 2.14 116.84 116.80 2.00 116.41 0.00 0.14 0.29 5.71 3.71 117.24 117.17 4.00 115.80 0.57 0.00 0.29 2.14 2.57 116.21 116.53 6.00 #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 [[alternative HTML version deleted]]
On Jul 12, 2011, at 9:53 AM, Heiman, Thomas J. wrote:> Hi, > > I am trying to do a lasso regression using the lars package with the > following data (see attached):Nothing attached. (And now you have also sent an exact duplicate.) snipped failed attempt to include data inline that was sabotaged by using HTML mail> > > > #load Data > crs<- read.csv("file:///C:/temp/Horse//horseracing.csv<file:///C:\temp\Horse\horseracing.csv > >", na.strings=c(",", "NA", "", "?"), encoding="UTF-8")This looks wrong. Your data had no commas in it and you are also setting na.strings to include commas. If I am wrong then you should provide dput on crs instead of> > # # 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 > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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
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
On Tue, 2011-07-12 at 10:12 -0400, 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 > > #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!!Row 1 contains character data, the variable names. Are you missing a `header = TRUE` (this is the default in `read.csv()`), or do you have several header lines? I also think you have the response/predictors back to front there; otherwise, why would you need to shrink the coefficient and select from a model with a single predictor? HTH G> 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
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
On 07/12/2011 09:53 AM, Heiman, Thomas J. wrote:> # # define x and y > x= x<-crs[,9] #predictor variables > y= y<-crs[1:8,] #response variableThis cannot be correct. The response variable is a vector, while the predictor variables form a matrix. You have the response variable consisting of only the first 8 observations, then all the columns. Perhaps you mean: X <- crs[,1:8] y <- crs[,9] If this is not the case, please include the output of head(crs) and then tell us which variable is your response. -- Patrick Breheny Assistant Professor Department of Biostatistics Department of Statistics University of Kentucky