I have a pretty simple question.

Is it worth including a binary variable as a random effect within a mixed effect model?

For example, the fixed effect of a binary variable tells the mean effect between 0 and 1 in a regression. If I also include that as a random effect in a mixed effect model, what does this tell me?

For example, things like a rat's sex don't vary from year to year to year. They are fixed across time. But if I included it as a random effect, how would I interpret the correlation and standard deviation.

For example

    happiness = sex + money + ( sex | country)

If I am interpreting the output correctly, it is telling me the rate at which the differences between sex are not statistically different. Which seems somewhat obvious and not needed.

In other words, is there anything to be gained by including a fixed effect (non time varying) as a random effect in a model in terms of inference?


2 Answers 2


Variables used for the estimation of random slopes must be time-varying. If the variable is fixed over the study (i.e. sex), the slope will not be random (this applies only to random slopes, not random intercepts).

Fitzmaurice, G.M., Davidian, M., Verbeke G., Molenberghs, G. Longitudinal Data Analysis, 1st Edition. CRC Press, 2008. ISBN 978-1584886587, pp. 84 (subheading 'Reduced form')

Note: if a time-constant variable is included in an interaction term with a time-varying variable, estimation of random slopes based on that term become possible.


The term (sex | country) puts a random slope on sex, meaning that the model estimates a mean sex effect, + deviations of the mean sex effect for each country.

Yes, it's worth doing this and standard practice if you have reasons to expect that an effect of interest might be different in each group, regardless if the effect is produced by a binary or any other variable type.

ps: note that, if you write this syntax in lme4, it will estimate both the random slope and a normal random intercept (mean changes between countries).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.