Hello all, I?m running simple linear regressions on multiple species of plants, comparing abiotic factor X against plant trait Y (e.g. Species1: leaf length vs air temperature). Ideally, what I?m looking for is an output giving me the R2, p value, coefficient, and Y intercept for each regression. Something like the example below: Species1: leaf length vs air temperature R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 Species2: leaf length vs air temperature R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 Species1: leaf length vs snow-free date R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 Species2: leaf length vs snow-free date R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 I currently have my data in this form: Species LeafLength AirTemp. SnowFreeDate Species1 1.1 20 160 Species2 4.5 20 160 Species3 5.4 20 160 And thought I could try this formula: lm(formula = LeafLength~AirTemp, SnowFreeDate | Species) But R is not a fan of it. Is there a way to do this (or get something remotely close to this)? I realize the output will probably be a bit messier than this, but what I?m really looking to avoid is running these regressions individually. -- View this message in context: http://r.789695.n4.nabble.com/Linear-regressions-producing-multiple-outputs-tp3309411p3309411.html Sent from the R help mailing list archive at Nabble.com.
Hi RTSlider, I suspect you rather need to use the lme command (or perhaps glmmPQL or lmer) because you have a random predictor? lme(fixed=LeafLength~AirTemp*SnowFreeDate,random=~1|Species) See http://socserv.mcmaster.ca/jfox/Books/Companion-1E/appendix-mixed-models.pdf for a tutorial on lme. Toby ________________________________________ From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of RTSlider [rob.t.slider at gmail.com] Sent: 16 February 2011 18:13 To: r-help at r-project.org Subject: [R] Linear regressions: producing multiple outputs Hello all, I?m running simple linear regressions on multiple species of plants, comparing abiotic factor X against plant trait Y (e.g. Species1: leaf length vs air temperature). Ideally, what I?m looking for is an output giving me the R2, p value, coefficient, and Y intercept for each regression. Something like the example below: Species1: leaf length vs air temperature R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 Species2: leaf length vs air temperature R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 Species1: leaf length vs snow-free date R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 Species2: leaf length vs snow-free date R2 = 0.10 p = 0.50 m = 5.23 b = 12.2 I currently have my data in this form: Species LeafLength AirTemp. SnowFreeDate Species1 1.1 20 160 Species2 4.5 20 160 Species3 5.4 20 160 And thought I could try this formula: lm(formula = LeafLength~AirTemp, SnowFreeDate | Species) But R is not a fan of it. Is there a way to do this (or get something remotely close to this)? I realize the output will probably be a bit messier than this, but what I?m really looking to avoid is running these regressions individually. -- View this message in context: http://r.789695.n4.nabble.com/Linear-regressions-producing-multiple-outputs-tp3309411p3309411.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.
Gabor Grothendieck
2011-Feb-17 13:34 UTC
[R] Linear regressions: producing multiple outputs
On Wed, Feb 16, 2011 at 1:13 PM, RTSlider <rob.t.slider at gmail.com> wrote:> > Hello all, > I?m running simple linear regressions on multiple species of plants, > comparing abiotic factor X against plant trait Y (e.g. Species1: leaf length > vs air temperature). > > Ideally, what I?m looking for is an output giving me the R2, p value, > coefficient, and Y intercept for each regression. Something like the example > below: > > Species1: leaf length vs air temperature > ? ? ? ?R2 = 0.10 ? ? ? p = 0.50 ? ? ? ?m = 5.23 ? ? ? ?b = 12.2 > Species2: leaf length vs air temperature > ? ? ? ?R2 = 0.10 ? ? ? p = 0.50 ? ? ? ?m = 5.23 ? ? ? ?b = 12.2 > > Species1: leaf length vs snow-free date > R2 = 0.10 ? ? ? p = 0.50 ? ? ? ?m = 5.23 ? ? ? ?b = 12.2 > Species2: leaf length vs snow-free date > R2 = 0.10 ? ? ? p = 0.50 ? ? ? ?m = 5.23 ? ? ? ?b = 12.2 > > I currently have my data in this form: > Species LeafLength ? ? ? ? ? ? ?AirTemp. ? ? ? ?SnowFreeDate > Species1 ? ? ? ?1.1 ? ? ? ? ? ? ? ? ? ? 20 ? ? ? ? ? ? ?160 > Species2 ? ? ? ?4.5 ? ? ? ? ? ? ? ? ? ? 20 ? ? ? ? ? ? ?160 > Species3 ? ? ? ?5.4 ? ? ? ? ? ? ? ? ? ? 20 ? ? ? ? ? ? ?160 > > And thought I could try this formula: > lm(formula = LeafLength~AirTemp, SnowFreeDate | Species) > > But R is not a fan of it. > Is there a way to do this (or get something remotely close to this)? > I realize the output will probably be a bit messier than this, but what I?m > really looking to avoid is running these regressions individually. >lmList in lme4 supports that notation. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com