Solved – How to do two way repeated Measures ANOVA using aov() in R

repeated measures

I am attempting a 2-way ANOVA with repeated measures using the aov() function in R. I am trying to compare average heights ("X1" and "X2") of algae by treatment ("CODE") and site over time ("MONTH"). The data I entered into R is already averaged. Therefore each row = one observation per treatment, per code, per month (1-60). I have created a column called "ID" to identify each observation (1-60).

head(HNME1)
ID MONTH SITE CODE  X1       X2
1   OCT  BPT   C+  3.526667 3.440000
2   OCT  BPT   C-  3.296667 3.540000
3   OCT  BPT   U+  2.146667 1.000000
4   OCT  BPT   U-  3.146667 3.016667
5   OCT  BPT   P   2.827778 2.122222
6   OCT  FLC   C+  3.620000 1.990000

However, when running this code:

"x1.aov<-aov(X1 ~ MONTH * SITE * CODE + Error(ID/(SITE * CODE)), data=HNME1)"

I am not receiving any p-values in my ANOVA summary.
I have read other forums telling me to make the ID values into factors.

"HNME1$ID <- factor(HNME1$ID)"

I have tried this and received the error: "Error () model is singular." However, I do not have any gaps or missing data values. I am not sure what else could be going wrong.
Just messing around – I tried a one-way ANOVA with "MONTH" where "ID" was and this produced p-values…

Any suggestions/ help would be much appreciated! Thank you.

Best Answer

It is because you use averages for each condition. R thinks each unique combination of month, site and code has N=1 so it has not clue about the variance or the N. So, you should go back to the values that you had before you averaged and give those to R.

for example:

ID MONTH SITE CODE  X1       X2
1   OCT  BPT   C+  5.526667 5.440000
2   OCT  BPT   C+  1.526667 6.440000
3   OCT  BPT   C+  2.526667 2.440000
4   NOV  BPT   C+  6.526667 3.440000
5   NOV  BPT   C+  4.526667 2.440000
6   NOV  BPT   C+  0.526667 3.440000

...etc. Looks like it will be a very long table :)

Related Question