In this chapter, we are going to combine some of the concepts that we covered in Section 2 on longitudinal designs, with Section 3, on mixed-factorial designs. In combining these sections, we can see how we would analyze data when we have two time series that come from same person being measured at different times.

In rehabilitation, for instance we might be interested in the rate at which a person with Parkinson’s disease acquires a skill when they are on or off dopamine-replacement medication. Alternately, we might be interested in hemibody differences between the left and right arms, or left and right legs, over time.

As before however, we will work with our hypothetical dataset in which younger and older adults walked in a virtual environment on four different trials under three different conditions (arbitrary conditions A, B, and C).

1. Modeling Changes in Speed across 4 Trials, in 3 Different Conditions

To account for the fact that participants were tested under each of the three different conditions, we ideally want a random slopes for time within subjects and within conditions. Given the curvilinear trajectory we see above, we also would - ideally - like to model linear and quadratic slopes. Putting this altogether into a “maximal” random-effects model would look something like this:

# Fixed slope random intercepts model ---- 
mod_max<-lmer(speed~ 
                  # Fixed-effects 
                  1+
                time*condition*age_group+
                I(time^2)*condition*age_group+ 
                  # Random-effects 
                  (1+time+I(time^2)|subID)+
                  (1+time+I(time^2)|condition:subID),
                  data=DATA, REML=TRUE)

Before we fit the model, we will mean-center time to create a new variable time.c (\(time_i - \overline{time}\), where \(\overline{time}=2.5\)). Centering time around its mean changes the interpretation of the intercept from being the predicted value on Trial 0 (which does not exist for Trials 1 to 4) to the predicted value at the mid-range of time, \(Trial=2.5\). (Note that Trial 2.5 also doesn’t exist for Trials 1 to 4, but has a more useful interpretation.) Critically, mean centering time serves two other functions:

  1. With interactions in the model, if we mean center continuous variables and use “sum to zero” contrasts for categorical factors, then our results will reflect “main effect” (rather than simple effects) and interactions familiar to many people who have used ANOVA in the past. That is, when 0 = “on average across time” then the Group x Condition interaction can be interpreted as “on average across time”; whereas if 0 = the first time point, then the Group x Condition interaction is actually a special case of that interaction being evaluated at the first time point. (See more about coding choices in Section 5).

  2. Mean-centering our continuous predictors and contrast coding our categorical factors can help reduce multicollinearity between our predictors, especially when polynomials or interactions are present. For instance, imagine \(Time=(1,2,3,4)\) and \(Time^2=(1,4,9,16)\). Across people these two sets of numbers are strongly correlated. However, if I center Time around its own mean of 2.5, then \(Time.c=(-1.5, -0.5, 0.5, 1.5)\) and \(Time.c.sq=(2.25, 0.25, 0.25, 2.25)\). Across people these two sets of mean-centered values are uncorrelated. It gets more complicated than that (e.g., linear and cubic terms will still be correlated following mean centering), but I hope this token example helps to show how mean centering can fight multicollinearity.

# Maximal Random Slopes Model ---- 
# set contrasts for factors to polynomials
options(contrasts = c("contr.sum", "contr.poly"))

mod01<-lmer(speed~ 
                  # Fixed-effects 
                  1+time.c*condition*age_group+
                  I(time.c^2)*condition*age_group+ 
                  # Random-effects 
                  (1+time.c+I(time.c^2)|subID)+
                  (1+time.c+I(time.c^2)|condition:subID),
                  data=DATA, REML=TRUE)
