Reputation: 53
I have been provided with the following formulas and need to find the correct lme4 code. I find this rather challenging and could not find a good example I could follow...perhaps you can help?
I have two patient groups: group1 and group2. Both groups came to the lab 4 times for testing (4 VISITs) and during each of these visits, their memory was tested 4 times (4 RECALLs). The memory performance should be predicted from Age, Sex and two sleep parameters, which were assessed during each VISIT.
Thus Level 1 should be the RECALL (index i), Level 2 the VISIT (index j) and Level 3 the subject level (index k).
Level 1:
MEMSCOREijk = β0jk + β1jk * RECALLijk + Rijk
Level 2:
β0jk = γ00k + γ01k * VISITjk + U0jk
β1jk = γ10k + γ11k * VISITjk + U1jk
Level 3:
γ00k = δ000 + δ001 * SLEEPPARAM + V0k
γ10k = δ100 + δ101 * SLEEPPARAM + V1k
Thanks so much for your thoughts!
Upvotes: 0
Views: 385
Reputation: 735
Something like this should work:
lmer(memscore ~ age + sex + sleep1 + sleep2 + (1 | visit) + (1 + sleep1 + sleep2 | subject), data = mydata)
By adding sleep1
and sleep2
in (1 + sleep1 + sleep2 | subject)
you will be allowing the effects of the two sleep parameters to vary by participant (random slopes), and have a random intercept (more on that next sentence).(1 | visit)
will allow random intercepts for each visit (random intercepts would model data where different visits had a higher or lower mean memscore), but not random slopes; I don't think that you want random slopes for the sleep parameters by visit - were they only measured one time per visit? If so, there would be no slope variation to model, I believe.
Hope that helps! I found this book very useful:
Snijders, T. A. B., & Bosker, R. J. (2012). Multilevel analysis: an introduction to basic and advanced multilevel modeling (2nd ed.): Sage.
Upvotes: 3