[R] Using all variables in a linear model
Joshua Wiley
jwiley.psych at gmail.com
Wed Apr 21 00:20:11 CEST 2010
What about using x[,-predictor]. For instance:
x <- matrix(1:9, nrow=3)
x[,-2] # all but the second column
Perhaps using your code it would be something like...
lm=lm(x[,dim(x)[2]] ~ x[,-dim(x)[2]], data=x)
Best regards,
Josh
On Tue, Apr 20, 2010 at 3:12 PM, Walter Yund IV <wyundiv at gmail.com> wrote:
> Hello,
>
> I am trying to automate linear regression for many different datasets, each
> with the same rough format (the last variable is the response). I've been
> doing something like this:
>
> lm=lm(x[,dim(x)[2]] ~ ., data=x)
>
> where the dot denotes all variables. However, this means that the response
> is included as a predictor, which is obviously what I don't want. How do I
> request that all the columns in my dataset be used as predictors, except for
> the response?
>
> Thanks,
>
> Walter
>
> [[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.
>
--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/
More information about the R-help
mailing list