Hello everyone, I would like to a linear regression with the following code. lm(a[,"fquamsci"]~., data=a) a is a list with class "mts" "ts" , and "fquamsci" is the name of the response variable in a. I would like to do a linear regression of "fquamsci" to the rest of the variables. But it turns out the "fquamsci" is also included in the explanatory variables. I tried the following, it is quite strange that it does not work as well. lm(a[,"fquamsci"]~.-a[,"fquamsci"], data=a) Could anyone give me some advice? Many thanks -- View this message in context: http://www.nabble.com/Linear-Regression-tf4764346.html#a13626039 Sent from the R help mailing list archive at Nabble.com.
Try this: data(tcm, package="tseries") mod <- lm(tcm[,"tcm1y"]~., data=tcm[,- which(dimnames(tcm)[[2]]=="tcm1y")]) On 07/11/2007, livia <yn19832@msn.com> wrote:> > > Hello everyone, > > I would like to a linear regression with the following code. > lm(a[,"fquamsci"]~., data=a) > > a is a list with class "mts" "ts" , and "fquamsci" is the name of the > response variable in a. I would like to do a linear regression of > "fquamsci" > to the rest of the variables. But it turns out the "fquamsci" is also > included in the explanatory variables. I tried the following, it is quite > strange that it does not work as well. > > lm(a[,"fquamsci"]~.-a[,"fquamsci"], data=a) > > Could anyone give me some advice? > Many thanks > > -- > View this message in context: > http://www.nabble.com/Linear-Regression-tf4764346.html#a13626039 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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]]
Doesn't lm(fquamsci ~ ., data=a) work? It normally does for a list a, so there would seem to be something special about your example if it does not. E.g. library(MASS) attach(hills) a <- list(dist=dist, climb=climb, time=time) detach() lm(time ~ ., data=a) (Maybe 'a' is not actually a list but a matrix? In which case try as.data.frame(a).) On Wed, 7 Nov 2007, livia wrote:> > Hello everyone, > > I would like to a linear regression with the following code. > lm(a[,"fquamsci"]~., data=a) > > a is a list with class "mts" "ts" , and "fquamsci" is the name of the > response variable in a. I would like to do a linear regression of "fquamsci" > to the rest of the variables. But it turns out the "fquamsci" is also > included in the explanatory variables. I tried the following, it is quite > strange that it does not work as well. > > lm(a[,"fquamsci"]~.-a[,"fquamsci"], data=a) > > Could anyone give me some advice? > Many thanks > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595