I would like to build regression models for a number of different exposure variables and show the results using ggplot.Predict of the rms package. While creating regression models automatically works very well, Predict does not seem to like a variable as argument (mod is the ols model):

exp.var <- c("exp1", "exp2", "exp3")

for (exp in exp.var) {
   mod <- ols(formula(paste("endpoint ~ ", exp, sep="")), data=data)
   p.mod <- Predict(mod, exp)

This results in the error message:

Error in Predict(mod, exp) : 
  predictors(s) not in model: exp

When I use Predict(mod, exp1), it works without any problem.

Is it possible to either:

  • pass on a predictor name as variable to Predict
  • evaluate the variable in a way that Predict does not "see" the variable but only the predictor name (eval does not work)

Use Predict(mod, name=exp).

Note that pure programming questions are best asked on stackoverflow.com.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.