Re: [R] ANOVA in R

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 14 Sep 2006 - 09:25:32 GMT

Andrew Robinson <A.Robinson@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@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@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@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@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.
Received on Thu Sep 14 19:32:38 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 14 Sep 2006 - 10:30:05 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.