I'm trying to fit an lmer model with a random intercept and slope for each participant and I am struggling to identify the error of my setup.
Background: participants repeatedly attempted a putt before and after one of two possible interventions. Participants were randomized to how many putts they attempt before and after the intervention (putt_assignment, Factor: 3 levels 34, 50, 67), and which intervention they got (intervention_assignment, Factor: 2 levels a, b). Data is coded in wide format with unique participant IDs (pid, Factor 93 levels), session ids (session, Factor: 2 levels n_1, n_2), and the outcome variable (accuracy, Double) was a hit or miss for each attempt that has been converted into a session level accuracy value in the wide form of the data such that each row represents one session for one participant.
If I understand everything I've read so far, the design is nested repeated measures.
Here is a preview data in wide format:
A tibble: 186 x 5
# Groups: pid, session [186]
accuracy intervention_assignment session pid putt_assignment
<dbl> <fct> <fct> <fct> <dbl>
1 0.265 a n_2 n_120469 67
2 0.235 b n_2 n_130757 67
3 0.794 b n_2 n_138425 67
4 0.706 a n_2 n_154923 67
5 0.5 a n_2 n_190402 67
6 0.0588 b n_2 n_194232 67
7 0.735 b n_2 n_211431 67
8 0.706 a n_2 n_242107 67
9 0.676 a n_2 n_277723 67
10 0.559 b n_2 n_333301 67
# … with 176 more rows
Here is how I've been instructed to setup the lmer model with random intercept and slopes by participants:
lmer(accuracy~intervention_assignment*putt_assignment*session+(1+session|pid),data=ds,REML=FALSE)
but the +session
portion of the random effects model generates:
Error: number of observations (=186) <= number of random effects (=186) for term (1 + session | pid); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable
Is this because there is only one observation per participant:session combination? Ultimately, I would like to model to allow for each participant to have their own intercept (baseline(session 1) accuracy is different) and their own intervention effect across sessions (some increase accuracy, some decrease accuracy). I've read so many primers on mixed effects and lmer modeling and I'm struggling to diagnose why I can run the model with (1|pid)
for a random intercept, but can't get the random slopes element to work.
Edit: Since posting this I finally found this post with the exact same issue. Once I built the model in nlme using:
lme(accuracy~intervention_assignment*putt_assignment*session, random = ~session|pid, method = "REML", data = ds )
I didn't get the error. Is this just an issue with Lme4 as suggested by the answer in the linked post? Or a deeper issue with if it is appropriate to only use two observations to define random slopes? If the second, is there a more robust method for me to use on the long version of the data where the outcome variable is coded as a hit (1) or miss (0) for each putt attempted?