R error which says “Models were not all fitted to the same size of dataset”

I have created two generalised linear models as follows:

glm1 <-glm(Y ~ X1 + X2 + X3, family=binomial(link=logit))

glm2 <-glm(Y ~ X1 + X2, family=binomial(link=logit))

I then use the anova function:

anova(glm2,glm1)

but get an error message:

“Error in anova.glmlist(c(list(object),dotargs), dispersion = dispersion, :
models were not all fitted to the same size of dataset”

What does this mean and how can I fix this? I have attached the dataset at the start of my code so both models are working off of the same dataset.

Leave a Comment