0

I get the following error when I try to predict using lmer

> predict(mm1, newdata = TEST)
Error in terms.formula(formula(x, fixed.only = TRUE)) : 
  '.' in formula and no 'data' argument

This is what my formula looks like

> formula(mm1)
log_bid_price ~ . - zip_cbsa_name + (1 | zip_cbsa_name)

I'm able to summarize the model, but I can't pass it to the predict function.

I would like to be able to automatically generate a formula given the columns of the predictor matrix and then pass that to lmer. How would I do that?

goldisfine
  • 4,742
  • 11
  • 59
  • 83
  • 1
    http://stackoverflow.com/q/28517747/489704 & https://stat.ethz.ch/pipermail/r-sig-mixed-models/2014q3/022691.html might be helpful. – jbaums Mar 26 '15 at 05:02

1 Answers1

1

You might have more success building formula objects like so:

resp <- "log_bid_price"
reserve.coef <- c("zip_cbsa_name")
RHS <- names(data)[-(which(names(data)  %in% c(resp, reserve.coef))]
f <- paste0(paste(resp, paste(RHS, collapse="+"), sep= "~"), " + (1 | zip_cbsa_name)")
mm1 <- lmer(f, data= data)

eg.

paste0(paste("Y", paste(c("a", "b", "c"), collapse= "+"), sep="~"),  "+ (1 | zip_cbsa_name)")
[1] "Y~a+b+c+ (1 | zip_cbsa_name)"

If you wish to do variable selection as you do model selection, you can iterate on this to produce your RHS object

alexwhitworth
  • 4,839
  • 5
  • 32
  • 59