1

I am fitting several models with a different structure. Example of each structure:

> m1 <- glmer(X~Y1+Y2+Y3+(1|B/C),control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)), data = dataset, family=binomial(link="logit"))
> 
> m2 <- glmer(X~Y1*A+Y2*A+Y3*A+(1|B/C),control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)), data = dataset, family=binomial(link="logit"))
> 
> m3 <- glmer(X~(1+Y1|B)+Y2+Y3,control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)), data = dataset, family=binomial(link="logit"))

I am using the same dataset for all of them, and I wish to compare the AIC values, using the AIC() formula in stats package. After running AIC(m1, m2, m3), I get the following warning message:

Warning message:
In AIC.default(m1, m2, m3) :
  models are not all fitted to the same number of observations

I checked the number of observations for all of them, and they are indeed different:

> nobs(m1)
[1] 157278

> nobs(m2)
[1] 150164

> nobs(m3)
[1] 157278

But I don't understand why is this value different, since I am using the exact same dataset (I ran it twice from the beginning, as well as the models, to make sure it was the same for all models).

Could it be related to the formula of the model?

merv
  • 42,696
  • 7
  • 122
  • 170
mtao
  • 249
  • 1
  • 3
  • 13
  • I see that `m2` is the only model using the `A` variable. Are there some `NA`s in the data? This might explain why that specific model can only use a subset of the data. If that is the case, you could use `complete.cases` to subset to only the useable rows. See this question for details: https://stackoverflow.com/questions/4862178/remove-rows-with-all-or-some-nas-missing-values-in-data-frame/4862264 – merv Apr 20 '19 at 15:14

0 Answers0