LMM for Repeated Measures tree ring chronology

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 2000-2020, and treatment begun in the middle.

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 individual annual rings of each tree. Especially since the treatment was applied continuously after since it began, until 2020. 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))  So trying to account for the repeated measures, first added year as a random slope with the random tree, then as an autoregressive term. Then both. Each gave a better AIC than the previous. 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 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)  This appears too simple. Do I need to separate each tree and perform individually? What would be the right code considering my ar1 and random slopes models? Or a different approach completely? Wanted to get some input on whether I am on the right path or not. Any comments suggestions would be valuable. Thanks! 1 Answer Yes, I think you are on the right path. Do I need to separate each tree and perform individually? Yes, we are interested in dealing with autocorrelation within subjects, and here trees are the subjects. What would be the right code considering my ar1 and random slopes models? I would start by plotting the data. This is almost never a bad idea :) In R you could do something like: library(ggplot2) Mont$residuals <- residuals(Mon_tmb0)
ggplot(Mont,
aes(x = year, y = residuals, group = tree)) +
geom_line() +
facet_wrap(~tree)


Then you can apply the acf function separately to the residuals of each tree:

lapply(split(Mont$$residuals, Mont$$Subject), acf)


Also, glmmTMB gives better AIC than nlme overall.

Just be aware that not all packages compute the likelihood in the same way so you might not be able to compare AICs this way.

You can also consider fitting a model with an unstructured covariance matrix. In glmmTMB you would use us() and in nlme I think it's corSymm. Be aware in this case, with 21 time points this will require the software to estimate 210 parameters for the covariance matrix, as opposed to 2 using AR(1). For this reason it is not unusual for this to run into computational problems when there are many time points.