This is my first endeavor into linear mixed models, and I haven't found an example that uses a fully repeated measures design, so I was hoping that I could get some help.
I have a dataset that looks like this:
Mydata <- data.frame(
Subject = c(1,2,3,4,5),
Condition =c(rep(c("High", "Low"), each=50)),
Size =c(rep(c(8, 20, 50, 70, 100), each=10)),
Estimate =c(10, 12, 15, 18, 8, 12, 12, 10, 14, 8, 25, 36, 29, 45, 38, 28, 36, 29, 40, 36, 68, 75, 65, 78, 60, 69, 74, 63, 80, 62, 85, 99, 84, 100, 90, 82, 99, 88, 102, 85, 140, 150, 190, 180, 200, 130, 160, 190, 190, 210, 8, 6, 9, 8, 10, 7, 7, 8, 9, 12, 20, 21, 25, 30, 26, 22, 23, 22, 30, 25, 45, 40, 50, 60, 55, 40, 45, 55, 57, 58, 70, 80, 60, 80, 75, 75, 78, 65, 60, 70, 100, 115, 120, 125, 110, 110, 105, 120, 120, 110)
)
Mydata <- Mydata[order(Mydata$Subject),]
In the data, I have 2 within-subjects factor:
- Set size (8, 20, 50, 70, 100); 2 repetitions per level (Note: this is a continuous/ordinal numeric variable)
- Condition (High vs. low)
Each subject was presented with a dot array of different set sizes (8, 20, 50, 70, 100), with 2 repetitions per set size, and they had to estimate how many dots they saw. Each subject did the same task twice with different levels of calibration (high vs. low). Hence, each row represents a single trial based on condition and set size.
My goal is to examine if there are main effects of Condition and Set size, and if there is a Condition x Set Size interaction.
From what I have read, a linear mixed model is well-suited especially if I want to model Subjects as a random factor (and Condition and Set Size as fixed effects), and to minimize data aggregation across levels of a factor.
My first set of questions are: Can I use the trial-level data as they are now? My actual dataset has 15 levels of set size and 8 repetitions per set size. Or would it be more appropriate to aggregate across repetitions to obtain a mean value per set size before I fit the mixed model?
After reading up on how to use lme4 and nlme, I tried to fit the following random-intercepts-only models using lme4 (I also fitted them with nlme):
baseline.model <- lmer(Estimate ~ 1 + (1|Subject), Mydata)
To test for main effect of set size
setsize.model <- lmer(Estimate ~ Size + (1|Subject), Mydata)
anova(baseline.model, setsize.model)
To test for main effect of condition
condition.model <- lmer(Estimate ~ Size + Condition + (1|Subject), Mydata)
anova(setsize.model, condition.model)
To test for interaction
interaction.model <- lmer(Estimate ~ Size*Condition + (1|Subject), Mydata)
anova(condition.model, interaction.model)
My second set of questions are: Are these models appropriately fitted? Should I be considering nested models, e.g., Size and Condition within Subject? Should I also consider random slopes as it seems reasonable to suppose that the effects of Size and/or Condition, or even Size x Condition may vary across Subjects. I thought this may be critical if I trial-level data tend to be correlated within subjects. If so, is this the correct way to fit it?
interaction.model <- lmer(Estimate ~ Size*Condition + (1 + Condition + Size + Condition*Size|Subject), Mydata)
My final question is: With an expected Size x Condition interaction, how can I perform post-hoc tests to examine if there is an effect of Condition for each level of Size (I'm hypothesizing Condition effects for larger set sizes, but not for small set sizes)? I've tried the following, but the parameter estimates are identical for the 2 levels of Conditions for each level of Size, so I was wondering if the model was fitted wrongly in the first place:
lsmeans(interaction.model, ~ Condition | Size, adjust="tukey")
I would greatly appreciate any advice! If there is anything that I should clarify, please let me know, and I will provide as much details as I can.
Thanks!