# Suggestions for repeated measures multilevel mixed model?

I'd like to model the variation in type-token ratio (TTR) of texts written by the same person over time. It seems reasonable to me to treat this as a repeated measures mixed model. What I want to test is whether the number of previous comments received has an effect on the increase of complexity of the texts written in the following years.

I tried to model it in R using the lme4 package but I'm not sure how to specify the random effects, since some of them are correlated. The number of comments someone received is associated to the number of people who read the texts (the more read it the more likely it is to have more comments), so I want to check for this interaction as a fixed effect. But it doesn't matter to me if a text has received a lot of comments or reads in absolute terms (I'm interested in the comments->TTR relation), so I thought to allow both sum_reads and sum_previous_comments to vary freely and model them as random effects.

Does it make sense? Is this the correct way to do it?

model <- lmer(TTR ~ year * sum_previous_comments * sum_reads + (1 + sum_reads|author) + (1 + sum_previous_comments |author)


Following @Robert Long's answer, I used this formula (names of variables are slightly different):

model3 <- lmer(TTR ~ date_year * prev_comments_sum * hits_sum + (1 + hits_sum + prev_comments_sum | author))


This is the result of my model:

    REML criterion at convergence: 6911.4

Scaled residuals:
Min      1Q  Median      3Q     Max
-2.5311 -0.5890 -0.1841  0.4103  3.9347

Random effects:
Groups   Name              Variance  Std.Dev. Corr
author   (Intercept)       1.760e+00 1.326714
hits_sum          4.384e-05 0.006621 -1.00
Residual                   3.475e+00 1.864118
Number of obs: 1567, groups:  author, 442

Fixed effects:
Estimate Std. Error         df t value Pr(>|t|)
(Intercept)                           8.910e+01  7.985e+01  9.180e+02   1.116  0.26478
date_year                            -4.213e-02  3.960e-02  9.173e+02  -1.064  0.28764
prev_comments_sum                    -2.788e+00  9.161e-01  4.859e+02  -3.043  0.00247 **
hits_sum                             -2.352e+00  1.519e+00  1.337e+02  -1.548  0.12387
date_year:prev_comments_sum           1.384e-03  4.543e-04  4.857e+02   3.046  0.00245 **
date_year:hits_sum                    1.165e-03  7.537e-04  1.334e+02   1.546  0.12439
prev_comments_sum:hits_sum            3.738e-02  1.451e-02  1.375e+02   2.576  0.01104 *
date_year:prev_comments_sum:hits_sum -1.854e-05  7.195e-06  1.372e+02  -2.577  0.01102 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr) dat_yr prv_c_ hts_sm dt_:__ dt_y:_ pr__:_
date_year   -1.000
prv_cmmnts_ -0.596  0.596
hits_sum    -0.555  0.555  0.355
dt_yr:prv__  0.596 -0.596 -1.000 -0.355
dt_yr:hts_s  0.555 -0.555 -0.355 -1.000  0.355
prv_cmmn_:_  0.401 -0.401 -0.663 -0.660  0.663  0.660
dt_yr:p__:_ -0.401  0.401  0.662  0.660 -0.662 -0.660 -1.000
fit warnings:
Some predictor variables are on very different scales: consider rescaling
convergence code: 0
boundary (singular) fit: see ?isSingular


I guess there is indeed an effect of prev_comments_sum

Second update with new model, because previous one was singular

Formula: TTR ~ date_year * prev_comments_sum * hits_sum + (1 |      author)
Data: no_outliers_filtered

REML criterion at convergence: 6925.6

Scaled residuals:
Min      1Q  Median      3Q     Max
-2.5072 -0.5899 -0.1797  0.4227  4.0042

Random effects:
Groups   Name        Variance Std.Dev.
author   (Intercept) 1.649    1.284
Residual             3.480    1.866
Number of obs: 1567, groups:  author, 442

Fixed effects:
Estimate Std. Error         df t value Pr(>|t|)
(Intercept)                           9.450e+01  7.877e+01  1.459e+03   1.200  0.23048
date_year                            -4.480e-02  3.907e-02  1.459e+03  -1.147  0.25166
prev_comments_sum                    -2.605e+00  8.784e-01  1.413e+03  -2.966  0.00307 **
hits_sum                             -3.020e+00  1.521e+00  1.408e+03  -1.986  0.04723 *
date_year:prev_comments_sum           1.293e-03  4.356e-04  1.413e+03   2.969  0.00304 **
date_year:hits_sum                    1.496e-03  7.543e-04  1.408e+03   1.984  0.04746 *
prev_comments_sum:hits_sum            3.913e-02  1.453e-02  1.404e+03   2.692  0.00719 **
date_year:prev_comments_sum:hits_sum -1.941e-05  7.207e-06  1.404e+03  -2.693  0.00717 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr) dat_yr prv_c_ hts_sm dt_:__ dt_y:_ pr__:_
date_year   -1.000
prv_cmmnts_ -0.596  0.596
hits_sum    -0.533  0.534  0.351
dt_yr:prv__  0.596 -0.596 -1.000 -0.351
dt_yr:hts_s  0.533 -0.533 -0.351 -1.000  0.351
prv_cmmn_:_  0.389 -0.389 -0.656 -0.656  0.656  0.656
dt_yr:p__:_ -0.389  0.389  0.656  0.656 -0.656 -0.656 -1.000
fit warnings:
Some predictor variables are on very different scales: consider rescaling


Thanks again to @Robert Long!

• I see you have updated the question with the results of one of the models in my answer. However the fit is singular so I would suggest trying the model with first model I suggested. If the fit is still singular then you can try using || instead of | and lastly you may need to remove the random slopes. Nov 9, 2020 at 8:14

The model:

model <- lmer(TTR ~ year * sum_previous_comments * sum_reads + (1 + sum_reads|author) + (1 + sum_previous_comments |author)


does not make sense because you are specifying random intercepts for author twice (because you use 1 +  twice for the grouping variable author)

If the intention is to fit random slopes for sum_reads and sum_previous_comments but to have them uncorrelated, then you can use:

(1 + sum_reads | author) + (0 + sum_previous_comments | author)


but if you want to allow for all the random effects for be correlated (as it appears from your question) then use:

(1 + sum_reads + sum_previous_comments | author)


provided that the data supports such a model.

• Thanks! Yes, the data support the model... here is the result: Nov 9, 2020 at 1:09
• You're welcome but the data doesn't support the model. It has a singular fit. Nov 9, 2020 at 8:06
• Thanks! It's my first time using a multilevel mixed model... I updated the answer again, removing the random effects Nov 9, 2020 at 9:09
• That looks much better. Nov 9, 2020 at 9:51