mplus: Create, Run, and Print Mplus Models

View source: R/mplus.R

mplusR Documentation

Create, Run, and Print Mplus Models

Description

This wrapper function creates a Mplus input file, runs the input file by using the mplus.run() function, and prints the Mplus output file by using the mplus.print() function.

Usage

mplus(x, file = "Mplus_Input.inp", data = NULL, comment = FALSE,
      replace.inp = TRUE, mplus.run = TRUE, show.out = FALSE,
      replace.out = c("always", "never", "modified"), Mplus = detect.mplus(),
      print = c("all", "input", "result"),
      input = c("all", "default", "data", "variable", "define", "analysis",
                "model", "montecarlo", "mod.pop", "mod.cov", "mod.miss",
                "message"),
      result = c("all", "default", "summary.analysis.short",
                 "summary.data.short", "random.starts", "summary.fit",
                 "mod.est", "fit", "class.count", "classif", "mod.result",
                 "total.indirect"),
      exclude = NULL, variable = FALSE, not.input = TRUE, not.result = TRUE,
      write = NULL, append = TRUE, check = TRUE, output = TRUE)

Arguments

x

a character string containing the Mplus input text.

file

a character string indicating the name of the Mplus input file with or without the file extension .inp, e.g., "Mplus_Input.inp" or "Mplus_Input".

data

a matrix or data frame from which the variables names for the subsection NAMES are extracted.

comment

logical: if FALSE (default), comments (i.e., text after the ! symbol) are removed from the input text specified in the argument x.

replace.inp

logical: if TRUE (default), an existing input file will be replaced.

mplus.run

logical: if TRUE, the input file specified in the argument file containing the input text specified in the argument x is run using the mplus.run() function.

show.out

logical: if TRUE, estimation output (TECH8) is show on the R console. Note that if run within Rgui, output will display within R, but if run via Rterm, a separate window will appear during estimation.

replace.out

a character string for specifying three settings: "always" (default), which runs all models, regardless of whether an output file for the model exists, "never", which does not run any model that has an existing output file, and "modified", which only runs a model if the modified date for the input file is more recent than the output file modified date.

Mplus

a character string for specifying the name or path of the Mplus executable to be used for running models. This covers situations where Mplus is not in the system's path, or where one wants to test different versions of the Mplus program. Note that there is no need to specify this argument for most users since it has intelligent defaults.

print

a character vector indicating which results to show, i.e. "all" (default) for all results "input" for input command sections, and "result" for result sections.

input

a character vector specifying Mplus input command sections included in the output (see 'Details' in the mplus.print function).

result

a character vector specifying Mplus result sections included in the output (see 'Details' in the mplus.print function).

exclude

a character vector specifying Mplus input command or result sections excluded from the output (see 'Details' in the mplus.print function).

variable

logical: if TRUE, names of the variables in the data set (NAMES ARE) specified in the VARIABLE: command section are shown. By default, names of the variables in the data set are excluded from the output unless all variables are used in the analysis (i.e., no USEVARIABLES option specified in the Mplus input file).

not.input

logical: if TRUE (default), character vector indicating the input commands not requested are shown on the console.

not.result

logical: if TRUE (default), character vector indicating the result sections not requested are shown on the console.

write

a character string naming a file for writing the output into a text file with file extension ".txt" (e.g., "Output.txt").

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown on the console by using the function mplus.print().

Details

The NAMES Option

The NAMES option in the VARIABLE section used to assign names to the variables in the data set can be specified by using the data argument:

  • Write Mplus Data File: In the first step, the Mplus data file is written by using the write.mplus() function, e.g. write.mplus(ex3_1, file = "ex3_1.dat").

  • Specify Mplus Input: In the second step, the Mplus input is specified as a character string. The NAMES option is left out from the Mplus input text, e.g., input <- 'DATA: FILE IS ex3_1.dat;\nMODEL: y1 ON x1 x3;'.

  • Run Mplus Input: In the third step, the Mplus input is run by using the mplus() function. The argument data needs to be specified given that the NAMES option was left out from the Mplus input text in the previous step, e.g., mplus(input, file = "ex3_1.inp", data = ex3_1).

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

x

a character vector containing the Mplus input text

args

specification of function arguments

input

list with input command sections

write

write command sections

result

list with input command sections (input) and result sections (result)

Author(s)

Takuya Yanagida

References

Muthen, L. K., & Muthen, B. O. (1998-2017). Mplus User's Guide (8th ed.). Muthen & Muthen.

See Also

read.mplus, write.mplus, mplus.update, mplus.print, mplus.plot, mplus.bayes, mplus.run, mplus.lca

Examples

## Not run: 
#----------------------------------------------------------------------------
# Example 1: Write data, specify input, and run input

# Write Mplus Data File
write.mplus(ex3_1, file = "ex3_1.dat")

# Specify Mplus input, specify NAMES option
input1 <- '
DATA:     FILE IS ex3_1.dat;
VARIABLE: NAMES ARE y1 x1 x3;
MODEL:    y1 ON x1 x3;
OUTPUT:   SAMPSTAT;
'

# Run Mplus input
mplus(input1, file = "ex3_1.inp")

#----------------------------------------------------------------------------
# Example 2: Alternative specification using the data argument

# Specify Mplus input, leave out the NAMES option
input2 <- '
DATA:     FILE IS ex3_1.dat;
MODEL:    y1 ON x1 x3;
OUTPUT:   SAMPSTAT;
'

# Run Mplus input, specify the data argument
mplus(input2, file = "ex3_1.inp", data = ex3_1)

## End(Not run)

misty documentation built on Oct. 24, 2024, 5:10 p.m.

Related to mplus in misty...