[R] ANOVA in R

Russell Compton rmc095 at bham.ac.uk
Thu Sep 14 11:43:32 CEST 2006


Andrew, Peter,

Thanks both for the help, that's exactly what I was after. 

It is for a one-way ANOVA, looking at identifying differentially expressed
genes across time in a microarray dataset. Also, one of the datasets I'm
working with is unbalanced, so that additional code will be most useful.

Thanks again,

Russell Compton

-----Original Message-----
From: pd at pubhealth.ku.dk [mailto:pd at pubhealth.ku.dk] On Behalf Of Peter
Dalgaard
Sent: 14 September 2006 10:26
To: Andrew Robinson
Cc: Russell Compton; r-help at stat.math.ethz.ch
Subject: Re: [R] ANOVA in R

Andrew Robinson <A.Robinson at ms.unimelb.edu.au> writes:

> Try
> 
> test <- data.frame(day.1=c(2,3,3,6,1), 
>      day.4=c(7,2,4,6,3),
>      day.8=c(2,8,7,8,4))
> 
> test
> 
> test.long <- reshape(test, direction="long", 
> 	  varying=c("day.1","day.4","day.8"),
> 	  v.names="response",
> 	  timevar="day",
> 	  times=names(test))
> 
> test.long$day <- factor(test.long$day)
> 
> test.long
> 
> aov(response ~ day, data=test.long)


Was a one-way ANOVA intended? He never said.

On a more elementary level,

y <- with(test, c(day.1,day.4,day.8))
day <- factor(rep(c(1,4,8),each=5)) # or gl(3,5,labels=c(1,4,8))
sub <- factor(rep(1:5,3))           # or gl(5,1,15)

print(data.frame(y,day,sub)) # just to show the point

anova(lm(y~day))        # 1-way
anova(lm(y~day+sub))    # 2-way

# This could be better for unbalanced designs:

drop1(lm(y~day+sub),test="F")

 

 
> 
> I hope that this helps,
> 
> Andrew
> 
> 
> On Thu, Sep 14, 2006 at 09:23:13AM +0100, Russell Compton wrote:
> > Despite having used R on a daily basis for the past two years, I'm
> > encountering some difficulty performing an ANOVA on my data. What I'm
trying
> > to do is the following:
> > 
> >  
> > 
> > Given data such as:
> > 
> >  
> > 
> > Day 1    Day 4    Day 8
> > 
> > 2          7          2
> > 
> > 3          2          8          
> > 
> > 3          4          7
> > 
> > 6          6          8
> > 
> > 1          3          4
> > 
> >  
> > 
> > I want to use ANOVA to determine if there is a significant change over
the
> > three days. In other stats packages I have used, I can just select this
data
> > and run the ANOVA function and get the F and p values. However in R, the
> > anova function seems to only work with a fitted model, eg. Linear
> > regression. This function seems to assume there is a relationship such
as
> > day1~ day 4 + day 8, but in my case there isn't - I just want to perform
an
> > ANOVA without regression. If anyone could point me in the right
direction
> > I'd greatly appreciate it,
> > 
> >  
> > 
> > Thanks
> > 
> > 
> > 	[[alternative HTML version deleted]]
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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.
> 
> -- 
> Andrew Robinson  
> Department of Mathematics and Statistics            Tel: +61-3-8344-9763
> University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
> Email: a.robinson at ms.unimelb.edu.au         http://www.ms.unimelb.edu.au
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list