Imputation example?

283 views
Skip to first unread message

Daniel Briley

unread,
May 14, 2018, 4:17:02 PM5/14/18
to MplusAutomation
Hello,

I'm having trouble figuring out the correct syntax for using TYPE = IMPUTATION with the mplusObject and mplusModeler functions. I've tried out various techniques, but no matter what I can't get the model to run as expected. Typically when I run mplusModeler it tells me that "formal argument "imputed" matched by multiple actual arguments". As background, I'm attempting to analyze PISA data which includes multiple plausible values for achievement outcomes. I'll leave the code short, but can provide more if useful. 

Here's an example of how I'd really like to use the functions:

#save datafiles 1-10 with plausible values 1-10
prepareMplusData(df.1, "IMP1.dat")
...
prepareMplusData(df.10, "IMP10.dat")

#write text file to tell mplus where to find data
write.table(c(paste0("IMP",1:10,".dat")),"IMP input.txt",col.names=F,row.names = F,quote=F)

#create syntax and run it
model1<-mplusObject([model information], rdata = ????, imputed=T)

model1.results<-mplusModeler(model1, dataout="IMP input.txt", modelout="model 1.inp", run=1L, hashfilename=F,imputed=T)

Interestingly, mplusModeler writes the correct input file and can be run from mplus or R by calling the specific script, but I can't seem to get it to run without error using only the mplusModeler command.

In reading the help pages, the best that I've been able to come up with is that the rdata command in mplusObject needs to be a list, such as list("IMP1",...,"IMP10"), and these values should match dataframes held within the R session. So, rather than saving the dataframes as .dat files using prepareMplusData, I told the mplusObject() function that the rdata was my list of the dataframe objects.

Could someone help me out here? I must be missing something obvious about how imputed data works with mplusautomation, but I can't seem to figure it out from the help text. 

Thanks in advance,
Daniel

Jorge Sinval

unread,
Jul 17, 2021, 6:10:59 PM7/17/21
to MplusAutomation
Any update? I am also using ILSAs data, I tried to use a *.txt file in the DATA argument, but I got this error:

Error in .cleanHashData(df = object$rdata, keepCols = object$usevariables, : Assertion on 'df' failed: Must be of type 'data.frame', not 'NULL'.

Joshua Wiley

unread,
Jul 17, 2021, 8:44:02 PM7/17/21
to Jorge Sinval, MplusAutomation
Hi Jorge,

A working example is below. But short is that mplusObject() and mplusModeler() expect you to give them the data, and they take care of writing it out for Mplus. Note in the example below, the quiet = FALSE is required in version 1.0.0 (on CRAN) due to a bug introduced when quiet was added as a default. This is fixed in the development version on github which you could test out by:

devtools::install_github("michaelhallquist/MplusAutomation")

Reports of issues using imputed data would be useful as I almost never analyze imputed data in Mplus so harder for me to find issues.

#####################################
library(MplusAutomation)

## create some simplistic "multiply imputed" data list
## 5 imputations as data frames stored in a list
set.seed(1234)
dimp <- replicate(5,list(data.frame(
  mpg = mtcars$mpg,
  hp = mtcars$hp + rnorm(nrow(mtcars)))))

## mplusobject
m <- mplusObject(
  MODEL = "
hp ON mpg;",
rdata = dimp,
imputed = TRUE)

## fit the model
mfit <- mplusModeler(m, modelout = "mplusautomation_imputed.inp", run = TRUE, quiet = FALSE)

## look at coefficient results
coef(mfit)

##            Label      est      se pval
##1         HP<-MPG   -8.825   1.271    0
##2  HP<-Intercepts  323.887  26.632    0
##3         HP<->HP 1818.988 455.097    0


--
You received this message because you are subscribed to the Google Groups "MplusAutomation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mplusautomati...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mplusautomation/07ac25a7-6b27-4390-a58f-629a3389c239n%40googlegroups.com.

Jorge Sinval

unread,
Jul 18, 2021, 6:48:30 AM7/18/21
to MplusAutomation
Hello Joshua!

Thank you! It worked, although i ended up with an error it is related to the threelevel HLM described in another post. One step less to fully automate the pipeline. :)

(¬_¬)mfit <- mplusModeler(m, modelout = "mplusautomation_imputed.inp", run = TRUE, quiet = FALSE) Wrote model to: mplusautomation_imputed.inp writing implist to mplusautomation_imputed.dat Running model: mplusautomation_imputed.inp System command: cd "/home/ubuntu/Multilevel_Modeling" && "/opt/mplus/8.6/mplus" "mplusautomation_imputed.inp" Reading model: mplusautomation_imputed.out Error extracting SUMMARY OF DATA in output file: mplusautomation_imputed.out <simpleError in extractValue(pattern = "^\\s*Average cluster size\\s*", section, filename, type = "dec"): More than one match found for parameter: ^\s*Average cluster size\s* mplusautomation_imputed.out>

Joshua Wiley

unread,
Jul 18, 2021, 6:57:20 AM7/18/21
to Jorge Sinval, MplusAutomation
Hi Jorge,

Yes I think you are correct that that's an issue related to three level models, which I don't have a fix for yet.

Cheers,

Josh

Jorge Sinval

unread,
Jul 18, 2021, 7:28:33 AM7/18/21
to MplusAutomation
Yes, I can confirm that. It is the same error I obtain using the manually written *.inp file.

Cheers, Sinval.

Reply all
Reply to author
Forward
0 new messages