In specification of a Linear Mixed Model (LMM) I encountered an issue with specifying the model, specifically the random effects. I fear I don't know whether the issue is about model specification in general or rather about the implementation in R. I guess most of you are experts in both so it doesn't hurt asking it here. Also I guess the issue can be resolved on a more abstract level without having a reproducible example with actual data. If not I'll provide one.
Let's assume I have participants react as quickly as possible to a number of images presented at different presentation times (3 levels). Each participant is assigned to only one presentation time, i.e., PT varies between participants. Each image however is presented at each PT, counterbalanced among participants. In my model I want to predict the reaction time from presentation duration (just as an example to understand the concept).
In the R package
lme4 (maybe it is more about R after all), I specify PT as a factor and depending on my hypothesis specify a sensible contrast.
My model would be
mod1 <- lmer(RT ~ 1 + PT + (1 + PT|image), data= ...). I do not need a random intercept (let alone slope) for participant, because each participant is in a different PT level, right?
Upon reading an introductory article by Brauer and Curtin (2017) on specifying LMMs, I encountered the following footnote (fn 8, p. 7): "This will be true in R only if the predictors are coded as numeric variables. Although R users have the possibility to code their variables as factors, this practice should be avoided when estimating LMEMs as lme4 has problems analyzing predictor variables that are coded as factors."
Well this does not sound too good. I thus tried to follow that advice. If your factor has two levels the situation does not seem that complicated. You do not specify PT as a factor and recode the PT variable into values that represent the contrast you want to have. The model specification in R would look the same,
mod2a <- lmer(RT ~ PT + (1 + PT|image), data= ...).
With three levels you need to introduce dummy variables that represent your contrasts. This I still get. But how I specify the random effects now?
I tried the following for treatment contrasts
mod2b <- lmer(RT ~ 1 + PT1vs2 + PT1vs3 + (1 + PT1vs2|image) + (1 + PT1vs3|image), data= ...).
This however does not give me the same random effects structure as
mod2a <- lmer(RT ~ PT + (1 + PT|image), data= ...), with PT being treatment coded. So there is either something wrong with my specification or this is exactly the issue the footnote warns about. But I cannot figure it out, I assume the former.
Reference: Brauer, M., & Curtin, J. J. (2017). Linear Mixed-Effects Models and the Analysis of Nonindependent Data: A Unified Framework to Analyze Categorical and Continuous Independent Variables that Vary Within-Subjects and/or Within-Items. Psychological Methods. doi: 10.1037/met0000159