[R] regression by groups

Chuck Cleland ccleland at optonline.net
Wed Oct 10 02:08:37 CEST 2007


Jiong Zhang, PhD wrote:
> Hi All,
> 
> I want to run regression (lm) on my dependant variable by gender and race. How do I integrate the "by" function in lm?
> 
> thanks.

  Here is an example using the iris data:

by(iris, iris$Species, function(x){
summary(lm(Sepal.Length ~ Sepal.Width +
                          Petal.Length +
                          Petal.Width, data=x))})

> jiong
>  The email message (and any attachments) is for the sole...{{dropped:11}}
> 
> ______________________________________________
> 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list