[R] Simple 2-Way Anova issue in R

Jeremy Miles jeremy.miles at gmail.com
Mon Nov 9 00:43:47 CET 2009


If I've understood correctly, you have cell sizes of 1.  This is not enough.

ANOVA compares within group variance to between group variance, and
your within group variances are zero.

You need more data, or to collapse some cells.

Jeremy




2009/11/8 znd <zackdaugherty at mail.com>:
>
> Hello, I'm new to R and have been following many guides including the two-way
> anova (http://www.personality-project.org/r/r.anova.html).  Using that
> walkthrough including the supplied data I do str(data.ex2) and receive the
> appropriate types of data as follows:
>> str(data.ex2)
> 'data.frame':   16 obs. of  4 variables:
>  $ Observation: int  1 2 3 4 5 6 7 8 9 10 ...
>  $ Gender     : Factor w/ 2 levels "f","m": 2 2 2 2 2 2 2 2 1 1 ...
>  $ Dosage     : Factor w/ 2 levels "a","b": 1 1 1 1 2 2 2 2 1 1 ...
>  $ Alertness  : int  8 12 13 12 6 7 23 14 15 12 ...
>
> aov.ex2 = aov(Alertness~Gender*Dosage,data=data.ex2)
>
> summary(aov.ex2)
>
> Outputs:
>              Df  Sum Sq Mean Sq F value Pr(>F)
> Gender         1  76.562  76.562  2.9518 0.1115
> Dosage         1   5.062   5.062  0.1952 0.6665
> Gender:Dosage  1   0.063   0.063  0.0024 0.9617
> Residuals     12 311.250  25.938
>
> However, when I got to use my data that I made in csv format I have to tell
> R to interpret my factors which are year and depth as factors...
> datafilename="C:/Rclass/hmwk1pt2.csv"
> data.ex2=read.csv(datafilename,header=T)
> data.ex2$Year<-as.factor(data.ex2$Year)
> data.ex2$Depth<-as.factor(data.ex2$Depth)
> data.ex2
> str(data.ex2)
>
> This outputs what I would expect:
>
>> str(data.ex2)
> 'data.frame':   12 obs. of  4 variables:
>  $ Year      : Factor w/ 3 levels "1999","2000",..: 1 1 1 1 2 2 2 2 3 3 ...
>  $ Depth     : Factor w/ 4 levels "10","15","20",..: 1 2 3 4 1 2 3 4 1 2 ...
>  $ Replicate1: num  14.3 15.1 16.7 17.3 16.3 17.4 18.6 20.9 22.9 23.9 ...
>  $ Replicate2: num  14.7 15.6 16.9 17.9 16.4 17.2 19.6 21.3 22.7 23.3 ...
>
> But something is not causing my anova to carry through...this is what I
> have.
>
> ANOVA = aov(Replicate1~Year*Depth,data=data.ex2)
> summary(ANOVA)
>
> which outputs:
>
>> summary(ANOVA)
>            Df  Sum Sq Mean Sq
> Year         2 143.607  71.803
> Depth        3  17.323   5.774
> Year:Depth   6   2.587   0.431
>
> There is no F-value or Pr(>F) columns.
>
> I also can't boxplot this correctly, again following the example at that
> website above they have:
>
> boxplot(Alertness~Dosage*Gender,data=data.ex2)
>
> which outputs:
>
> http://old.nabble.com/file/p26258684/87o3uicpf6dt4kkdyvfv.jpeg
>
> My code is:
>
> boxplot(Replicate1~Year*Depth,data=data.ex2)
>
> which outputs:
>
> http://old.nabble.com/file/p26258684/gik02vyhvvbmcvw3ia2h.jpeg
>
> This is incorrect, it's multiplying my factors but I thought that when I did
> the str() on my data it recognized the Year and Depth as factors, not
> numbers or integers.
>
> My csv file is:
> http://old.nabble.com/file/p26258684/hmwk1pt2.csv hmwk1pt2.csv
>
> Any help on what is going one would be greatly appreciated because I need to
> perform one-way, two-way, nested, and factorial anovas but I first need to
> solve this problem before I can continue.
>
>
> --
> View this message in context: http://old.nabble.com/Simple-2-Way-Anova-issue-in-R-tp26258684p26258684.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.
>



-- 
Jeremy Miles
Psychology Research Methods Wiki: www.researchmethodsinpsychology.com




More information about the R-help mailing list