mplus {misty}R 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", replace.inp = TRUE, data = NULL, mplus.run = TRUE,
      show.out = FALSE, replace.out = c("always", "never", "modified"),
      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".

replace.inp

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

data

a matrix or data frame from which the variables names for the subsection NAMES are extracted when using the ... specification in the VARIABLE section.

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.

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 specifiying Mplus input command sections included in the output (see 'Details' in the mplus.print function).

result

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

exclude

a character vector specifiying 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

in the VARIABLE section used to assign names to the variables in the data set can be specified by using ... and 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 can be specified by using ..., e.g., input <- 'DATA: FILE IS ex3_1.dat;\nVARIABLE: ...\nMODEL: y1 ON x1 x3;'.

  • Run Mplus Input: In the third step, the Mplus input is run by using the mplus() function. Note that the argument data needs to be specified given that the NAMES option was specified by using ... 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 (input)

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.print, mplus.update, 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: Alterantive specification using ... and the data argument

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

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

## End(Not run)

[Package misty version 0.6.5 Index]