Skip to content
Prev 15334 / 20628 Next

Using lme function in R in a brain imaging study

Dear IIlgim,

If I'm understanding your design correctly, then you have you crossed random effects -- you can think of participants as being nested within trials or trials as being nested within participant. I would recommend using lme4 instead of nlme for such designs.

I am not familiar with the specifics of fNIRS, but I'm guessing that the statistical analysis is somewhat similar to EEG, at least in terms of sensor placement, even if the units of measurement and temporal resolution are quite different. As such, it might make sense for you to look at resources discussing mixed models for EEG / ERP, including posts like this https://stat.ethz.ch/pipermail/r-help/2015-September/432520.html (by me).

You will also find a lot of resources from psycholinguistics, but the literature there often uses the terms "items" and "subjects" instead of "trials" and "participants", but these are essentially the same thing. In your case, you only have three trials per conditions, so you can't model that as a random effect (grouping variable). There are all sorts of rules of thumb for how many levels you need, but I generally wouldn't let something be a grouping variable (see below) with less than about 10 levels.

I'm not sure I would treat your n-back conditions as categorical -- if you treat n-back as a continuous variable, then you can make predictions about the response for arbitrary n. It depends on whether or not you expect the response to change in a linear fashion. If you don't, then treat the different types of n-back as categorical. (There are other ways to address non-linearity, but they may be a bit much for now.)  

There are also seems to be some terminological confusion around "random variables". You need to distinguish between the grouping variables (the stuff behind the vertical bar |), which are always discrete, and the "random slopes" (the stuff before the vertical bar |), which are predictors like any other and can be categorical or continuous. The trick is to read the vertical bar | as "by", so 

predictor | participant

is just "allow the strength of this predictor to vary by participant".

All that said, I would try something like the following (assuming you have enough participants to fit all these parameters):

library(lme4)

model <- lmer(nirs_response ~ NbackType * Trial * roi + (1 + NbackType |  participant), 
 data=oxyHbConditionandTrialCellbyCell, REML=FALSE)

model.gender <- update(model, . ~ . * gender)

anova(model, model.gender)

----

"roi" stands for "region of interest". For computational simplicity and model parsimony, I would not try to do things by sensor, but rather by groups of adjacent sensors (ROIs).  You can average across sensors to produce a single value for each ROI, which will also simplify things a bit.

Best,
Phillip