Henrique Dallazuanna
2010-Nov-16 19:03 UTC
[R] Error: invalid type(list) for variable when using lm()
Try this: y <- rnorm(100) X <- matrix(runif(100 * 10), ncol = 10) lm(y ~ ., data = cbind.data.frame(y, X)) On Tue, Nov 16, 2010 at 5:07 PM, Tianchan Niu <niu@isis.georgetown.edu>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. > >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Tianchan Niu
2010-Nov-16 19:07 UTC
[R] Error: invalid type(list) for variable when using lm()
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