I want to compare these two linear models by anova:

a<-c(-10:-1 , 1:10)
b<-sample(1000, 20, replace = FALSE)
ID<-rep(c("no","bo"), each=10)
dataf<-data.frame(a, b, ID)


Unfortunately when I run the test I got this warning where it says:

Warning message:In anova.lmlist(object, ...) :
  models with response ‘"dataf[11:20, ]$a"’ removed because response differs from model 1

May be the I should use another test. Can somebody help me to better understand and solve this?

  • $\begingroup$ 1. How does ggplot2 come into this anywhere? It seems to have no relation to the actual question. $\qquad\quad\:\:$ 2. Normally a question phrased as an issue with errors in code would be closed as off topic here unless there's an actual statistical issue. However, ultimately it turns out that there's both a statistical and a (resulting) code issue here. $\endgroup$
    – Glen_b
    Commented Sep 7, 2015 at 7:57

1 Answer 1


Your problem is that a partial F-test analysis of variance (ANOVA) is applied to models on the same observations, and you have specified two different sets of observations (this is actually mentioned in the help on anova).

Further, such models should be nested (though this isn't explained in the help).

If you fit a sequence of larger linear models (i.e. where each model is a special case of the next), then anova in R will give F-tests for a null where the smaller model applies against the alternative of the larger model for each pair of consecutive models.

There's no way to make your code example work as is and still have it be ANOVA, because your underlying premise doesn't apply; there's no theory giving an F-test for non-nested models. (There are some approaches for comparing and even testing non-nested models, however.)

The specific complaint you're getting is because the response variable is different in the two models (note that anova doesn't check your models are nested, but that doesn't mean you don't need it for the ANOVA to work).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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