Error in ANOVA for model comparison
Dear Rosario, Because of missing data in the additional variable PHt, the two models weren't fit to the same subset of valid observations -- the default in lm() is to use complete cases for the variables in the model. A mechanical solution is to use na.omit() to filter your data set, only for the variables you intend to use, to produce a data set with no NAs. Then you'll fit each model to a consistent subset of valid cases. Of course, if you have a substantial amount of missing data, complete-case analysis is probably a poor strategy. I hope this helps, John -------------------------------- John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Rosario Garcia Gil Sent: January-21-11 9:31 AM To: r-help at r-project.org Subject: [R] Error in ANOVA for model comparison Hello I am trying to compare two models using anova(), however I get a message error (see below). In the net I only found some information on certain library(car) for which one should use anova with A capital letter (Anova instead of anova), but I could not find car library as it says it does not exist.
Model <- lm(interceptG ~ SW + TSC + FSC + PF + SlopeG + K,
data=AllTrait)
Model1 <- lm(interceptG ~ SW + TSC + FSC + PF + SlopeG + PHt,
data=AllTrait) Error in anova.lmlist(object, ...) : models were not all fitted to the same size of dataset I have NA in the datafile, should that be the problem? Kind regards and thanks in advance Rosario
______________________________________________ R-help at 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.