## boundary (singular) fit: see help('isSingular')
summary(mod01)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## speed ~ 1 + time.c * condition * age_group + I(time.c^2) * condition *  
##     age_group + (1 + time.c + I(time.c^2) | subID) + (1 + time.c +  
##     I(time.c^2) | condition:subID)
##    Data: DATA
## 
## REML criterion at convergence: -430.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.3962 -0.4649 -0.0575  0.3358  4.9717 
## 
## Random effects:
##  Groups          Name        Variance  Std.Dev. Corr        
##  condition:subID (Intercept) 1.385e-03 0.037216             
##                  time.c      5.671e-05 0.007531 -1.00       
##                  I(time.c^2) 6.199e-05 0.007873  1.00 -1.00 
##  subID           (Intercept) 1.159e-02 0.107654             
##                  time.c      1.533e-03 0.039158  0.20       
##                  I(time.c^2) 1.647e-03 0.040580 -0.47 -0.77 
##  Residual                    1.184e-02 0.108801             
## Number of obs: 480, groups:  condition:subID, 120; subID, 40
## 
## Fixed effects:
##                                     Estimate Std. Error         df t value
## (Intercept)                         0.850984   0.019091  38.000970  44.575
## time.c                             -0.128325   0.007651  37.998853 -16.773
## condition1                         -0.053484   0.012226 127.394237  -4.375
## condition2                          0.057094   0.012226 127.394238   4.670
## age_group1                         -0.096255   0.019091  38.000970  -5.042
## I(time.c^2)                         0.038229   0.008145  38.000204   4.693
## time.c:condition1                   0.039525   0.006356 226.286749   6.218
## time.c:condition2                  -0.046300   0.006356 226.286749  -7.284
## time.c:age_group1                   0.021425   0.007651  37.998853   2.800
## condition1:age_group1              -0.012807   0.012226 127.394237  -1.048
## condition2:age_group1               0.008615   0.012226 127.394237   0.705
## condition1:I(time.c^2)             -0.002229   0.007096 236.401001  -0.314
## condition2:I(time.c^2)              0.003958   0.007096 236.401001   0.558
## age_group1:I(time.c^2)             -0.013146   0.008145  38.000204  -1.614
## time.c:condition1:age_group1        0.009275   0.006356 226.286749   1.459
## time.c:condition2:age_group1       -0.005200   0.006356 226.286749  -0.818
## condition1:age_group1:I(time.c^2)  -0.013604   0.007096 236.401003  -1.917
## condition2:age_group1:I(time.c^2)   0.010208   0.007096 236.401003   1.439
##                                   Pr(>|t|)    
## (Intercept)                        < 2e-16 ***
## time.c                             < 2e-16 ***
## condition1                        2.51e-05 ***
## condition2                        7.54e-06 ***
## age_group1                        1.16e-05 ***
## I(time.c^2)                       3.44e-05 ***
## time.c:condition1                 2.40e-09 ***
## time.c:condition2                 5.33e-12 ***
## time.c:age_group1                  0.00798 ** 
## condition1:age_group1              0.29683    
## condition2:age_group1              0.48234    
## condition1:I(time.c^2)             0.75370    
## condition2:I(time.c^2)             0.57750    
## age_group1:I(time.c^2)             0.11482    
## time.c:condition1:age_group1       0.14591    
## time.c:condition2:age_group1       0.41418    
## condition1:age_group1:I(time.c^2)  0.05643 .  
## condition2:age_group1:I(time.c^2)  0.15160    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation matrix not shown by default, as p = 18 > 12.
## Use print(x, correlation=TRUE)  or
##     vcov(x)        if you need it
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
VarCorr(mod01)
##  Groups          Name        Std.Dev.  Corr          
##  condition:subID (Intercept) 0.0372163               
##                  time.c      0.0075306 -1.000        
##                  I(time.c^2) 0.0078732  1.000 -1.000 
##  subID           (Intercept) 0.1076538               
##                  time.c      0.0391582  0.196        
##                  I(time.c^2) 0.0405802 -0.469 -0.766 
##  Residual                    0.1088007

Troubleshooting Singular Fit Warnings in our Maximal Model

