This is a repost from StackOverflow, I was advised to post here instead, thank you in advance!
I've seen many lmers , but not so many of them of longitudinal data (which is my case right now). The thing is, I have scores (outcome) collected at 2021 and at 2022 (predictor: Year) and in two languages (Spanish and English, predictor: Language). Therefore, my data look like this:
SUBJECT SCORE YEAR LANGUAGE
SUBJ01 200 2021 SPANISH
SUBJ01 250 2022 ENGLISH
SUBJ01 230 2021 SPANISH
SUBJ01 300 2022 ENGLISH
.
.
.
So each subject has 4 scores, 2 per year (2021/2022) and 2 per language (Span/Eng). I'm fitting a lmer but I'm wondering if I should include random slopes as well or stay with random intercepts.
So, basically, I'm thinking about:
lmer(SCORE ~ YEAR * LANGUAGE + (1|SUBJECT), data = data)
or
lmer(SCORE ~ YEAR * LANGUAGE + (1|SUBJECT)+ (1|YEAR:SUBJECT) + (1|LANGUAGE:SUBJECT)
I'm wondering if I should use the random slopes as well or not. Any thoughts would be much appreciated, thanks in advance :)
EDIT:
I've ran two more models,
modYearRandomSlope <- lmer(SCORE ~ LANGUAGE * YEAR + (YEAR|SUBJECT), data = data)
and
modLangRandomSlope <- lmer(SCORE ~ LANGUAGE * YEAR + (LANGUAGE|SUBJECT), data = data)
error: boundary (singular) fit: see help('isSingular')
why do I get an error fitting random slopes for language but not for year? Ps: If I only fit (YEAR|ID) as random slopes, do I still account for the variability within language as well?
I've plotted these two graphs:
SCORE against YEAR by SUBJECT
(ps: take 2020 as 2021 and 2021 as 2022) and
SCORE against LANGUAGE by SUBJECT
If I run an anova between these models and a model with just the subject random intercept, it selects the model with no random slopes, any guesses why?
ModOnlyRandomIntercept <- lmer(SCORE ~ LANGUAGE * YEAR + (1|ID)
I'm trying to model the best fit to account for all these within subjects variability, maybe it's clear now, thanks in advance
YEAR
norLANGUAGE
make a good candidate to be treated as "random effects". I wouldn't consider the second model. $\endgroup$YEAR
andLANGUAGE
effects with an interaction and random intercepts for the students. You can think about adding random slopes as well. For example(YEAR|SUBJECT)
adds a random slope for the effect of time, so that the performance of each student can change from one year to the next. $\endgroup$