Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test if a list is.mids() when running runMI() #51

Closed
cddesja opened this issue Dec 7, 2018 · 0 comments · Fixed by #52
Closed

Test if a list is.mids() when running runMI() #51

cddesja opened this issue Dec 7, 2018 · 0 comments · Fixed by #52

Comments

@cddesja
Copy link

cddesja commented Dec 7, 2018

I would expect the following to work based on the semTools help page:

library(mice)
library(semTools)

# impute data
imp <- mice(nhanes, m = 5, seed = 54321)

# check that imp is a list as sem.mi  as manual says “Ignored if data is already a list of imputed data set”
is.list(imp)

# create simple lavaan model 
mod <- "
 chl ~ 1 + age + bmi + hyp


# mi runs(?) and complains 
fit.mi <- sem.mi(model = mod, data = imp)
summary(fit.mi)

However, it doesn't. I have fixed this by adding the following to runMI():

else if (is.list(data)) {
    if(is.mids(data)){
      m <- data$m
      imputedData <- list()
      for(i in 1:m){
        imputedData[[i]] <- complete(data, i)
      } 
      imputeCall <- list()
      class(imputedData) <- "list"
    } else {
      seed <- integer(length = 0)
      imputeCall <- list()
      imputedData <- data
      m <- length(data)
      class(imputedData) <- "list"
    }
  }

I can submit a pull request.

@cddesja cddesja changed the title Test if a list is.mid() when running runMI() Test if a list is.mids() when running runMI() Dec 7, 2018
@cddesja cddesja mentioned this issue Dec 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant