Re: [Rd] inconsistent handling of factor, character, and logical predictors in lm()

2019-08-31 Thread Abby Spurdle
> I think that this misses the point I was trying to make: lm() et al. treat > logical variables as factors, not as numerical predictors. I'm unenthusiastic about mapping TRUE to -1 and FALSE to 1, in the model matrix. (I nearly got that back the front). However, I've decided to agree with your

Re: [Rd] inconsistent handling of factor, character, and logical predictors in lm()

2019-08-31 Thread Fox, John
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 con

Re: [Rd] inconsistent handling of factor, character, and logical predictors in lm()

2019-08-31 Thread William Dunlap via R-devel
> Functions like lm() treat logical predictors as factors, *not* as numerical variables. Not quite. A factor with all elements the same causes lm() to give an error while a logical of all TRUEs or all FALSEs just omits it from the model (it gets a coefficient of NA). This is a fairly common situ

Re: [Rd] inconsistent handling of factor, character, and logical predictors in lm()

2019-08-31 Thread Fox, John
Dear Abby, > On Aug 30, 2019, at 8:20 PM, Abby Spurdle wrote: > >> I think that it would be better to handle factors, character predictors, and >> logical predictors consistently. > > "logical predictors" can be regarded as categorical or continuous (i.e. 0 or > 1). > And the model matrix sho