fit.measure error when using runMI on a multiple imputed data set.

52 views
Skip to first unread message

Mohamed Yusuf

unread,
Feb 7, 2022, 2:49:18 PM2/7/22
to lavaan
I am trying to get the results of my sem model which uses a dataset that is multiple imputed. I have had no success with this. when I declare `fit.measures = TRUE` in the summary function, I get the below error. Does anybody have a solution for this?

Error in .local(object, ...) : unused argument (fit.measures = TRUE)

# download pacman package if not installed, otherwise load it
if(!require(pacman)) install.packages(pacman)

# loads relevant packages using the pacman package
pacman::p_load(
  dplyr,
  semTools,
  mice )       

# make 10 dataset using mice

boys_imp <- boys %>% 
  mice(.,
       m = 3, 
       cluster.seed = 1234)

# set up model
fit <-  "sem =~ age + bmi + hc + hgt + wgt"

# run model
out1 <- semTools::runMI(fit, 
                        data = nhanes_imp,
                        miPackage = "mice",
                        fun="sem",
                        seed = 12345)


# get results
summary(out1)

# lavaanList (0.6-10.1668) -- based on 3 datasets (3 converged)

# Latent Variables:
#   est.ave
# sem =~                   
# age               1.000
# bmi               0.287
# hc                0.778
# hgt               6.802
# wgt               3.676

# Variances:
#   est.ave
# .age               1.530
# .bmi               5.387
# .hc                6.660
# .hgt              39.388
# .wgt              55.099
#  sem              45.935

# get fit measures
summary(out1,
        fit.measures = TRUE
)

# Error in .local(object, ...) : unused argument (fit.measures = TRUE)

Jasper Bogaert

unread,
Feb 8, 2022, 2:56:09 AM2/8/22
to lavaan
Hi!

I am not very familiar with this subject, but I tried your code and the code below worked for me. The only noteworthy difference I made was changing the name of the dataset from nhanes_imp to boys_imp. Could it be that this was just the mistake?

-----------------------------------------------------------------------------------
# download pacman package
install.packages("pacman")


# loads relevant packages using the pacman package
pacman::p_load(
  dplyr,
  semTools,
  mice )      

# make 10 dataset using mice
boys_imp <- boys %>%
  mice(.,
       m = 3,
       cluster.seed = 1234)

# set up model
fit <-  "sem =~ age + bmi + hc + hgt + wgt"

# run model
out1 <- semTools::runMI(fit,
                        data = boys_imp,   # changed this name!

                        miPackage = "mice",
                        fun="sem",
                        seed = 12345)

# get results
summary(out1, fit.measures = T)
------------------------------------------------------------------------------------


Best wishes,

Jasper Bogaert
---------------------
PhD student and teaching assistant
Department of Data Analysis (PP01)
Faculty of Psychology and Educational Sciences
Ghent University

Mauricio Garnier-Villarreal

unread,
Feb 8, 2022, 6:19:36 AM2/8/22
to lavaan
Hi

I think the problem is that you are not loading the semTools package, and calling it with the :: operator

So, run library(semTools) at the begining, and then dont use the :: operator to call the runMI function

Mohamed Yusuf

unread,
Feb 8, 2022, 11:56:54 AM2/8/22
to lavaan
Hi both,

I have managed to resolve the issue now. CLosing my project and starting fresh really help the situation

Thank you for your answers!

Many thanks

Mo

Reply all
Reply to author
Forward
0 new messages