# Specifying mixed model in lmer for a single group reversal design

I have data on a simple experiment performed by one of my students looking at the effect of a single bout of aerobic exercise on working memory. The data are structured as follows:

data.frame':    85 obs. of  5 variables:
$$Participant.id: Factor w/ 21 levels "BM","CC","CL",..: 4 4 4 4 4 5 5 5 5 5 ...$$ Condition     : Factor w/ 3 levels "Baseline","Exercise",..: 1 1 2 3 1 1 1 2 3 1 ...
$$Day : int 1 2 3 4 5 1 2 3 4 5 ...$$ wm_rt         : num  1187 995 841 766 762 ...
\$ wm_accuracy   : num  1.13 1.15 1.07 1 1 1.35 1.2 NA 1.15 1.3 ...


On days 1, 2, and 5 there was no exercise and participants continued their activities as per normal with measurements of working memory taken at mid-day. On day 3 there was an aerobic exercise intervention followed by testing of working memory, and on day 4 there was a reversal (rest day). Edit: so the conditions are Baseline, Exercise, Reversal

I am new to mixed models and would like some feedback on whether I am specifying my model correctly in lmer. I have specified the analysis with a fixed effect for condition and random intercepts for Day and Participants. But I think there is most probably a better way to specify my model.

RImodel <- lmer(wm_rt ~ Condition + (1 | Participant.id) + (1 | Day), data = SipheData)


Any guidance on how I should work with the specification of the model so that I can take into account that performance may improve as a function of practice over time (Days), while identifying whether there is a change from baseline to experiment to reversal (Condition)? Forgive me if this is a simple question, I never had training in mixed models for repeated designs

• What are the tree conditions (only two listed above.) 5*21=105 > 85, so some missing. Why? Can you explain the design better? Or / and post (a link to) the data so we can experiment? – kjetil b halvorsen Oct 9 at 9:42
• 1) Sorry for not supplying enough information. The other level is reversal (i.e. complete rest day). 2.) Yes, there is missing data. Some participants did not pitch up for all testing sessions – Conrad Oct 9 at 9:52
• How is Reversal different from Baseline (presuming Baseline means no exercise)? – Isabella Ghement Oct 9 at 18:28
• @IsabellaGhement the reversal was supposed to be a complete rest day (refrain from all exercise). Whereas for baseline, the participant engages in normal activity as per their usual routine. The exercise condition was a single high-intensity aerobic exercise programme. – Conrad Oct 9 at 19:24

First it is useful to have a look at the data. A simple plot made with ggplot2:

First surprise looking at the plot is that the measurements on the exercise day (3) seems to be lower than baseline. Also note from the plot and data description that variables Day and Condition are fully confounded, so it does not make sense to use Day (as a factor variable) with its own effect, a linear model in Day to model an eventual trend is possible. So I will omit your model term (1 | Day).

library(lme4)
SipheMod0 <- lmer(wm_rt ~ Condition + Day +(1 | Participant.id),
data=SipheData)

summary(SipheMod0)
Linear mixed model fit by REML ['lmerMod']
Formula: wm_rt ~ Condition + Day + (1 | Participant.id)
Data: SipheData

REML criterion at convergence: 796.4

Scaled residuals:
Min       1Q   Median       3Q      Max
-2.80402 -0.54540  0.00676  0.59685  1.71870

Random effects:
Groups         Name        Variance Std.Dev.
Participant.id (Intercept) 124117   352.3
Residual                    24706   157.2
Number of obs: 61, groups:  Participant.id, 17

Fixed effects:
Estimate Std. Error t value
(Intercept)        1258.51      97.67  12.886
ConditionExercise  -108.36      59.90  -1.809
ConditionReversal   -42.44      60.63  -0.700
Day                 -46.92      15.25  -3.077

Correlation of Fixed Effects:
(Intr) CndtnE CndtnR
CondtnExrcs -0.093
CondtnRvrsl  0.037  0.201
Day         -0.399 -0.067 -0.327


A better model might be to include random slopes:

SipheMod1 <- lmer(wm_rt ~ Condition + Day + (1+Day | Participant.id),
data=SipheData)
summary(SipheMod1)
+ >
boundary (singular) fit: see ?isSingular
>
Linear mixed model fit by REML ['lmerMod']
Formula: wm_rt ~ Condition + Day + (1 + Day | Participant.id)
Data: SipheData

REML criterion at convergence: 793.3

Scaled residuals:
Min       1Q   Median       3Q      Max
-2.99084 -0.43479  0.02224  0.55630  1.98117

Random effects:
Groups         Name        Variance Std.Dev. Corr
Participant.id (Intercept) 75049    273.95
Day          1002     31.66   1.00
Residual                   22460    149.87
Number of obs: 61, groups:  Participant.id, 17

Fixed effects:
Estimate Std. Error t value
(Intercept)        1247.10      80.11  15.567
ConditionExercise  -111.34      57.15  -1.948
ConditionReversal   -37.74      58.03  -0.650
Day                 -40.24      16.74  -2.405

Correlation of Fixed Effects:
(Intr) CndtnE CndtnR
CondtnExrcs -0.104
CondtnRvrsl  0.040  0.201
Day         -0.025 -0.063 -0.277
convergence code: 0
boundary (singular) fit: see ?isSingular


I am really not sure what to make of this---was it expected that the exercise effect should be to lower wm_rt? That is what it looks like ...

Some details:

SipheData  <- read.csv("SipheData.csv") # contains missing


As noted in a comment, I guessed there was some errors in the data file, which I have edited accordingly. If that guess is wrong, the analysis must be recomputed.

R code for the plot:

library(ggplot2)
gg <- ggplot(SipheData, aes(x=Day, y=wm_rt, color=Condition))
gg + geom_point() + facet_wrap( ~ Participant.id)

• Thank you for your answer and clarification, this is very helpful. The data file is correct as supplied, the missing values are where participants did not pitch up to the testing venue on that specific day. The expectation was that response time should be quicker (lower values) on the exercise day (day 3). I am a little confounded by the results because it appears there is a steady decrease in wm_rt over days until day 4, with an increase in day 5. These could be testing effects (familiarity with the test), but either way, it doesn't conform to the research hypothesis. – Conrad Oct 9 at 19:48
• One last question, seeing as Day and Condition are fully confounded, should I not perform the analysis using one or the other? For example, I could run ls_means on a model using just Day to perform pairwise comparisons, which I would hypothesise should not be significant for Day 1,2,5 comparisons; but should be significant for comparisons with day 3? – Conrad Oct 9 at 20:12