I understand that having a continuous or numerical variable as a random effect in a mixed effects model does not make much sense (for example, see here ).
But I wonder if lme4::lmeror nlme::lmein R purposefully prevents you from doing this ...
In particular, I ask: if I put lmer(or lme) any non-factorial (non-categorical) variable as a random effect, does the function automatically process it as a factor?
Inserting factor()directly into lmer (as commonly used when using it lm) causes the following error:
lmer(y ~ z + (1|factor(x)), data = dat)
Error: couldn't evaluate grouping factor factor(x) within model frame: try adding grouping factor to data frame explicitly if possible
Although the above error mentions adding a grouping factor directly to the data, it does not indicate whether the grouping factor should be a factor (or perhaps implied from a word choice)?
I understand that it is quite simple to create a new factor class variable directly from my data, but I'm just wondering if this is really necessary when using lmer(or lme).
source
share