# Mixed models - Intuition of correlated discrete random effects

I'm looking into this source and I'm trying to understand what does it mean to have "positive correlation between the random effects when the variables aren't continuous"

In the link there is this example where the model is built using the continuous variable Days and the discrete Subject (I assume this from the output).

What if both Days and Subject would have been discrete? In that case, what could be the meaning of having a correlation of 0.081 between Days and subject could mean? (assuming that they were both discrete vars)

They provide the variance covariance plot $$\Sigma$$ which seems to show the covariance between each pair of day and subject. Positive correlation implies that by increasing the var1 (Days) the var2 increasing as well(Subject), but how this could be understood when the variables are discrete?

If we name the variables in your model as follows reaction = a + b * days + (c + d * Days) * Subject, the correlation is the correlation between c and d. That means that based on the data, the correlation for these two variables was estimated at 0.08, and, accordingly, the estimates for c and d were adjusted for that.

It's maybe easiest to think about what this means for estimates for Subjects for which you have no data. If there is no data, this model would fit a c and d with the means and the uncertainty derives from the standard deviation from your output. Makes sense, from the data it follows that for all subjects, these are typical values. But, now comes the subtle twist, the uncertainties for c and d are not independent, so when c is higher, d is also typically higher (assuming positive correlation).

This is not really affected by days being a discrete variable. The formulas and the explanation are the same.

• I like the idea of thinking a subject without data but I struggle to understand how your model is equivalent to the lmer(Reaction ~ 1 + Days + (1 + Days|Subject)). In essence how would you interpret such correlation- I'm not looking on how is estimated Commented Jun 26 at 11:17
• I would interpret as; subjects that have a high reaction also tend to have a higher response to the days increasing. In other words, if they are slow to begin with, they will also more quickly get slower when the number of days is increasing.
– Gijs
Commented Jun 26 at 11:48

They provide the variance covariance plot which seems to show the covariance between each pair of day and subject. Positive correlation implies that by increasing the var1 (Days) the var2 increasing as well(Subject), but how this could be understood when the variables are discrete?

There is nothing terribly strange about the correlation between two factor variables. It can be assessed outside the mixed model framework in several ways, for example a chi-square test of independence.

In a mixed model it is not uncommon for a time variable to be categorical - it is a good way to assess a curvilinear association. And it is perfectly reasonable to use that variable as a random slope. Let's take a look at that by categorising the Days variable in the sleepstudy dataset. First we fit the model with Days numeric:

library(lme4)

fm06 <- lmer(Reaction ~ 1 + Days +(1+Days|Subject), sleepstudy)
summary(fm06)


which produces this:

Random effects:
Groups   Name        Variance Std.Dev. Corr
Subject  (Intercept) 612.10   24.741
Days         35.07    5.922   0.07
Residual             654.94   25.592
Number of obs: 180, groups:  Subject, 18

Fixed effects:
Estimate Std. Error      df t value Pr(>|t|)
(Intercept)  251.405      6.825  17.000  36.838  < 2e-16 ***
Days          10.467      1.546  17.000   6.771 3.26e-06 ***


Now we split the Days variable into 3 categories and name that variable DaysC:

sleepstudy$DaysC = cut(sleepstudy$Days,
breaks = c(-Inf, 3, 6, Inf),
labels = c("Early", "Middle", "Late"),
right = TRUE)
fm06a <- lmer(Reaction ~ 1 + DaysC +(1+DaysC|Subject), sleepstudy)
summary(fm06a)


which produces:

Random effects:
Groups   Name        Variance Std.Dev. Corr
Subject  (Intercept)  663.3   25.75
DaysCMiddle  882.4   29.70    0.36
DaysCLate   1415.7   37.63    0.33 0.85
Residual              748.8   27.36
Number of obs: 180, groups:  Subject, 18

Fixed effects:
Estimate Std. Error      df t value Pr(>|t|)
(Intercept)  267.375      6.874  17.000  38.898  < 2e-16 ***
DaysCMiddle   35.740      8.561  17.000   4.175 0.000635 ***
DaysCLate     68.035     10.145  17.000   6.706 3.69e-06 ***


The very interesting thing here is that the correlations are so high compared to those for the model with numeric Days. Hmmm, I'm not sure if I can explain it, but it could be related to the apparent nonlinearity of the trajectories (as shown by considerable differences in the fixed effect estimates for DaysC)