# Binary variable shows twice in random effects when random intercept excluded

When I use lmer of lme4 to fit a random one-variable slope model with random intercept excluded, both levels of the one-variable slope are reported with random variances, as if the slope had two variables (i.e., as if it were a three-level treatment effect). How should I interpret this?

## Detailed Example:

Here is what the model looks like with both random slope and intercept included. Everything works as expected: in line 7, the binary variable Cond1 shows up with just one effect (Cond1hetero, the upper level of the two-level categorical)...

> RT_log.CVquestA.lmer=lmer(RT_log~Cond1+(1+Cond1|Subject),data=basedata)
> summary(RT_log.CVquestA.lmer)
...
Random effects:
Groups   Name        Variance Std.Dev. Corr
Subject  (Intercept) 0.026121 0.16162
Cond1hetero 0.001366 0.03696  -0.47
Residual             0.028667 0.16931
Number of obs: 3321, groups:  Subject, 19

Fixed effects:
Estimate Std. Error t value
(Intercept)  6.57461    0.03725  176.49
Cond1hetero  0.02815    0.01052    2.68

Correlation of Fixed Effects:
(Intr)
Cond1hetero -0.412


Here is what the model looks like when I remove the random intercept. Note the extra variance term on line 6 of the block below (i.e., we now see an effect for Cond1non-hetero, the reference level of the Cond1 categorical variable, in addition to the upper level Cond1hetero). I don't know how to interpret or use this output!

> RT_log.CVquestB.lmer=lmer(RT_log~Cond1+(0+Cond1|Subject),data=basedata)
> summary(RT_log.CVquestB.lmer)
...
Random effects:
Groups   Name            Variance Std.Dev. Corr
Subject  Cond1non-hetero 0.02612  0.1616
Cond1hetero     0.02184  0.1478   0.98
Residual                 0.02867  0.1693
Number of obs: 3321, groups:  Subject, 19

Fixed effects:
Estimate Std. Error t value
(Intercept)  6.57461    0.03725  176.49
Cond1hetero  0.02815    0.01052    2.68

Correlation of Fixed Effects:
(Intr)
Cond1hetero -0.412


The general answer to your question (how to fix various parts of a statistical model involving a categorical term varying across groups) is ?dummy.

Let's suppose that the model with random effects (Cond1|subject), with 3 variance-covariance parameters (variation among groups in the response to the "homo" condition; variation among groups in the "hetero"-"homo" response difference; covariance between these two terms) seems too complex (for some reason) and you want to simplify it.

Depending on what you thought made sense, you could

(1) allow the "intercepts" but not the "slopes" (I'm using quotation marks here because among-factor-level differences don't really feel like slopes to me, although at the model matrix level they really are) to differ among groups: this is just the random-intercept model, (1|Subject) [1 parameter]

(2) allow just the slopes (i.e., the "hetero"-"homo" response difference) but not the intercepts to vary among subjects: this is (0+dummy(Cond1,"hetero")|Subject), and is closest to what you've done above. [1 parameter]

(3) allow both the intercepts (responses in the "homo" condition) and slopes ("hetero"-"homo" differences) to vary, but assume they're uncorrelated: (1|Subject)+(0+dummy(Cond1,"hetero")|Subject) [2 parameters]

(4) allow the responses in the "homo" condition and the responses in the "hetero" condition to vary in an uncorrelated way; (0+dummy(Cond1,"homo")|Subject) + (0+dummy(Cond1,"hetero")|Subject) [2 parameters]

• One reason to be suspicious of strategies that drop the correlation between random effect terms is that the model then depends on the contrast coding (i.e. #3, which corresponds to treatment coding, vs. #4, which corresponds roughly to sum-to-zero coding).
• The reason I'm particularly suspicious of #2 is that it is the most asymmetric of all of the options in how it treats the two levels.

The (just-now-modified) ?expandDoubleVerts man page discusses this concept:

Because || works at the level of formula parsing, it has no way of knowing whether a variable is a factor. It just takes the terms within a random-effects term and literally splits them into the intercept and separate no-intercept terms, e.g. (1+x+y|f) would be split into (1|f) + (0+x|f) + (0+y|f). However, || will fail to break up factors into separate terms; the dummy function can be useful in this case, although it is not as convenient as ||. }

Example:

library("lme4")
m <- ~ x + (x || g)
expandDoubleVerts(m)
set.seed(101)
dd <- expand.grid(f=factor(letters[1:3]),g=factor(1:200),rep=1:3)
dd\$y <- simulate(~f + (1|g) + (0+dummy(f,"b")|g) + (0+dummy(f,"c")|g),
newdata=dd,
newparams=list(beta=rep(0,3),
theta=c(1,2,1),
sigma=1),
family=gaussian)[]
m1 <- lmer(y~f+(f|g),data=dd)
VarCorr(m1)
m2 <- lmer(y~f+(1|g) + (0+dummy(f,"b")|g) + (0+dummy(f,"c")|g),
data=dd)
VarCorr(m2)


If you wanted to fit an uncorrelated model with three treatment levels, your suggestion in the comments

(1|Subject) + (0+dummy(Condition, "hetero")|Subject) +
(0+dummy(Condition,"homo")|Subject)


would work.

I would strongly recommend against removing variation in one of the treatment levels from consideration because of lack of significance; this is analogous to dropping non-significant random factors from the model that are intrinsic parts of the experimental design ("sacrificial pseudoreplication, sensu Hurlbert 1984), and is generally deprecated.

• Thanks for your help! In actuality, what I have is a 3-level categorical variable Condition. Its levels are hetero, homo, and oddman. To code an uncorrelated model using categorical treatment coding, would the following be correct: (1|Subject) + (0+dummy(Condition, "hetero")|Subject) (0+dummy(Condition,"homo")|Subject)? – clarpaul Mar 9 '16 at 18:33
• And if I want to remove one of the treatment levels from consideration (because of lack of significance), would the following be correct: (1|Subject) + (0+dummy(Condition,"hetero")|Subject)? Let me know if you think I need to generate additional questions for this, or add to my question above. I will do so if you think it benefits the overall community. – clarpaul Mar 9 '16 at 18:36
• Thanks for your guidance regarding the appropriate terms. Regarding removal of variation in a treatment level from the model: I am using AIC to guide the search for a best model, and am using the results to draw conclusions about which effects are of significance. The only purpose of dropping the treatment level is to show that it results in a significant reduction in AIC (i.e., the distinction made by that treatment level is not significant. – clarpaul Mar 12 '16 at 21:39

Both models have the same model fit, but a different parametrisation.

Cond1hetero from model 1 is the difference between Cond1hetero and Cond1non-hetero. Cond1hetero from model 2 is the direct effect of Cond1hetero