Closed ahcombs closed 10 months ago
Thanks for the report Aidan and I'm almost certain you have diagnosed the root cause properly — I've sprouted quite a few gray hairs trying to properly support factors! I will work on this as soon as I am able, it should be fixable as I already replace factors with their dummies in the other parts of the formula.
Hi there,
It doesn't appear to be possible to include random slopes for factor variables, which makes it pretty involved to model random slopes for a categorical variable with more than two levels (in my real data, I have individuals nested within cities, and I want to include a random slope for each city).
Reprex with the wage data is below.
The error appears to emerge because
e$data
, produced bywb_prepare_data()
, contains dummy variable columns named for each factor level (in the below example,south_namessouth
, a 0/1 col) while the random intercept term ine$fin_formula
is still(south_names|id)
. The error arises when the prepped data is passed toprepare_lme4_formula()
, specifically whenprepare_lme4_formula()
callslme4::mkReTrms)_()
. My best guess is that the name discrepancy created by breaking out the factor variable into dummy variable columns is preventinglme4::mkReTrms)_()
from finding the relevant random slopes columns.