I am quite new to R and is setting up a mixed effect model. I have a large dataset and want to include 3 random effects that are nested. I have data from 2 years, 2021 and 2022, and there are rounds of experiments every year, that are named experiment 1, 2 and 3 and so on on each year.
The problem is that for the random effects, the number of experiment rounds are calculated wrong, as the numbering of the experiments are the same for each year. How can I include “year” for the random effects so the number of groups will be correct?
This is a example of the set up of my df :
Site Square Round Year Variable Outcome
1 1 1 2021 2 20
1 1 2 2021 2 10
1 1 3 2021 2 39
1 2 1 2021 2 22
1 2 2 2021 2 25
1 2 3 2021 2 29
1 1 1 2022 1 13
1 1 2 2022 1 15
1 1 3 2022 1 12
1 2 1 2022 1 10
1 2 2 2022 1 9
1 2 3 2022 1 15
2 1 1 2021 2 40
2 1 2 2021 2 33
2 1 3 2021 2 42
2 2 1 2021 2 29
2 2 2 2021 2 35
2 2 3 2021 2 50
2 1 1 2022 1 25
2 1 2 2022 1 23
2 1 3 2022 1 22
2 2 1 2022 1 26
2 2 2 2022 1 24
2 2 3 2022 1 23
This is my code:
model8<-lmer(Outcome ~ Variable + (1|Site/Square/Round), data=example)
summary(model8)
And here is the output:
boundary (singular) fit: see help('isSingular')
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: Outcome ~ Variable + (1 | Site/Square/Round)
Data: example
REML criterion at convergence: 150.7
Scaled residuals:
Min 1Q Median 3Q Max
-2.44099 -0.39914 -0.02029 0.45294 2.26577
Random effects:
Groups Name Variance Std.Dev.
Round:(Square:Site) (Intercept) 0.00 0.000
Square:Site (Intercept) 0.00 0.000
Site (Intercept) 78.12 8.838
Residual 37.96 6.161
Number of obs: 24, groups: Round:(Square:Site), 12; Square:Site, 4; Site, 2
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 5.000 7.408 1.813 0.675 0.575
Variable 13.083 2.515 21.000 5.201 3.73e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr)
Variable -0.509
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
Please do not pay attention to the singularity error, this is just an example. Look at the number of observations:
Number of obs: 24, groups: Round:(Square:Site), 12; Square:Site, 4; Site, 2
Here the number of rounds is incorrect, it should be 24 (same as number of observations). How should I specify year for the random effect Round? Is it at all possible or I am on the wrong track? The Sites and Squares are the same year after year, but the rounds are unique for each year/the dataset. Or is it just easier to change the Rounds to 1, 2, 3 at 2021 and then 4,5,6 on year 2022? I am just in the process of setting up my model, and I have started with the random effects.
Thanks a lot for input!
Liv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.