R: likelihood ratio test comparing two models, however missing data made the two models not in the same dimension -
i'm trying likelihood ratio test between 2 models.
glm.model1 <- glm(result ~ height + weight ) glm.model2 <- glm(result ~ hight + weight + speed + speed : height + speed : weight ) require(lmtest) <- lrtest(glm.model1, glm.model2)
and got following error:
error in lrtest.default(glm.model1, glm.model2) : models not fitted same size of dataset
i know of "speed" data missing, none of height , weight data missing, since model 2 includes variable "speed" model 1 doesn't, model 2 has datapoints got deleted glm due missingness. when likelihood ratio test between model 2 , model 1, data dimension not equal, , end error message above. there way can datapoints deleted in model 2, in reduced model can include script delete same datapoint in order keep dimension of data same?
here's i've tried:
1) add na.action = na.pass keep missing data in model 2, doesn't work.
2) tried:
glm.model1 <- glm(result ~ height + weight + speed - speed ) ## work , gets rid of sample "speed" missing, cheating.
here's summary of each model:
summary(glm.model1)
...... null deviance: 453061 on 1893 degrees of freedom residual deviance: 439062 on 1891 degrees of freedom aic: 15698 number of fisher scoring iterations: 2
number of fisher scoring iterations: 2
summary(glm.model2)
...... null deviance: 451363 on 1887 degrees of freedom residual deviance: 437137 on 1882 degrees of freedom (6 observations deleted due missingness) ## want at: aic: 15652 number of fisher scoring iterations: 2
how can @ observations deleted , write script delete same observations in other model? thanks!
you can use subset
argument of glm()
function:
glm.model1 <- glm(result ~ height + weight, subset=!is.na(speed) )
Comments
Post a Comment