# crossed factors with random effect in R

After trying and testing a lot I cannot figure out what I am doing wrong. My set-up is as follows: I have measures of the growth per day of tree stem diameters. Trees were grown in two treatment chambers. One is control with ambient conditions (Amb) and the second is climate change simulator with elevated CO2 and temperature (Elev). Within each treament chamber half of the trees were subjected to well-watered conditions (Wet) and half to mildly drought stress (Dry). So I have two crossed treatments; CO2 treatment (with factors Amb and Elev) and watertreatment (with factors Wet and Dry). Growth per day was measured on three trees per treatment for 82 days. So I have 82 repeated measures of growth per day for 16 trees in total. Because growth per day can vary between trees I want to add tree subject as a random effect.

My data is structured in a data.frame named summarytable (note that treatment is 1 to 4 for the four different combinations of treatments and DOY is Day of Year, the day of measurement but currently not used in my model):

     DOY tree watertreatment CO2treatment treatment growth_per_day
1    118    1              2            2         4      0.0050000
2    119    1              2            2         4      0.0140000
3    120    1              2            2         4      0.0200000
4    121    1              2            2         4      0.0060000
5    122    1              2            2         4      0.0060000
6    123    1              2            2         4      0.0380000
7    124    1              2            2         4     -0.0050000
8    125    1              2            2         4      0.0290000
9    126    1              2            2         4      0.0240000
10   127    1              2            2         4      0.0230001
11   128    1              2            2         4      0.0310000
12   129    1              2            2         4      0.0320000
13   130    1              2            2         4      0.0440000
14   131    1              2            2         4      0.0440000
15   132    1              2            2         4      0.0880000
16   133    1              2            2         4      0.0610000
17   134    1              2            2         4      0.0260000
18   135    1              2            2         4      0.0410000
19   136    1              2            2         4      0.0520000
20   137    1              2            2         4      0.0650000
21   138    1              2            2         4      0.0390000
22   139    1              2            2         4      0.0540000
23   140    1              2            2         4      0.0370000
24   141    1              2            2         4      0.0480000
25   142    1              2            2         4      0.0780000
26   143    1              2            2         4      0.0400000
27   144    1              2            2         4      0.0630000
28   145    1              2            2         4      0.0480000
29   146    1              2            2         4      0.0649990
30   147    1              2            2         4      0.0570000
31   148    1              2            2         4      0.0790000
32   149    1              2            2         4      0.0430000
33   150    1              2            2         4      0.0440000
34   151    1              2            2         4      0.0260000
35   152    1              2            2         4      0.0470000
36   153    1              2            2         4      0.0210000
37   154    1              2            2         4      0.0220000
38   155    1              2            2         4      0.0320000
39   156    1              2            2         4      0.0430000
40   157    1              2            2         4      0.0300000
41   158    1              2            2         4      0.0470000
42   159    1              2            2         4      0.0450000
43   160    1              2            2         4      0.0440000
44   161    1              2            2         4      0.0360000
45   162    1              2            2         4      0.0580000
46   163    1              2            2         4      0.0560000
47   164    1              2            2         4      0.0430000
48   165    1              2            2         4      0.0390000
49   166    1              2            2         4      0.0480000
50   167    1              2            2         4      0.0320000
51   168    1              2            2         4      0.0370000
52   169    1              2            2         4      0.0350000
53   170    1              2            2         4      0.0270000
54   171    1              2            2         4      0.0420000
55   172    1              2            2         4      0.0290000
56   173    1              2            2         4      0.0320000
57   174    1              2            2         4      0.0370000
58   175    1              2            2         4      0.0310000
59   176    1              2            2         4      0.0220000
60   177    1              2            2         4      0.0290000
61   178    1              2            2         4      0.0320000
62   179    1              2            2         4      0.0270000
63   180    1              2            2         4      0.0300000
64   181    1              2            2         4      0.0300000
65   182    1              2            2         4      0.0310000
66   183    1              2            2         4      0.0170000
67   184    1              2            2         4      0.0300000
68   185    1              2            2         4      0.0270000
69   186    1              2            2         4      0.0290000
70   187    1              2            2         4      0.0220000
71   188    1              2            2         4      0.0210000
72   189    1              2            2         4      0.0297800
73   190    1              2            2         4      0.0254700
74   191    1              2            2         4      0.0267900
75   192    1              2            2         4      0.0150400
76   193    1              2            2         4      0.0154000
77   194    1              2            2         4      0.0241300
78   195    1              2            2         4      0.0147900
79   196    1              2            2         4      0.0143900
80   197    1              2            2         4      0.0173800
81   198    1              2            2         4      0.0224300
82   199    1              2            2         4      0.0207400
83   118    2              2            2         4     -0.0080000
84   119    2              2            2         4     -0.0080000
85   120    2              2            2         4      0.0190000


I want to check whether CO treatment and water treatment has an affect and whether there is an interactive effect and also check later on whether post-hoc test reveal one-by-one treatment differences.

If I understand correctly I need to include a random term to check whether differences between trees are not the reason for seeing statistical significant differences.

I have used the following formulation:

aov(growth_per_day~CO2treatment*watertreatment+Error(tree/(CO2treatment*watertreatment)),data=summarytable)


According to what I have read and my understanding this should give the correct outcome, but I get the error Error() model is singular. I am not sure this has to do with statistics I am misinterpreting or rather a coding issue. I already checked whether my data contains NA values and made sure tree, watertreatment, CO2 treatment and treatment are factors. Also the data is nicely balanced with 82 observations for each tree.

Despite the error I can generate an output from the aov:

Error: tree
Df  Sum Sq Mean Sq F value  Pr(>F)
CO2treatment                 1 0.02791 0.02791   6.254 0.02787 *
watertreatment               1 0.04457 0.04457   9.986 0.00822 **
CO2treatment:watertreatment  1 0.00347 0.00347   0.778 0.39521
Residuals                   12 0.05356 0.00446
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: Within
Df Sum Sq  Mean Sq F value Pr(>F)
Residuals 1296 0.7271 0.000561


But here again I am puzzled looking at the degrees of freedom. I would expect to have 82-3 degrees of freedom for my Residuals because I have 82 measurements per tree and the two treatments and their interaction (which gives minus 3). So for now I think this outcome doesn't reflect what I want to study.

Any help or advice would be much appreciated, because I have spend a lot of time looking things up already, but nothing helped me solving my issues. Also whether I am doing something wrong in a statistical way or rather a coding way would help enormously.