Tianchan -Your X is not a matrix -- it's a dataframe. Probably the simplest solution is to use
lm(y~as.matrix(X)) but you should also learn the difference between a data frame and a matrix. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 16 Nov 2010, Tianchan Niu wrote:
Dear All,I would like to do multiple regression in R. I used: lm(y~X), where y is a n by 1 vector, and X is a n by m matrix. I kept getting the error message:Error in model.frame.default(formula = y ~ X, : invalid type (list) for variable 'X'. However, when I used: lm(y~X[,1]+X[,2]+X[,3]+…+X[,m]), it works well, but this is not the form I prefer, it makes my codes complicated.Please help.Thank you very much,Jane
______________________________________________ R-help@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.