In the code below, models 1 & 2 work just fine and produce the same result. Model 4 works fine as well.
require(rms)
mtcars$ind <- I(mtcars$gear==4)
dd <- datadist(mtcars)
options(datadist = "dd")
ols(as.formula(mpg ~ wt + cyl + gear + cyl:gear), data=mtcars) #1
ols(as.formula(mpg ~ wt + cyl + gear + cyl * gear), data=mtcars) #2
ols(as.formula(mpg ~ wt + cyl + gear + cyl:ind), data=mtcars) #3
ols(as.formula(mpg ~ wt + cyl + gear + cyl * ind), data=mtcars) #4
Model 3 gives the following error
Error in if (!length(fname) || !any(fname == zname)) { :
missing value where TRUE/FALSE needed
The output of traceback() is
2: Design(eval.parent(m))
1: ols(as.formula(mpg ~ wt + cyl + gear + cyl:ind), data = mtcars)
I tried to set debug() on ols and rms:::Design and didn't get very far!! I ran into this issue when I was using rms::lrm() and realized that it was happening in ols as well.
Why does #4 work while #3 does not? They have the same terms in the formula where one uses :
, the other uses *
. Thx.