If you run the model above, you will see a “boundary (singular) fit” warning. Looking at VarCorr(mod01) or the random effects part of the summary() output shows why: the estimated correlation between the random slopes and intercepts within condition:subID are all perfectly \(+/-1.00\), meaning the model is trying to estimate more structure (a full 3x3 variance-covariance matrix, including three separate correlation parameters) than these data can actually support (i.e., if I know your linear slope, I already know your quadratic slope, so I don’t need both terms.

I will discuss a few different ways to troubleshoot this issue below, but first let’s talk about what random slopes these different strata represent:

  • The Person Stratum - (1+time.c+I(time.c^2)|subID): Conceptually, including random slopes at this level is asking about how subjects change over time, on average, across conditions (i.e., does a person generally show a steep and shallow change across trials?). Covariances between these terms thus ask if, across people, e.g., higher intercepts are generally associated with higher slopes, beyond any group-level differences explained by the fixed effects.

  • The Condition Stratum - (1+time.c+I(time.c^2)|condition:subID): Conceptually, including random slopes at this level is asking about how subjects change over time in each specific condition, beyond and group-level differences explained by the fixed effects and beyond any person-level differences captured by the level above. As such, we can think about these random slopes and intercepts as condition specific deviates from a subjects overall trajectory. Covariances between these terms then ask if, across people, e.g., higher intercepts deviates are generally associated with higher slopes deviates.

Examining the singular fit warning we saw above, it looks like there is important variance and covariance in these terms at the person stratum, but we are not able to successfully estimate this variance in the condition stratum. Below, we will walk through a few strategies for troubleshooting this singular fit and explaining what this does to our estimates of the (co)variance at each level.

Removing Random Effects from Complex to Simplest

Given that random effects at the person-level converged just fine, let’s focus on removing random effects from the condition-level first. In this case, VarCorr() shows us this is where the problem lives, but imagine if we had boundary warnings at both levels. In that case, we might still want to start at the condition level because it is also more complicated (i.e., at the person-level, I only have one value per person, whereas at the condition level I have 3). Similarly, I will start with removing higher-order polynomials before removing any lower order polynomials, so we drop the random effect of \(Time^2\) before dropping the random effect of \(Time\).

# Dropping quadratic slope at condition level ----
mod_1a<-lmer(speed~ 
                  # Fixed-effects 
                  1+time.c*condition*age_group+
                  I(time.c^2)*condition*age_group+ 
                  # Random-effects 
                  (1+time.c+I(time.c^2)|subID)+
                  (1+time.c |condition:subID),
                  data=DATA, REML=TRUE)
## boundary (singular) fit: see help('isSingular')
VarCorr(mod_1a)
##  Groups          Name        Std.Dev.  Corr          
##  condition:subID (Intercept) 0.0468894               
##                  time.c      0.0057457 -1.000        
##  subID           (Intercept) 0.1062958               
##                  time.c      0.0391779  0.197        
##                  I(time.c^2) 0.0407377 -0.448 -0.775 
##  Residual                    0.1092314

In this case, our singular fit warning remains because even the linear effect of time is collinear with the intercept at the condition-level. Next, we will drop the linear slope for \(Time\), retaining only the random intercept at the condition-level:

# Dropping all slopes at condition level ----
mod_1b<-lmer(speed~ 
                  # Fixed-effects 
                  1+time.c*condition*age_group+
                  I(time.c^2)*condition*age_group+ 
                  # Random-effects 
                  (1+time.c+I(time.c^2)|subID)+
                  (1|condition:subID),
                  data=DATA, REML=TRUE)

VarCorr(mod_1b)
##  Groups          Name        Std.Dev. Corr          
##  condition:subID (Intercept) 0.046601               
##  subID           (Intercept) 0.106276               
##                  time.c      0.039268  0.175        
##                  I(time.c^2) 0.040677 -0.447 -0.774 
##  Residual                    0.109504

This model converges without a singular fit warning, suggesting that our model is no longer over-parameterized (Matuschek et al., 2017; Bates et al., 2015 “Parsimonious mixed models”). We can also show this empirically through AIC/BIC comparison across models (shown below), where mod_1b has the lowest AIC (\(-519\)) with no random slopes at the condition-level. This reinforces what the singularity warnings above were telling us; our data do not support the complexity of random slopes at the condition level. Conceptually, we can think about this as a relatively stable difference between people across conditions. That is, people tend to have relatively consistent trajectories across conditions, so once we take that into account at the person-level ((1+time.c+I(time.c^2)|subID)), there is not evidence that trajectories consistently vary within people at the condition-level ((1|condition:subID)). Note that this is “absence of evidence” not “evidence of absence”; i.e., we have not proven that there is truly 0 variation between trajectories at the condition level (Bland Altman, 1995).

# comparison across models
anova(mod01, mod_1a, mod_1b)
## refitting model(s) with ML (instead of REML)

In either case, we now have a stable model that converged without error and we can draw inferences about our fixed effects using either the summary() function, if we want to make inferences about individual coefficients, or the anova() function, if we want to make inferences about omnibus effects that require multiple degrees of freedom.

# summary table; requires library("lmerTest") to estimage df and calculate p-values
summary(mod_1b)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## speed ~ 1 + time.c * condition * age_group + I(time.c^2) * condition *  
##     age_group + (1 + time.c + I(time.c^2) | subID) + (1 | condition:subID)
##    Data: DATA
## 
## REML criterion at convergence: -428.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6729 -0.4495 -0.0727  0.3327  4.8984 
## 
## Random effects:
##  Groups          Name        Variance Std.Dev. Corr        
##  condition:subID (Intercept) 0.002172 0.04660              
##  subID           (Intercept) 0.011295 0.10628              
##                  time.c      0.001542 0.03927   0.18       
##                  I(time.c^2) 0.001655 0.04068  -0.45 -0.77 
##  Residual                    0.011991 0.10950              
## Number of obs: 480, groups:  condition:subID, 120; subID, 40
## 
## Fixed effects:
##                                     Estimate Std. Error         df t value
## (Intercept)                         0.850984   0.019091  38.000331  44.575
## time.c                             -0.128325   0.007651  38.000672 -16.773
## condition1                         -0.053484   0.012815 224.600350  -4.174
## condition2                          0.057094   0.012815 224.600350   4.455
## age_group1                         -0.096255   0.019091  38.000331  -5.042
## I(time.c^2)                         0.038229   0.008145  38.000312   4.693
## time.c:condition1                   0.039525   0.006322 271.998836   6.252
## time.c:condition2                  -0.046300   0.006322 271.998836  -7.323
## time.c:age_group1                   0.021425   0.007651  38.000672   2.800
## condition1:age_group1              -0.012807   0.012815 224.600350  -0.999
## condition2:age_group1               0.008615   0.012815 224.600350   0.672
## condition1:I(time.c^2)             -0.002229   0.007068 271.998836  -0.315
## condition2:I(time.c^2)              0.003958   0.007068 271.998836   0.560
## age_group1:I(time.c^2)             -0.013146   0.008145  38.000312  -1.614
## time.c:condition1:age_group1        0.009275   0.006322 271.998836   1.467
## time.c:condition2:age_group1       -0.005200   0.006322 271.998836  -0.822
## condition1:age_group1:I(time.c^2)  -0.013604   0.007068 271.998836  -1.925
## condition2:age_group1:I(time.c^2)   0.010208   0.007068 271.998836   1.444
##                                   Pr(>|t|)    
## (Intercept)                        < 2e-16 ***
## time.c                             < 2e-16 ***
## condition1                        4.29e-05 ***
## condition2                        1.32e-05 ***
## age_group1                        1.16e-05 ***
## I(time.c^2)                       3.44e-05 ***
## time.c:condition1                 1.56e-09 ***
## time.c:condition2                 2.75e-12 ***
## time.c:age_group1                  0.00798 ** 
## condition1:age_group1              0.31868    
## condition2:age_group1              0.50213    
## condition1:I(time.c^2)             0.75272    
## condition2:I(time.c^2)             0.57594    
## age_group1:I(time.c^2)             0.11482    
## time.c:condition1:age_group1       0.14352    
## time.c:condition2:age_group1       0.41151    
## condition1:age_group1:I(time.c^2)  0.05532 .  
## condition2:age_group1:I(time.c^2)  0.14983    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation matrix not shown by default, as p = 18 > 12.
## Use print(x, correlation=TRUE)  or
##     vcov(x)        if you need it
#  ANOVA table using Type III sums of squares; requires library("lmerTest")
anova(mod_1b)

Forcing Random Effects to be Uncorrelated (i.e., 0 Covariance)

An alternative strategy to dropping higher order random effects is to force their covariances to be 0; that is, we can force all of our random slopes and intercepts to be independent of each other. We can do this using the || operator in lme4 when specifying our random effects:

# Zero-correlation alternative ----
mod_orth<-lmer(speed~ 
                  # Fixed-effects 
                  1+time.c*condition*age_group+
                  I(time.c^2)*condition*age_group+ 
                  # Random-effects 
                  (1+time.c+I(time.c^2)|subID)+
                  (1+time.c+I(time.c^2)||condition:subID),
                  data=DATA, REML=TRUE)
## boundary (singular) fit: see help('isSingular')
VarCorr(mod_orth)
##  Groups            Name        Std.Dev.   Corr          
##  condition.subID   I(time.c^2) 2.4451e-06               
##  condition.subID.1 time.c      0.0000e+00               
##  condition.subID.2 (Intercept) 4.6602e-02               
##  subID             (Intercept) 1.0627e-01               
##                    time.c      3.9269e-02  0.175        
##                    I(time.c^2) 4.0676e-02 -0.447 -0.774 
##  Residual                      1.0950e-01

Note that we still get a singular fit warning, but the source of the problem has shifted. Before, we were getting perfectly positive or negative covariances. Now, we have forced the random effects to be uncorrelated, so there is no covariance, and instead the variances are 0.

Even if we drop the quadratic random effect at the condition level, we get a singular fit warning and the variance for time.c at the condition level is estimated to be 0.

# Zero-correlation alternative ----
mod_orth<-lmer(speed~ 
                  # Fixed-effects 
                  1+time.c*condition*age_group+
                  I(time.c^2)*condition*age_group+ 
                  # Random-effects 
                  (1+time.c+I(time.c^2)|subID)+
                  (1+time.c||condition:subID),
                  data=DATA, REML=TRUE)
## boundary (singular) fit: see help('isSingular')
VarCorr(mod_orth)
##  Groups            Name        Std.Dev. Corr          
##  condition.subID   time.c      0.000000               
##  condition.subID.1 (Intercept) 0.046601               
##  subID             (Intercept) 0.106277               
##                    time.c      0.039268  0.175        
##                    I(time.c^2) 0.040678 -0.448 -0.774 
##  Residual                      0.109504

So, forcing the random effects to be uncorrelated has not brought us to a different conclusion in this specific example, but that is not always the case. In many situations, forcing random effects to be independent might solve convergence/singular fit warnings while also allowing you to retain random slopes at different levels. In this particular case, however, there is simply not sufficient variability between conditions within a person - after the fixed effects and person-level variance is taken into account - to justify the added complexity of random slopes at the condition level.

References

Altman DG, Bland JM. Absence of evidence is not evidence of absence. British Medical Journal. 1995 Aug 19;311(7003):485-6.

Bates D, Kliegl R, Vasishth S, Baayen H. Parsimonious mixed models. arXiv preprint arXiv:1506.04967. 2015 Jun 16.

Matuschek H, Kliegl R, Vasishth S, Baayen H, Bates D. Balancing Type I error and power in linear mixed models. Journal of memory and language. 2017 Jun 1;94:305-15.