Learn R Programming

MplusAutomation (version 0.6-1)

mplusModeler: Create, run, and read Mplus models.

Description

This is a convenience wrapper to automate many of the usual steps required to run an Mplus model. It relies in part on functions from the MplusAutomation package.

Usage

mplusModeler(object, dataout, modelout, run = 0L,
    check = FALSE, varwarnings = TRUE, ...)

Arguments

object
An object of class mplusObject
dataout
the name of the file to output the data to for Mplus.
modelout
the name of the output file for the model. This is the file all the syntax is written to, which becomes the Mplus input file. Typically ends in .inp.
run
an integer indicating how many models should be run. Defaults to zero. If zero, the data and model input files are all created, but the model is not run. This can be useful for seeing how the function works and what setup is done. If one, a basic
check
logical whether the body of the Mplus syntax should be checked for missing semicolons using the parseMplus function. Defaults to FALSE.
varwarnings
A logical whether warnings about variable length should be left, the default, or removed from the output file.
...
additional arguments passed to the prepareMplusData function.

Value

  • An Mplus model object, with results. If run = 1, returns an invisible list of results from the run of the Mplus model (see readModels from the MplusAutomation package). If run = 0, the function returns a list with two elements, model and boot that are both NULL. if run >= 1,returns a list with two elements, model and boot containing the regular Mplus model output and the boot object, respectively. In all cases, the Mplus data file and input files are created.

Details

Combined with functions from the MplusAutomation package, this function is designed to make it easy to fit Mplus models from R and to ease many of the usual frustrations with Mplus. For example, Mplus has very specific formats it accepts data in, but also very little data management facilities. Using Rdata management is easy. This function is designed to make using data from Rin Mplus models easy. It is also common to want to fit many different models that are slight variants. This can be tedius in Mplus, but using Ryou can create one basic set of input, store it in a vector, and then just modify that (e.g., using regular expressions) and pass it to Mplus. You can even use loops or the *apply constructs to fit the same sort of model with little variants.

See Also

runModels and readModels

Examples

Run this code
# simple example of a model using builtin data
# demonstrates use
test <- mplusObject(
  TITLE = "test the MplusAutomation Package and my Wrapper;",
  MODEL = "
    mpg ON wt hp;
    wt WITH hp;",
  usevariables = c("mpg", "wt", "hp"),
  rdata = mtcars)

 res <- mplusModeler(test, "mtcars.dat", modelout = "model1.inp", run = 1L)

 # remove files
 unlink("mtcars.dat")
 unlink("model1.inp")
 unlink("model1.out")

 # similar example using a robust estimator for standard errors
 test2 <- update(test, ANALYSIS = ~ "ESTIMATOR = MLR;")

 res2 <- mplusModeler(test2, "mtcars.dat", modelout = "model2.inp", run = 1L)
 unlink("mtcars.dat")
 unlink("model2.inp")
 unlink("model3.out")

 # now use the built in bootstrapping methods
 # note that these work, even when Mplus will not bootstrap
 res3 <- mplusModeler(test2, "mtcars.dat", modelout = "model3.inp", run = 10L)

 unlink("mtcars.dat")
 unlink("model3.inp")
 unlink("model3.out")
 unlink("Mplus Run Models.log")

Run the code above in your browser using DataLab