The error is generated in the last line of code shown here from predict.lm > predict.lm function (object, newdata, se.fit = FALSE, scale = NULL, df = Inf, interval = c("none", "confidence", "prediction"), level = 0.95, type = c("response", "terms"), terms = NULL, na.action = na.pass, pred.var = res.var/weights, weights = 1, ...) { tt <- terms(object) if (!inherits(object, "lm")) warning("calling predict.lm(<fake-lm-object>) ...") if (missing(newdata) || is.null(newdata)) { mm <- X <- model.matrix(object) mmDone <- TRUE offset <- object$offset } else { Terms <- delete.response(tt) m <- model.frame(Terms, newdata, na.action = na.action, xlev = object$xlevels) #MORE LINES DELETED HERE...
As written, if newdata is specified but it doesn't contain every term in the original data frame, then an error is thrown. But for predict.lm to predict values for a term, i.e., type = "term", those terms cannot be in the newdata vector. -John -- View this message in context: http://r.789695.n4.nabble.com/predict-lm-type-terms-question-tp4641665p4641951.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.