runAlignment: Run alignment procedure using Mplus

View source: R/runAlignment.R

runAlignmentR Documentation

Run alignment procedure using Mplus

Description

Facilitates running alignmnet procedure in Mplus. It creates Mplus input and data from R data.frame, runs the input using Mplus, and returns its summaries back in R.

Usage

runAlignment(
  model,
  group,
  dat,
  categorical = NULL,
  sim.samples = c(100, 500, 1000),
  sim.reps = 500,
  Mplus_com = "mplus",
  path = getwd(),
  summaries = FALSE,
  estimator = "MLR",
  parameterization = NULL,
  listwise = "OFF",
  processors = 2
)

Arguments

model

Character. Formula in Mplus format, e.g. "Factor1 BY item1 item2 item3 item4; item4 WITH item3;", see example.

group

Character, name of the grouping variable.

dat

Data frame containing data.

categorical

Character vector of variable names. Indicators that are binary or ordinal. Default is NULL.

sim.samples

Vector of integers. Group sample sizes for simulation, the length of this vector also determines a number of simulation studies. Default is 'c(100, 500, 1000)'. May take a substantial amount of time. Use NULL to avoid running simulations.

sim.reps

A number of simulated datasets in each simulation. Default is 500. Use 0 to avoid running simulations.

Mplus_com

Sometimes you don't have a direct access to Mplus, so this argument specifies what to send to a system command line. Default value is "mplus".

path

Where all the .inp, .out, and .dat files should be stored?

summaries

If the extractAlignment and extractAlignmentSim should be run after all the Mplus work is done. Default is FALSE.

estimator

Could be any estimator supported by Mplus. Default is "MLR".

listwise

'Listwise' option of Mplus; whether the missing values should be deleted listwise.

processors

'Processors' option of Mplus.

Details

The function runs in four steps to facilitate setting up and running alignment:

  1. Converts data.drame into a dat file compatible with Mplus. Saves it on the disk.

  2. Creates Mplus input file for free alignemnent. Saves it on the disk.

  3. Runs this input using the saved data, which produces an .out file.

  4. Reads in the output, selects the appropriate reference group, creates a new input file for fixed alignment, and runs it.

  5. (Optional) Runs simulations to check the reliability of the fixed alignment results.

  6. (Optional) Using extractAlignment and/or extractAlignmentSim reads in the output file of the fixed alignment and summarizies them in a convenient, publishable tables.

The sequence of free, fixed alignment and simulations follows recommendations of Muthen & Asparouhov (2014).

All the files created during these steps stay on the disk and can be used independently for reporting. For a detailed tutorial on alignment in general see https://maksimrudnev.com/2019/05/01/alignment-tutorial/

Examples

## Not run:  aling.res = runAlignment(model = "Moral1 BY prostit homosex abortion divorce;
Moral2 BY benefits taxes bribes;", 
group = "country",
 dat = wvs.s1,
 Mplus_com = "mplus",
 summaries = T
 )
 
## End(Not run)
 @seealso extractAlignment, extractAlignmentSim, extractAlignmentSim, measurementInvarianceMplus
 

MaksimRudnev/MIE.package documentation built on March 5, 2024, 1:24 p.m.