I'm new to linear mixed-effects models and I was wondering if I could get some help in getting my model to properly work.
I have an example dataset:
data_ex <- data.frame( pnum = c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10),
group = c("1","1","1","2","2","2","3","3","3","1","1","1","2","2","2","3","3","3","1","1","1","2","2","2","3","3","3","1","1","1"),
day = c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3),
score_x = floor(runif(30, min=0, max=101)),
score_y = floor(runif(30, min=0, max=101)))
My research question: I'm interested in if there are group differences in the effect of x on y. However, each participant has been measured three times (on three days). I however do not care about this effect.
What I first did was just check the group differences on the effect of x on y like so:
lm(score_y ~ score_x * group, data_ex)
However then I realized that I am inflating my data by not accounting for the repeated measures of my participants.
I opted for aggregating my entire data across variable "day", but then I would also lose a lot of data.
Thus I wanted to try mixed-effects models. As I understand, I could account for days and participants as random slopes. I'm however not entirely sure if this would be correct for my research question.
Would I be able to answer my research question if I model my data like this?
m <- lmer(y_scorescore_y ~ x_scorescore_x * group + (1 + x_scorescore_x | pnum ) + (1|day), data=data = data_ex)
m_small <- lmer(y_scorescore_y ~ x_scorescore_x + (1 + x_scorescore_x | pnum ) + (1|day), data=data = data_ex)
anova(m, m_small)
Thank you for your help!