[R] Getting lm() to work with a matrix

Gabor Grothendieck ggrothendieck at gmail.com
Wed May 20 02:46:48 CEST 2009


Try this (note dot after ~):

lm(response[, 3] ~., as.data.frame(spectra.spec[, 2:20]))


On Tue, May 19, 2009 at 6:21 PM, MikSmith <mike at hsm.org.uk> wrote:
>
> Hi
>
> I'm fairly new to R and am trying to analyse some large spectral datasets
> using stepwise regression (fairly standard in this area). I have a field
> sampled dataset, of which a proportion has been held back for validation. I
> gather than step() needs to be fed a regression model and lm() can produce a
> multiple regression. I had thought something like:
>
> spectra.lm <- lm(response[,3]~spectra.spec[,2:20])
>
> might work but lm() doesnt appear to like being fed a range of columns. I
> suspect Ive missed something fairly fundamental here.....
>
> Any help much appreciated
>
> best wishes
>
> mike
> --
> View this message in context: http://www.nabble.com/Getting-lm%28%29-to-work-with-a-matrix-tp23625486p23625486.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list