Skip to content

inconsistent handling of factor, character, and logical predictors in lm()

1 message · John Fox

#
Dear Bill,

Thanks for pointing this difference out -- I was unaware of it.

I think that the difference occurs in model.matrix.default(), which coerces character variables but not logical variables to factors. Later it treats both factors and logical variables as "factors" in that it applies contrasts to both, but unused factor levels are dropped while an unused logical level is not.

I don't see why logical variables shouldn't be treated just as character variables are currently, both with respect to single levels (whether this is considered an error or as collinear with the intercept and thus gets an NA coefficient) and with respect to $levels.

Best,
 John