Re: [R] automating regression or correlations for many variables

From: Dennis Murphy <djmuser_at_gmail.com>
Date: Mon, 04 Apr 2011 12:53:38 -0700

Hi:

Here's a small example:
> df <- data.frame(y1 = rnorm(10), y2 = rnorm(10), y3 = rnorm(10), lat =
rnorm(10))
> m <- lm(cbind(y1, y2, y3) ~ lat, data = df)
> summary(m)

<snip...provides summaries for each response>

The LHS of the model formula needs to be a matrix. In your case, something like

m <- lm(as.matrix(snp[, -1]) ~ lat, data = snp)

ought to work.

HTH,
Dennis

On Mon, Apr 4, 2011 at 10:13 AM, geral <geraldes_at_mail.ubc.ca> wrote:

> Dear All,
>
> I have a large data frame with 10 rows and 82 columns. I want to apply the
> same function to all of the columns with a single command. e.g. zl <- lm
> (snp$a_109909 ~ snp$lat) will fit a linear model to the values in lat and
> a_109909. What I want to do is fit linear models for the values in each
> column against lat. I tried doing zl <- (snp[,2:82] ~ snp$lat[,1]) but got
> the following error message "Error in model.frame.default(formula = snp[,
> 2:82] ~ snp[, 1], drop.unused.levels = TRUE) :
> invalid type (list) for variable 'snp[, 2:82]'". Does this mean I cannot
> use a data frame to do this? Should I have my data in a matrix instead?
>
> Thanks
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/automating-regression-or-correlations-for-many-variables-tp3426091p3426091.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.
>

        [[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. Received on Mon 04 Apr 2011 - 19:56:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 04 Apr 2011 - 21:00:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive