[R] Model formula for ols function (rms package)

Mark Seeto markseeto at gmail.com
Wed Apr 13 00:28:37 CEST 2011


Dear R help,

I'm having some trouble with model formulas for the ols function in
the rms package. I want to have two variables represented as
restricted cubic splines, and also include an interaction as a product
of linear terms, but I get an error message.

library(rms)
d <- data.frame(x1 = rnorm(50), x2 = rnorm(50), y = rnorm(50))

ols(y ~ rcs(x1,3) + rcs(x2,3) + x1*x2, data=d)
Error in if (!length(fname) || !any(fname == zname)) { :
  missing value where TRUE/FALSE needed

ols(y ~ rcs(x1,3) + rcs(x2,3) + I(x1*x2), data=d)
Error in if (!length(fname) || !any(fname == zname)) { :
  missing value where TRUE/FALSE needed

I get the same error if I try to fit a model with a quadratic term:

ols(y ~ x1 + I(x1^2), data=d)
Error in if (!length(fname) || !any(fname == zname)) { :
  missing value where TRUE/FALSE needed

ols(y ~ I(x1^2), data=d)  # No error message, but lacks linear term

Is there a way to do these things without first creating new variables
in the data frame?

Thanks,

Mark Seeto
National Acoustic Laboratories



More information about the R-help mailing list