0

I want to fit a mixed model with data containing missing values.

The imputation is performed with mice. How can I compare the original data model fit to the mice one? Example code..

## dummy data

set.seed(123)

DF <- data.frame(countryname = rep(LETTERS[1:10],each = 10), x1 = sample(10,100,replace = T),x2 = sample(5,100,replace = T), y = sample(10,100,replace = T))

# impute NAs
DF[sample(100,10),c("x1")] <- NA
DF[sample(100,10),c("x2")] <- NA
DF[sample(100,10),c("y")] <- NA

#

library(mice)

imp = mice(data = DF, m = 10, printFlag = FALSE)

fit = with(imp, expr=lme4::lmer(y~  x1+x2+ (1 | countryname)))

library(broom.mixed)

pool(fit) 
summary(fit)

## fit to original data


fitor= lme4::lmer(y~  x1+x2+ (1 | countryname),data=DF)

## how to compare model estimates for fit and fitor?

## example output

## 
## =======================================
##              base          w/SES       
## ---------------------------------------
## (Intercept)     0.105        -0.954 ***
##                (0.058)       (0.085)   
## x1        -0.497 ***    -0.356 ***
##                (0.058)       (0.054)   
## x2        -0.079        -0.102 *  
##                (0.043)       (0.040)   

## ---------------------------------------
## R2              0.039         0.157    
## Nobs         4073          4073        
## =======================================
## *** p < 0.001, ** p < 0.01, * p < 0.05

###
Erin
  • 53
  • 6
  • What type of comparison do you want to do exactly? Do you want to compare estimates from a model that just drops missing data rather than imputing? If you are asking for suggestions on how to evaulate your model fit, you should instead ask at [stats.se]. Questions here should be specific programming questions and should have a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 29 '21 at 05:42
  • Yes i want to compare the estimates of the model terms, to see how they change when using data with imputations. I update my example code to include some dummy data – Erin Jul 29 '21 at 05:52
  • 1
    What's wrong with comparing `pool(fit)` to `summary(fitor)` ? – jay.sf Jul 29 '21 at 06:01
  • I am looking for a nice output like the ones obtained with stargazer or texreg. – Erin Jul 29 '21 at 06:04
  • So the question is just about formatting output? Again, it's really not clear what you mean when you say you want to "compare" the results. What exactly is the desired output? – MrFlick Jul 29 '21 at 06:13
  • made another update with example output – Erin Jul 29 '21 at 06:16

0 Answers0