Hello R help-ers, I have a basic question, but I have been playing with it for a while and haven't quite gotten a hang of how to get it working. I want to perform multiple one-way ANOVAs on subsets of data and am not sure how to do it in an automated way. I am thinking of doing something similar to 'aggregate' but I would like to collect all of the ANOVA results in a way in which I can get to the information from each of the independent ANOVAs. In effect, I would like a data frame with each of the subset identifiers, F and P values in the rows. Or a list of all of the ANOVA summaries or something like that. I would like to do an anova of the form aov(var ~ day) for each subset of data corresponding to "temp" and "line". I have lots of temps and lines and would like to do this in an automated fashion. I know of the aggregate function for doing this kind of thing to compute means etc, but I am not sure how to call an anova in this way. I have looked at "by" and "apply" and have tried various things but am unable to get it to work. Any help would be greatly appreciated. A sample of the dataset is below. Thank you for your time, Kevin temp line day var 12 WMG 1 LD 70.59 12 WMG 1 LD 100.00 12 WMG 1 LD 100.00 12 WMG 1 SD 85.00 12 WMG 1 SD 75.00 12 WMG 1 SD 90.00 12 WMG 2 LD 100.00 12 WMG 2 LD 83.33 12 WMG 2 LD 100.00 12 WMG 2 SD 91.67 14 WMG 1 LD 76.03 . [[alternative HTML version deleted]]
Kevin, I guess this may not have a one line solution (I may be wrong). I would try something like this: -Get all the unique (use 'unique') values in 'temp' -Loop through these values and extract the subset of data and perform the ANOVA on this subset. As an example, code may go something like this: X<-data.frame(temp=c(12,12,12,12,12,14,14,12,14,14,14,14), day=c('LD','LD','SD','LD','SD','SD','LD','SD','LD','LD','SD','SD'), var=rnorm(12)) temp_unique <- unique(X$temp) for (i in seq(temp_unique)){ Y <- X[X$temp==temp_unique[i],] # perform ANOVA here on Y } You may have to append the ANOVA results to another variable to retrieve them. Do the same for 'line' too. -Ashoka. --- Scientist Pacific Northwest National Laboratory Richland, WA On Dec 13, 2007 12:21 PM, Kevin J Emerson <kemerson@uoregon.edu> wrote:> Hello R help-ers, > > > I have a basic question, but I have been playing with it for a while and > haven't quite gotten a hang of how to get it working. I want to perform > multiple one-way ANOVAs on subsets of data and am not sure how to do it in > an automated way. I am thinking of doing something similar to 'aggregate' > but I would like to collect all of the ANOVA results in a way in which I > can > get to the information from each of the independent ANOVAs. In effect, I > would like a data frame with each of the subset identifiers, F and P > values > in the rows. Or a list of all of the ANOVA summaries or something like > that. > > > > I would like to do an anova of the form aov(var ~ day) for each subset of > data corresponding to "temp" and "line". I have lots of temps and lines > and > would like to do this in an automated fashion. I know of the aggregate > function for doing this kind of thing to compute means etc, but I am not > sure how to call an anova in this way. I have looked at "by" and "apply" > and have tried various things but am unable to get it to work. > > > > Any help would be greatly appreciated. A sample of the dataset is below. > > > > Thank you for your time, > > Kevin > > > > > > temp line day var > > 12 WMG 1 LD 70.59 > > 12 WMG 1 LD 100.00 > > 12 WMG 1 LD 100.00 > > 12 WMG 1 SD 85.00 > > 12 WMG 1 SD 75.00 > > 12 WMG 1 SD 90.00 > > 12 WMG 2 LD 100.00 > > 12 WMG 2 LD 83.33 > > 12 WMG 2 LD 100.00 > > 12 WMG 2 SD 91.67 > > 14 WMG 1 LD 76.03 > > . > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- --- Scientist Pacific Northwest National Laboratory Richland, WA [[alternative HTML version deleted]]
Look at ?by and if that is not enough then look at the doBy package. If neither of those give you what you want, then give us more detail to help you with. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Kevin J Emerson > Sent: Thursday, December 13, 2007 1:21 PM > To: r-help at r-project.org > Subject: [R] multiple ANOVAs > > Hello R help-ers, > > > I have a basic question, but I have been playing with it for > a while and haven't quite gotten a hang of how to get it > working. I want to perform multiple one-way ANOVAs on > subsets of data and am not sure how to do it in an automated > way. I am thinking of doing something similar to 'aggregate' > but I would like to collect all of the ANOVA results in a way > in which I can get to the information from each of the > independent ANOVAs. In effect, I would like a data frame > with each of the subset identifiers, F and P values in the > rows. Or a list of all of the ANOVA summaries or something like that. > > > > I would like to do an anova of the form aov(var ~ day) for > each subset of data corresponding to "temp" and "line". I > have lots of temps and lines and would like to do this in an > automated fashion. I know of the aggregate function for > doing this kind of thing to compute means etc, but I am not > sure how to call an anova in this way. I have looked at "by" > and "apply" > and have tried various things but am unable to get it to work. > > > > Any help would be greatly appreciated. A sample of the > dataset is below. > > > > Thank you for your time, > > Kevin > > > > > > temp line day var > > 12 WMG 1 LD 70.59 > > 12 WMG 1 LD 100.00 > > 12 WMG 1 LD 100.00 > > 12 WMG 1 SD 85.00 > > 12 WMG 1 SD 75.00 > > 12 WMG 1 SD 90.00 > > 12 WMG 2 LD 100.00 > > 12 WMG 2 LD 83.33 > > 12 WMG 2 LD 100.00 > > 12 WMG 2 SD 91.67 > > 14 WMG 1 LD 76.03 > > . > > > > > > > > > [[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. >