I collected data on the growth of juvenile fish from 4 different types of crosses using multiple distinct family blocks and I am trying to see if cross type has an effect on growth using linear mixed effects models. I have one fixed factor (Length), 3 categorical random factors (sire, dam and sire/dam interaction) and a continuous random factor (density per tank). As I am relatively new to R and new to mixed effects models, I was wondering if I would have to code the continuous random factor in R differently from the categorical random factors using lme4?

So far I have


is density coded in properly, or would I have to alter it due to the fact that it is a continuous variable?

  • 4
    $\begingroup$ Continuous random factors don't make sense to me. See Douglas Bates, lme4: Mixed-effects modeling with R, pages 1-2: random (or fixed) effects parameters are associated with the levels of categorical covariates. $\endgroup$ – Sergio Jul 3 '14 at 17:55
  • $\begingroup$ You can try to convert it to categorical variable: cut(Density,5). But I agree it doesn't make much sense. $\endgroup$ – user3226167 Mar 20 '19 at 2:17

I'll elaborate on what I think Sergio meant in his comment.

A random effect is always associated with a categorical variable. This categorical variable will most often divide the observations into different observational units (this could for instance be Dam in your data set as it seems reasonable to assume that observations from the same dam are more alike than from different dams. Using something like (1|Dam) will give you a random intercept on that variable.

Using a continuous predictor like Density you can get a random slope on the predictor. Then you'll have to use (Density|Dam) in your model formulae. This will give you a (random) slope, i.e. effect of Density, for each level of Dam.

What you're doing in the above code is forcing Density to be used as a categorical predictor, i.e. making a random intercept for each level (value) of Density. This is probably not what you want.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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