1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ "lme4 has problems analyzing predictor variables that are coded as factors" Only having read this out of context I'd challenge this statement. Anyway, I'm missing the participant ID in your model. I think you need crossed random effects for grouping by image and by participant. $\endgroup$ – Roland Jul 25 '18 at 11:06
  • $\begingroup$ I'm not familiar with the claim about factors by Curran and Bauer - I don't believe it but I may be wrong. But the equivalent model specification would be: + (0 + PT1vs1 + PT1vs2 + PT1vs3 | image). Placing them in separate parentheses forces them to be uncorrelated, which isn't necessary since each image undergoes the different PTs. But I think you can simply use the original factor variable. $\endgroup$ – Heteroskedastic Jim Jul 25 '18 at 11:11
  • $\begingroup$ Additionally, if individuals repeat tasks, you can have a random effect by persons. In fact, you should be able to add + (0 + PT1vs1 + PT1vs2 + PT1vs3 || participant). Because a single participant only does one PT, those random effects cannot be correlated, hence the double bar/pipe. The double pipe (||) should be equivalent to your specification of one indicator variable per parenthesis. But this would be more adequate for participants. It would permit the random effect of PT to have different variances depending on which category a participant fell under. $\endgroup$ – Heteroskedastic Jim Jul 25 '18 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.