Search code examples
rimputationr-micerowsum

How can I use rowSums() after multiple imputation with MICE package in R


I have a short question:

I imputed item data using multiple imputation with the MICE package.
After imputation, I would like to sum items to a total score.
However, my data is now in a mids object, and I can't figure out how to do this simple task.
Does anyone have experience with this "problem"?


Solution

  • I figured it out:

    1. Create an object that contains all imputed datasets and the original dataset
    2. Apply the rowSums()
    3. Reconstruct the .mids object

    Example code:

    # load .mids object
    library("miceadds")
    Dmi<-load.Rdata2("imp.Rdata",paste(getwd(),"imp",sep=""))
    
    # create object that contains all imputed datasets and the original dataset
    D<-complete(Dmi,"long",include=T)
    
    # use rowSums
    D$T<-rowSums(D[2:11])
    
    # reconstruct .mids object
    Dmi<-as.mids2(D)