Having my first go at R and stats.
I sampled and analyzed tree rings for different measures (width, density, etc.). There are 3 treatments, 3 plot per treatment, and 5 trees per plot. The ring time series is between 2000-2020, and the treatment started in the middle and continued thereafter consecutively through the next years, until 2020.
I would like to test whether there are differences between the 3 treatments in each year.
The data looks like this (showing only 'width' as the dependent variable here):
'data.frame': 1197 obs. of 13 variables:
$ trtmnt : Factor w/ 3 levels "Control",..: 3 3 3 3 3 3 3 3 3 3 ...
$ plot : Factor w/ 9 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$ tree : Factor w/ 57 levels "3006","3015",..: 1 1 1 1 1 1 1 1 1 1 ...
$ year : Factor w/ 21 levels "2000","2001",..: 21 20 19 18 17 16 15 14 13 12 ...
$ width : int 61 70 74 54 100 100 80 137 121 76 ...
I would like to account for the repeated measurements of the years of each tree.
For that, I tried a LMM in nlme (as well as similar code in glmmTMB, adjusted) with different approaches:
Mon_0 <- lme(fixed = width ~ trtmnt*year, random = ~ year | tree,
data = Mon)
Mon_1 <- lme(fixed = width ~ trtmnt*year, random = ~ 1 | tree,
data = Mon,
correlation = corAR1(form = ~ year | tree))
Mon_2 <- lme(fixed = width ~ trtmnt*year, random = ~ as.integer(year) | tree,
data = Mont,
correlation = corAR1(form = ~ year | tree))
Considering the repeated measures, I initially added year as a random slope with the random effect of tree, then as an autoregressive term. Then both. Each gave a better AIC than the previous. Yet, the model fit of predicted-observed is better for the first model (higher R2). Also, glmmTMB gives better AIC than nlme overall.
Mon_tmb0 <- glmmTMB(formula = width ~ trtmnt*year + (year | tree),
data = Mont,
family = gaussian(link = 'identity'), REML = TRUE)
After the LMM, a pairwise with Tukey in emmeans
.
I will note that I was not able to completely figure how to compute properly an autocorrelation test (to understand if it is even appropriate to use an AR term).
acf.1 <- residuals(model)
appears lacking.
Do I need to separate and perform acf
for each tree individually? What would be the right code considering my ar1
and random slopes models? Or is a different approach completely necessary here?
Wanted to get some input on whether I am on the right path or not. Any comments suggestions would be valuable. Thanks!