[R] Linear Regression

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Nov 7 14:01:55 CET 2007


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



More information about the R-help mailing list