I understand that having a continuous or numeric variable as a random effect in a mixed effects model doesn't make much sense (e.g., see here).
But what I'm wondering is if lme4::lmer
or nlme::lme
in R purposefully prevent you from doing so...
Specifically, what I'm asking is: if I supply lmer
(or lme
) any non-factor (non-categorical) variable as a random effect, does the function automatically treat it as a factor?
Inserting factor()
directly into lmer (as is the usual method when using lm
) produces 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 doesn't specify whether said grouping factor needs to be a factor (or is that perhaps implicit from the word choice)?
I understand it's fairly simple to just create a new factor class variable directly from my data, but I'm just curious if it's actually necessary when using lmer
(or lme
).