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

后端 未结 6 1045
栀梦
栀梦 2020-12-01 21:42

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=bino         


        
6条回答
  •  半阙折子戏
    2020-12-01 22:03

    The solution is to use:

    glm1 <-glm(Y ~ X1 + X2 + X3, family = binomial(link = logit), na.action = na.exclude)
    glm2 <-glm(Y ~ X1 + X2, family = binomial(link = logit), na.action = na.exclude)
    
    anova(glm2,glm1)
    

    This will make R include the cases with missing data (NA) in the fitted model. This ensures that datasets are identical across different fit models no matter how missing data is distributed.

提交回复
热议问题