I have a dataset that contains some missing values (on independent variables). I’m fitting a glm model :
f.model=glm(data = data, formula = y~x1 +x2, "binomial", na.action =na.omit )
After this model I want the ‘null’ model , so I used update
:
n.model=update(f.model, . ~ 1)
This seems to work, but the number of observations in both models differ (f.model n=234; n.model n=235). So when I try to estimate a likelihood ratio I get an error: Number of observation not equal!!
.
Q: How to update the model so that it accounts for the missing values?
Although it is a bit strange that na.action =na.omit
dit not solve the NA problem. I decided to filter out the data.
library(epicalc) # for lrtest
vars=c(“y”, “x1”, “x2”) #variables in the model
n.data=data[,vars] #filter data
f.model=glm(data = data, formula = y~x1 +x2, binomial)
n.model=update(f.model, . ~ 1)
LR= lrtest(n.model,f.model)
If someone has a better solution or an argument way na.action
in combination with update
results in unequal observations, your answer or solution is more than welcome!