### Example dropCols Usage Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/LatexSummaryTable.html Demonstrates how to specify columns to drop using the dropCols parameter. ```R dropCols Example: `[c("InputInstructions", "TLI")](https://rdrr.io/r/base/c.html)` ``` -------------------------------- ### Example: Create and Plot LTA Model Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/plotLTA.html This example demonstrates how to create an Mplus mixture model, run it, read the results, and then plot the latent transition probabilities using plotLTA. Ensure Mplus is installed and accessible. ```R data <- read.table("http://statmodel.com/usersguide/chap8/ex8.13.dat")[c(1:10)] names(data) <- c("u11", "u12", "u13", "u14", "u15", "u21", "u22", "u23", "u24", "u25") createMixtures( classes = 2, filename_stem = "dating", model_overall = "c2 ON c1;", model_class_specific = c( "[u11$1] (a{C}); [u12$1] (b{C}); [u13$1] (c{C}); [u14$1] (d{C}); [u15$1] (e{C});", "[u21$1] (a{C}); [u22$1] (b{C}); [u23$1] (c{C}); [u24$1] (d{C}); [u25$1] (e{C});" ), rdata = data, ANALYSIS = "PROCESSORS IS 2; LRTSTARTS (0 0 40 20); PARAMETERIZATION = PROBABILITY;", VARIABLE = "CATEGORICAL = u11-u15 u21-u25;" ) runModels(filefilter = "dating") results <- readModels(filefilter = "dating") plotLTA(results) ``` -------------------------------- ### Install MplusAutomation from GitHub Source: https://github.com/michaelhallquist/mplusautomation/blob/master/README.md Install the latest development version of the MplusAutomation package using the devtools package. ```R library(devtools) install_github("michaelhallquist/MplusAutomation") ``` -------------------------------- ### Simulate Data and Train LGMM Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/trainLGMM.html This example demonstrates how to simulate data for three classes and then train an LGMM. It requires setting a working directory, loading necessary libraries, and preparing the data with splines. The example is computationally intensive and not run by default. ```R if (FALSE) { setwd(tempdir()) ## Simulate Some Data from 3 classes library(MASS) set.seed(1234) allcoef <- rbind( cbind(1, mvrnorm(n = 200, mu = c(0, 2, 0), Sigma = diag(c(.2, .1, .01)), empirical = TRUE)), cbind(2, mvrnorm(n = 200, mu = c(-3.35, 2, 2), Sigma = diag(c(.2, .1, .1)), empirical = TRUE)), cbind(3, mvrnorm(n = 200, mu = c(3.35, 2, -2), Sigma = diag(c(.2, .1, .1)), empirical = TRUE))) allcoef <- as.data.frame(allcoef) names(allcoef) <- c("Class", "I", "L", "Q") allcoef$ID <- 1:nrow(allcoef) d <- do.call(rbind, lapply(1:nrow(allcoef), function(i) { out <- data.frame( ID = allcoef$ID[i], Class = allcoef$Class[i], Assess = 1:11, x = sort(runif(n = 11, min = -2, max = 2))) out$y <- rnorm(11, mean = allcoef$I[i] + allcoef$L[i] * out$x + allcoef$Q[i] * out$x^2, sd = .1) return(out) })) ## create splines library(splines) time_splines <- ns(d$x, df = 3, Boundary.knots = quantile(d$x, probs = c(.02, .98))) d$t1 <- time_splines[, 1] d$t2 <- time_splines[, 2] d$t3 <- time_splines[, 3] d$xq <- d$x^2 ## create new data to be used for predictions nd <- data.frame(ID = 1, x = seq(from = -2, to = 2, by = .1)) nd.splines <- with(attributes(time_splines), ns(nd$x, df = degree, knots = knots, ``` -------------------------------- ### Install MplusAutomation from GitHub Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/index.html Installs the development version of the MplusAutomation package directly from GitHub using the devtools package. Ensure devtools is installed first. ```r #install.packages("devtools") library(devtools) install_github("michaelhallquist/MplusAutomation") ``` -------------------------------- ### Create and Summarize an mplusObject Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/summary.mplusObject.html Demonstrates how to create an mplusObject, run a model using mplusModeler, and then summarize the results. This is a basic usage example. ```R test <- mplusObject( TITLE = "test the MplusAutomation Package;", 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) summary(res) ``` -------------------------------- ### Plotting Coefficients from mplusObject Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/plot.mplusObject.html This example demonstrates how to create an mplusObject, run it using mplusModeler, and then plot the resulting coefficients. It also includes cleanup of generated files. ```R if (FALSE) { # simple example of a model using builtin data # demonstrates use test <- mplusObject( TITLE = "test the MplusAutomation Package;", MODEL = " mpg ON wt hp; wt WITH hp;", OUTPUT = "STANDARDIZED;", usevariables = c("mpg", "wt", "hp"), rdata = mtcars) res <- mplusModeler(test, "mtcars.dat", modelout = "model1.inp", run = 1L) # example of the coef method plot(res) # remove files unlink("mtcars.dat") unlink("model1.inp") unlink("model1.out") unlink("Mplus Run Models.log") } ``` -------------------------------- ### Example Usage of extractParameters_1section Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/extractParameters_1section.html Illustrative examples demonstrating how to use the extractParameters_1section function with different Mplus output file scenarios. These examples are commented out and intended for testing purposes. ```R if (FALSE) { #a few examples of files to parse #mg + lc. Results in latent class pattern, not really different from # regular latent class matching. See Example 7.21 #mg + twolevel. Group is top, bw/wi is 2nd. See Example 9.11 #lc + twolevel. Bw/wi is top, lc is 2nd. See Example 10.1. # But categorical latent variables is even higher #test cases for more complex output: 7.21, 9.7, 9.11, 10.1 } ``` -------------------------------- ### Change Directory with Base, Prefix, and Number Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/cd.html This example demonstrates creating and changing to directories with a common base path and a unique prefix and number. This is useful for organizing multiple related directories. ```R base <- "~/testdir" pre <- "test_" cd(base, pre, 1) cd(base, pre, 2) ``` -------------------------------- ### Example keepCols Usage Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/LatexSummaryTable.html Demonstrates how to specify custom columns to keep using the keepCols parameter. ```R keepCols Example: `[c("Title", "LL", "AIC", "CFI")](https://rdrr.io/r/base/c.html)` ``` -------------------------------- ### Complete Mplus Template Example Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html A comprehensive example demonstrating the use of conditional tags and variable substitution to generate a large number of Mplus input files for growth mixture modeling. It includes nested iterators and complex filename/directory generation. ```Mplus [[init]] iterators = outcome group model classes zeroclass; outcome = 1:10; group = 2 5; model = 1:3; classes = 1:4; zeroclass = 1:2; outcomenames#outcome = Paranoid Schizoid Schizotypal Antisocial Borderline Histrionic Narcissistic Avoidant Dependent OCPD; groupnames#group = "Low Risk" "High Risk"; modelnames#model = "Normal LGCM" "Poisson GMM" "Poisson LCGA"; zeroclassnames#zeroclass = "" " with zero class"; #wave names are with respect to the outcome iterator w1name#outcome = Paran1 Szoid1 Sztyp1 Anti1 Border1 Hist1 Narc1 Avoid1 Depend1 OCPD1; w2name#outcome = Paran2 Szoid2 Sztyp2 Anti2 Border2 Hist2 Narc2 Avoid2 Depend2 OCPD2; w3name#outcome = Paran3 Szoid3 Sztyp3 Anti3 Border3 Hist3 Narc3 Avoid3 Depend3 OCPD3; filename = "[[classes]]-class [[groupnames#group]] [[outcomenames#outcome]] [[modelnames#model]][[zeroclassnames#zeroclass]].inp"; outputDirectory = "PD GMM/[[outcomenames#outcome]]/[[groupnames#group]]/Unconditional_Models/[[modelnames#model]]"; [[/init]] TITLE: [[classes]]-class [[outcomenames#outcome]] [[groupnames#group]] [[modelnames#model]] Unconditional Model[[zeroclassnames#zeroclass]] DATA: FILE = "personality_mplus.dat"; VARIABLE: NAMES ARE id group sex age Paran1 Szoid1 Sztyp1 Anti1 Border1 Hist1 Narc1 Avoid1 Depend1 OCPD1 PaAg1 Sadist1 SelfDef1 Paran2 Szoid2 Sztyp2 Anti2 Border2 Hist2 Narc2 Avoid2 Depend2 OCPD2 Paran3 Szoid3 Sztyp3 Anti3 Border3 Hist3 Narc3 Avoid3 Depend3 OCPD3; ``` -------------------------------- ### Install MplusAutomation from CRAN Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/index.html Installs the latest stable release of the MplusAutomation package from CRAN. ```r install.packages("MplusAutomation") ``` -------------------------------- ### Create Mixture Models and Summarize Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/mixtureSummaryTable.html This example demonstrates how to create mixture models using createMixtures and then generate a summary table of their fit statistics using mixtureSummaryTable. It's useful for comparing different mixture models. ```R if (FALSE) { res <- createMixtures(classes = 1:2, filename_stem = "iris", rdata = iris, OUTPUT = "tech11 tech14;", run = 1L) mixtureSummaryTable(res) } ``` -------------------------------- ### Run Mplus Models with File Filter and No Log Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/runModels.html This example shows how to run Mplus models from the current working directory, filtering files by a pattern and disabling logging. ```R if (FALSE) { runModels(getwd(), filefilter = "ex8.*", logFile=NULL) } ``` -------------------------------- ### Create and Plot Mixture Models Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/plotMixtures.html This example demonstrates how to create mixture models using createMixtures and then visualize the results with plotMixtures, including plotting raw data in the background. ```R res <- createMixtures(classes = 1:2, filename_stem = "cars", model_overall = "wt ON drat;", model_class_specific = "wt; qsec;", rdata = mtcars, usevariables = c("wt", "qsec", "drat"), OUTPUT = "standardized", run = 1L) plotMixtures(res, rawdata = TRUE) ``` -------------------------------- ### Extracting Model Summaries Example Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/extractModelSummaries.html Demonstrates how to use the extractModelSummaries function to extract summaries from a specified Mplus examples directory. This code is intended to be run within an R environment. ```r if (FALSE) { allExamples <- extractModelSummaries( "C:/Program Files/Mplus/Mplus Examples/User's Guide Examples") } ``` -------------------------------- ### Example: Running and Extracting Mplus Model Results Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/extract.html Demonstrates creating an Mplus model object, running it with mplusModeler, and then extracting the results using the extract function. Includes cleanup of generated files. ```R test <- mplusObject( TITLE = "test the MplusAutomation Package;", MODEL = " mpg ON wt hp; wt WITH hp;", OUTPUT = "STANDARDIZED;", usevariables = c("mpg", "wt", "hp"), rdata = mtcars) res <- mplusModeler(test, "mtcars.dat", modelout = "model1.inp", run = 1L) extract(res$results) # there is also a method for mplusObject class extract(res) # load the texreg package # to use pretty printing via screenreg # uncomment to run these examples # library(texreg) # screenreg(res) # screenreg(res, type = 'stdyx') # screenreg(res, type = 'un', params = 'regression', # single.row=TRUE) # screenreg(res, type = 'un', params = 'regression', summaries = 'CFI', # single.row=TRUE) # remove files unlink("mtcars.dat") unlink("model1.inp") unlink("model1.out") unlink("Mplus Run Models.log") ``` -------------------------------- ### Remove Example Objects Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/detectVariables.html This snippet removes the previously created example objects from the R environment. ```R rm(example1, example2, example3) ``` -------------------------------- ### Example Usage of extractModelParameters Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/extractModelParameters.html Demonstrates how to use the extractModelParameters function to extract parameters from an Mplus output file. This example is conditional and will only run if FALSE is TRUE. ```R if (FALSE) { ex3.14 <- extractModelParameters( "C:/Program Files/Mplus/Mplus Examples/User's Guide Examples/ex3.14.out") } ``` -------------------------------- ### Run Mplus Models Recursively with Options Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/runModels.html This example demonstrates running Mplus models recursively from a specified directory, showing output, using a modified date replacement strategy, and logging to a file. It also specifies a custom path to the Mplus executable. ```R if (FALSE) { runModels("C:/Users/Michael/Mplus Runs", recursive=TRUE, showOutput=TRUE, replaceOutfile="modifiedDate", logFile="MH_RunLog.txt", Mplus_command="C:\\Users\\Michael\\Mplus Install\\Mplus51.exe") } ``` -------------------------------- ### Basic Model Estimation with mplusModeler Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/mplusModeler.html This snippet shows a minimal example of creating an mplusObject with built-in data and then running the model using mplusModeler. It defaults to `writeData = 'ifmissing'`. ```R if (FALSE) { # minimal example of a model using builtin data, allowing R # to automatically guess the correct variables to use test <- [mplusObject](mplusObject.html)(MODEL = "mpg ON wt hp; wt WITH hp;", rdata = mtcars) # estimate the model in Mplus and read results back into R res <- mplusModeler(test, modelout = "model1.inp", run = 1L) } ``` -------------------------------- ### Plot Mixture Model with Standardized Coefficients Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/plotMixtures.html This example illustrates plotting a mixture model using standardized coefficients. ```R plotMixtures(res, coefficients = "stdyx.standardized") ``` -------------------------------- ### prepareMplusData for Multiply Imputed Data Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Shows how to prepare multiply imputed datasets for Mplus. This example prepares three data frames, each representing an imputed dataset. ```R # can write multiply imputed data too # here are three "imputed" datasets idat <- list( data.frame(mpg = mtcars$mpg, hp = c(100, mtcars$hp[-1])), data.frame(mpg = mtcars$mpg, hp = c(110, mtcars$hp[-1])), data.frame(mpg = mtcars$mpg, hp = c(120, mtcars$hp[-1])) ) ``` -------------------------------- ### Extract Mplus Results Example Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/get_results.html Demonstrates how to create an Mplus object, run a model, and then extract specific results like summaries using the get_results function. It also includes cleanup of generated files. ```R if (FALSE) { test <- mplusObject(MODEL = "mpg ON wt hp;\n wt WITH hp;", rdata = mtcars) res <- mplusModeler(test, modelout = "model1.inp", run = 1L) get_results(res, "summaries") unlink(res$results$input$data$file) unlink("model1.inp") unlink("model1.out") } ``` -------------------------------- ### Dynamic Output Directory with Custom Names Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html This example shows how to create a dynamic directory structure using custom names for iterators. The 'outputDirectory' path is constructed using tags that reference specific names defined for 'outcome' and 'model' iterators. ```mplus [[init]] iterators = outcome model; outcome = 1:2; model = 1:3; outcomeName#outcome = Outcome1 Outcome2; modelName#model = Model1 Model2 Model3; outputDirectory = "C:/CFA/[[outcomeName#outcome]]/[[modelName#model]]"; filename="testfile.inp" [[/init]] ``` -------------------------------- ### Example: Extracting Coefficients from mplus.model Object Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/coef.mplus.model.html Demonstrates how to use the coef method on the results of readModels to extract different types of coefficients. Also shows the coef method for mplusObject. ```R test <- mplusObject( TITLE = "test the MplusAutomation Package;", MODEL = " mpg ON wt hp; wt WITH hp;", OUTPUT = "STANDARDIZED;", usevariables = c("mpg", "wt", "hp"), rdata = mtcars) res <- mplusModeler(test, "mtcars.dat", modelout = "model1.inp", run = 1L) # example of the coef method on an mplud.model object # note that res$results holds the results of readModels() coef(res$results) coef(res$results, type = "std") coef(res$results, type = "stdy") coef(res$results, type = "stdyx") # there is also a method for mplusObject class coef(res) # remove files unlink("mtcars.dat") unlink("model1.inp") unlink("model1.out") unlink("Mplus Run Models.log") ``` -------------------------------- ### Create and Plot Growth Mixture Models with Free Loadings Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/plotGrowthMixtures.html Creates a growth mixture model with freely estimated loadings and then plots the results. This example also shows plotting with black and white output and adjusted alpha for transparency. ```R res <- createMixtures(classes = 1:3, filename_stem = "ex8.2_free", model_overall = "i s | V1@0 V2* V3* V4@3; i s on V5;", rdata = mydat, OUTPUT = "tech11 tech14;", usevariables = c("V1", "V2", "V3", "V4", "V5"), run = 1L) plotMixtureDensities(res, variables = c("V1", "V2", "V3", "V4")) plotGrowthMixtures(res, estimated = TRUE, rawdata = TRUE, bw = TRUE, time_scale = c(0, 1, 2, 3), alpha_range = c(0, .05)) ``` -------------------------------- ### Monte Carlo Simulation Setup Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/mplusModeler.html Configures an Mplus model for a Monte Carlo simulation, defining sample size, number of replications, population model, and analysis parameters using the Bayesian estimator. ```R montecarlo <- mplusObject( TITLE = "Monte Carlo Example;", MONTECARLO = " NAMES ARE i1-i5; NOBSERVATIONS = 100; NREPS = 100; SEED = 1234;", MODELPOPULATION = " f BY i1-i5*1; f@1; i1-i5*1;", ANALYSIS = " ESTIMATOR = BAYES; PROC = 2; fbiter = 100;", MODEL = " f BY i1-i5*.8 (l1-l5); f@1; i1-i5*1;", MODELPRIORS = " l1-l5 ~ N(.5 .1);", OUTPUT = "TECH9;" ) fitMonteCarlo <- mplusModeler(montecarlo, modelout = "montecarlo.inp", run = 1L, writeData = "always", hashfilename = FALSE) unlink("montecarlo.inp") unlink("montecarlo.out") ``` -------------------------------- ### createModels Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/createModels.html Processes a single Mplus template file and creates a group of related model input files. Definitions and examples for the template language are provided in the MplusAutomation vignette. ```APIDOC ## createModels ### Description Processes a single Mplus template file and creates a group of related model input files. Definitions and examples for the template language are provided in the MplusAutomation vignette. ### Method Not applicable (R function) ### Endpoint Not applicable (R function) ### Parameters #### Arguments - **templatefile** (string) - Required - The filename (absolute or relative path) of an Mplus template file to be processed. Example “C:/MplusTemplate.txt” ### Value No value is returned by this function. It is solely used to process an Mplus template file. ### Examples ```R createModels("L2 Multimodel Template No iter.txt") ``` ``` -------------------------------- ### Lookup Parameter in TECH1 Output Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/lookupTech1Parameter.html This example demonstrates how to use lookupTech1Parameter to find a specific parameter within the TECH1 output. It requires the readModels function to first parse the Mplus output. ```R if (FALSE) { models <- readModels("test1.out") param <- lookupTech1Parameter(models$tech1, 16) } ``` -------------------------------- ### Multinomial Regression Example Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/dot-mplusMultinomial.html Demonstrates how to use the internal .mplusMultinomial function for multinomial regression. It includes data generation and calls to the function with different settings for pairwise tests. ```R if (FALSE) { set.seed(1234) tmpd <- data.frame( x1 = rnorm(200), x2 = rnorm(200), x3 = cut(rnorm(200), breaks = c(-Inf, -.7, .7, Inf), labels = c("a", "b", "c"))) tmpd$y <- cut(rnorm(200, sd = 2) + tmpd$x1 + tmpd$x2 + I(tmpd$x3 == "b"), breaks = c(-Inf, -.5, 1, Inf), labels = c("L", "M", "H")) tmpres <- MplusAutomation:::.mplusMultinomial( dv = "y", iv = c("x1", "x2"), data = tmpd, pairwise = TRUE) tmpres2 <- MplusAutomation:::.mplusMultinomial( dv = "y", iv = c("x1", "x2"), data = tmpd, pairwise = FALSE) tmpres3 <- MplusAutomation:::.mplusMultinomial( dv = "y", iv = c("x1@0", "x2@0"), data = tmpd, pairwise = FALSE) } ``` -------------------------------- ### Prepare Data Frames for Mplus Conversion Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/dot-convertData.html Demonstrates preparing different data frames with various data types (factor, logical, character, Date) before conversion. This setup is for testing the .convertData function. ```R df1 <- df2 <- df3 <- df4 <- mtcars df2$cyl <- factor(df2$cyl) df2$am <- as.logical(df2$am) df3$mpg <- as.character(df3$mpg) df4$vs <- as.Date(df4$vs, origin = "1989-01-01") ``` -------------------------------- ### Example Usage of testBParamConstraint Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/testBParamConstraint.html This snippet demonstrates how to use the `testBParamConstraint` function to test an inequality hypothesis between two parameters. It requires a `bparameters` object and specifies the parameters and the comparison operator. ```R testBParamConstraint(bparamsDF, "MGM.TRT1", ">", "MGM.EX2") ``` -------------------------------- ### Basic Conditional Tag Example Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html Demonstrates the fundamental structure of conditional tags for including or excluding Mplus syntax based on variable conditions. The `[[init]]` block sets up variables, and the `[[model > 2]]` block shows conditional inclusion. ```Mplus [[init]] iterators=model; model=1:5; var1=test1; var2=test2; var3=test3; [[/init]] [[model > 2]] COUNT ARE [[var1]] [[var2]] [[var3]]; [[/model > 2]] ``` -------------------------------- ### Get current operating system name Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/OS.html Use this function to retrieve the name of the current operating system as a character string. For example, it might return 'windows', 'macos', or 'linux'. ```R MplusAutomation:::os() #> [1] "windows" ``` -------------------------------- ### prepareMplusData Syntax Output to File Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Demonstrates how to direct the Mplus syntax output to an input file instead of standard output, using 'inpfile=TRUE' or specifying a filename. ```R # write syntax to input file, not stdout prepareMplusData(mtcars, "test09.dat", inpfile=TRUE) # write syntax to alternate input file, not stdout prepareMplusData(mtcars, "test10.dat", inpfile="test10alt.inp") ``` -------------------------------- ### Advanced Mixture Model Syntax with Class-Specific Syntax Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/createMixtures.html Creates syntax for a two-class mixture model with custom overall and class-specific model syntax, including variable definitions and analysis options. This example demonstrates how to define complex model structures and Mplus analysis parameters. ```R data <- read.table("http://statmodel.com/usersguide/chap8/ex8.13.dat")[ ,c(1:10)] names(data) <- c("u11", "u12", "u13", "u14", "u15", "u21", "u22", "u23", "u24", "u25") createMixtures( classes = 2, filename_stem = "dating", model_overall = "c2 ON c1;", model_class_specific = c( "[u11$1] (a{C}); [u12$1] (b{C}); [u13$1] (c{C}); [u14$1] (d{C}); [u15$1] (e{C});", "[u21$1] (a{C}); [u22$1] (b{C}); [u23$1] (c{C}); [u24$1] (d{C}); [u25$1] (e{C});" ), rdata = data, ANALYSIS = "PROCESSORS IS 2; LRTSTARTS (0 0 40 20); PARAMETERIZATION = PROBABILITY;", VARIABLE = "CATEGORICAL = u11-u15 u21-u25;" ) ``` -------------------------------- ### prepareMplusData Interactive Mode Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Shows how to run prepareMplusData in interactive mode, which prompts the user for input. ```R # interactive (test08.dat) prepareMplusData(mtcars, interactive=TRUE) ``` -------------------------------- ### prepareMplusData Re-running and Hashing Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Illustrates the default behavior of re-writing data on subsequent calls and how to use hashing ('ifmissing' and 'hashfilename=TRUE') to avoid redundant writes when data has not changed. ```R # by default, if re-run, data is re-written, with a note test01b <- prepareMplusData(mtcars, "test01.dat") # if we turn on hashing in the filename the first time, # we can avoid overwriting notes the second time test01c <- prepareMplusData(mtcars, "test01c.dat", hashfilename=TRUE) # now that the filename was hashed in test01c, future calls do not re-write data # as long as the hash matches test01d <- prepareMplusData(mtcars, "test01c.dat", writeData = "ifmissing", hashfilename=TRUE) # now that the filename was hashed in test01c, future calls do not re-write data # as long as the hash matches test01db <- prepareMplusData(mtcars, "test01d.dat", writeData = "ifmissing", hashfilename=TRUE) # however, if the data change, then the file is re-written test01e <- prepareMplusData(iris, "test01c.dat", writeData = "ifmissing", hashfilename=TRUE) ``` -------------------------------- ### Display R Output in Console Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html Pass showOutput=TRUE to runModels() to display TECH8 output in the console. The output appears in the R window if started with Rgui.exe, or a separate DOS window if started with Rterm. ```R runModels( "C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE, showOutput=TRUE) ``` -------------------------------- ### Basic Usage of prepareMplusData Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Demonstrates the basic usage of prepareMplusData with imputed data and hashed filenames. The first call writes the data, while subsequent calls with identical data and hashes do not. ```R testimp1 <- prepareMplusData(idat, "testi1.dat", writeData = "ifmissing", hashfilename=TRUE, imputed = TRUE) # now that the filename was hashed, future calls do not re-write data # as long as all the hashes match testimp2 <- prepareMplusData(idat, "testi2.dat", writeData = "ifmissing", hashfilename=TRUE, imputed = TRUE) # in fact, the number of imputations can decrease # and they still will not be re-written testimp3 <- prepareMplusData(idat[-3], "testi3.dat", writeData = "ifmissing", hashfilename=TRUE, imputed = TRUE) ``` -------------------------------- ### prepareMplusData with Column Selection (keepCols) Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Demonstrates how to use the 'keepCols' argument to select specific variables by name, index, or logical vector. ```R # tests for keeping and dropping variables prepareMplusData(mtcars, "test02.dat", keepCols = c("mpg", "hp")) prepareMplusData(mtcars, "test03.dat", keepCols = c(1, 2)) prepareMplusData(mtcars, "test04.dat", keepCols = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) ``` -------------------------------- ### mplusAvailable() Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/index.html Checks whether Mplus can be found on the system. This utility function verifies if Mplus is installed and accessible. ```APIDOC ## mplusAvailable() ### Description Check whether Mplus can be found. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters None explicitly documented in the source. ### Request Example ```R is_mplus_available <- mplusAvailable() ``` ### Response Returns TRUE if Mplus is found, FALSE otherwise. ``` -------------------------------- ### friendlyGregexpr Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/friendlyGregexpr.html Creates a data frame documenting the start and end of all tags found using a regular expression pattern. ```APIDOC ## friendlyGregexpr ### Description Creates a data frame documenting the start and end of all tags. ### Arguments * **pattern** - The pattern to search for * **charvector** - Character vector * **perl** (logical) - Whether or not to use perl based regular expressions. Defaults to TRUE. ### Value A `data.frame` ``` -------------------------------- ### Create and Display Summary Table Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/SummaryTable.html Demonstrates how to create two Mplus models, run them, and then generate a summary table of their fit statistics. The output is sent to the console by default. ```R m1 <- mplusObject(TITLE = "Reduced", MODEL = "mpg ON wt;", rdata = mtcars) m1.fit <- mplusModeler(m1, "mtcars.dat", run = 1L) m2 <- mplusObject(TITLE = "Full", MODEL = "mpg ON wt hp qsec;", rdata = mtcars) m2.fit <- mplusModeler(m2, "mtcars.dat", run = 1L) SummaryTable(list(m1.fit, m2.fit)) ``` -------------------------------- ### Update R Packages Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html Updates all installed R packages to their latest versions. Set ask to FALSE to avoid interactive prompts. ```r update.packages(ask=FALSE, checkBuilt=TRUE) ``` -------------------------------- ### Clean up generated files Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/confint.mplus.model.html Removes temporary files created during the Mplus model execution and analysis. This is good practice after running examples. ```R unlink("mtcars.dat") unlink("model1.inp") unlink("model1.out") unlink("Mplus Run Models.log") ``` -------------------------------- ### lcademo Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/index.html Latent Class Analysis Demonstration. This function likely provides an example or runs a demonstration of latent class analysis using Mplus. ```APIDOC ## lcademo() ### Description Latent Class Analysis Demonstration. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters None explicitly documented in the source. ### Request Example ```R lcademo() ``` ### Response Likely runs a demonstration of LCA and may output results or plots. ``` -------------------------------- ### prepareMplusData with Column Selection (dropCols) Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Demonstrates how to use the 'dropCols' argument to exclude specific variables by name, index, or logical vector. ```R prepareMplusData(mtcars, "test05.dat", dropCols = c("mpg", "hp")) prepareMplusData(mtcars, "test06.dat", dropCols = c(1, 2)) prepareMplusData(mtcars, "test07.dat", dropCols = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)) ``` -------------------------------- ### Create and Display HTML Summary Table Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html Use HTMLSummaryTable to create an HTML file with model fit statistics and display it in the browser. Specify the output filename and which columns to keep. ```r HTMLSummaryTable( summaryStats, filename = "C:/MyModelSummary.html", display = TRUE, keepCols = c("Title", "LL", "AIC", "BIC", "AICC"), sortBy = "AIC") ``` -------------------------------- ### Check Mplus Availability (Silent) Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/mplusAvailable.html Checks if Mplus is installed and accessible by the system without printing any messages. Returns 0 if found, 1 otherwise. ```R mplusAvailable(silent = TRUE) ``` -------------------------------- ### prepareMplusData Error Handling and Overwriting Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Illustrates error handling when no file is specified for interactive mode and how the 'overwrite' argument controls behavior when existing files are detected. ```R # should be error, no file prepareMplusData(mtcars, interactive=FALSE) # new warnings if it is going to overwrite files # (the default to be consistent with prior behavior) prepareMplusData(mtcars, "test10.dat") # new warnings if it is going to overwrite files # (the default to be consistent with prior behavior) prepareMplusData(mtcars, "test11.dat", inpfile="test10alt.inp") # new errors if files exist and overwrite=FALSE prepareMplusData(mtcars, "test10.dat", inpfile="test10alt.inp", overwrite=FALSE) ``` -------------------------------- ### Check Mplus Availability (Verbose) Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/mplusAvailable.html Checks if Mplus is installed and accessible by the system, printing a success message if found. Returns 0 if found, 1 otherwise. ```R mplusAvailable(silent = FALSE) ``` -------------------------------- ### Circular Tag Definition Example Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html Demonstrates a circular dependency in Mplus init variable definitions, which leads to an error. Ensure that variable definitions do not create loops. ```plaintext iterators = model; model = 1:3; A = a_test1 a_test2 "a_test3[[B#model]]"; B = "b_test1 [[A#model]]" "b_test2 [[A#model]]" "b_test3 [[A#model]]"; ``` -------------------------------- ### Update mplusObject Use Variables Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/update.mplusObject.html Illustrates updating the 'usevariables' parameter of an mplusObject to include additional variables. This example adds 'cyl' to the existing 'mpg' and 'hp'. ```R update(example1, usevariables = c("mpg", "hp", "cyl")) ``` -------------------------------- ### processInit Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/processInit.html Processes the initialization section of an Mplus input file. This function takes a list representing the parsed init section and returns a processed list of arguments. ```APIDOC ## processInit ### Description Processes the initialization section of an Mplus input file. This function takes a list representing the parsed init section and returns a processed list of arguments. ### Function Signature `processInit(initsection)` ### Arguments #### Arguments * **initsection** (list) - The list of all arguments parsed from the init section. ### Value * **arglist** (list) - The processed list of arguments. ``` -------------------------------- ### Clean Up Mplus Output Files Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/SummaryTable.html Provides an example of how to remove generated Mplus output files after they are no longer needed. This is good practice for managing disk space. ```R # remove files unlink("mtcars.dat") unlink("mtcars.inp") unlink("mtcars.out") unlink("Mplus Run Models.log") closeAllConnections() ``` -------------------------------- ### Get SAVEDATA File Information Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/getSavedata_Fileinfo.html Reads the SAVEDATA INFORMATION section from an Mplus output file. This is useful for understanding the structure of the SAVEDATA file generated by Mplus. ```R fileInfo <- getSavedata_Fileinfo("C:/Program Files/Mplus/Test Output.out") ``` -------------------------------- ### Advanced Filename and Output Directory Configuration Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html This snippet illustrates an advanced configuration for 'filename' and 'outputDirectory', using descriptive names for iterators and embedding them into both the file and directory paths for organized output generation. ```mplus [[init]] iterators = outcome model; outcome = 1:5; model = 1:3; outcomeDirNames#outcome = Conscientiousness Extraversion Agreeableness Openness Neuroticism; modelNames#model = Poisson "Negative Binomial" "Negative Binomial Hurdle"; filename = "[[modelNames#model]] Growth Model.inp"; outputDirectory = "Template Output/[[outcomeDirNames#outcome]];" [[/init]] ``` -------------------------------- ### Basic prepareMplusData Usage Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Demonstrates the basic usage of prepareMplusData by preparing the mtcars dataset for Mplus. The output syntax is stored in the 'test01' object. ```R library(foreign) study5 <- read.spss("reanalysis-study-5-mt-fall-08.sav", to.data.frame=TRUE) ASData5 <- subset(study5, select=c("ppnum", paste("as", 1:33, sep=""))) prepareMplusData(ASData5, "study5.dat") # basic example test01 <- prepareMplusData(mtcars, "test01.dat") # see that syntax was stored test01 ``` -------------------------------- ### Generate Homogenous Residual Covariance Syntax with Custom Labels Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/mplusRcov.html Example of generating Mplus syntax for a homogenous residual covariance structure using custom labels for parameters. ```R mplusRcov(x = c("t1", "t2", "t3"), type = "homogenous", r = "rho", e = "e") ``` -------------------------------- ### prepareMplusData with Factor and Logical Variables Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/prepareMplusData.html Shows how prepareMplusData handles datasets containing factor and logical variables. The temporary dataset 'tmpd' is created, processed, and then removed. ```R tmpd <- mtcars tmpd$cyl <- factor(tmpd$cyl) tmpd$am <- as.logical(tmpd$am) prepareMplusData(tmpd, "test_type.dat") rm(tmpd) ``` -------------------------------- ### os() Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/OS.html Returns the name of the current operating system as a character string. ```APIDOC ## os() ### Description Returns the name of the current operating system. ### Function Signature os() ### Returns A character string representing the operating system (e.g., "windows", "macos", "linux"). ### Example ```R MplusAutomation:::os() ``` ``` -------------------------------- ### Display Summary Table in Popup Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/SummaryTable.html Shows how to generate a summary table of Mplus model fit statistics and display it in a popup window. ```R SummaryTable(list(m1.fit, m2.fit), type = "popup") ``` -------------------------------- ### HTMLSummaryTable() Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/index.html Creates an HTML file containing a summary table of Mplus model statistics. This function is useful for generating reports. ```APIDOC ## HTMLSummaryTable() ### Description Create an HTML file containing a summary table of Mplus model statistics. ### Method N/A (R function) ### Endpoint N/A (R function) ### Parameters - **summary_data** (data.frame) - Data frame containing summary statistics. - **output_file** (character) - Path for the output HTML file. ### Request Example ```R # Assuming 'model_summaries' is a data frame of summary statistics HTMLSummaryTable(model_summaries, "summary_report.html") ``` ### Response Generates an HTML file with the summary table. ``` -------------------------------- ### Basic Mplus Model with Bootstrapping Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/mplusModeler.html Sets up a basic Mplus model for bootstrapping, specifying categorical variables, weights, and included variables. The `mplusModeler` function is then used to run the analysis. ```R test4 <- mplusObject( TITLE = "test bootstrapping;", VARIABLE = " CATEGORICAL = cyl; WEIGHT = wt; USEVARIABLES = cyl mpg;", ANALYSIS = "ESTIMATOR = MLR;", MODEL = " cyl ON mpg;", usevariables = c("mpg", "wt", "cyl"), rdata = mtcars) res4 <- mplusModeler(test4, "mtcars.dat", modelout = "model4.inp", run = 10L, hashfilename = FALSE) # see the results res4$results$boot # remove files unlink("mtcars.dat") unlink("model4.inp") unlink("model4.out") ``` -------------------------------- ### Check Mplus Code for Long Lines Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/parseMplus.html This example checks Mplus code for lines that are too long (over 90 characters) without adding any semicolons. It assumes the code is otherwise syntactically correct. ```R test <- " MODEL: mpg cyl disp hp drat wt qsec vs am gear PWITH cyl disp hp drat wt qsec vs am gear carb; " cat(parseMplus(test), file=stdout()) ``` -------------------------------- ### Generate Markdown Summary Table with Custom Columns and Caption Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/SummaryTable.html Illustrates creating a summary table in markdown format, specifying which columns to keep, adding a caption, and setting a table split width. This is useful for reports. ```R SummaryTable(list(m1.fit, m2.fit), type = "markdown", keepCols = c("Title", "Parameters", "LL", "AIC", "CFI", "SRMR"), caption = "Table of Model Fit Statistics", split.tables = 200) ``` -------------------------------- ### Conditional Logic for Multiple Conditions Workaround Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/articles/vignette.html Shows a workaround for Mplus conditional tags that only support single conditions. This example uses nested conditional tags to achieve the effect of multiple conditions. ```plaintext [[model > 1]] [[classes != 1]] var3@0; !Mplus code here [[/classes]] [[/model > 1]] ``` -------------------------------- ### Create and run an Mplus model Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/confint.mplus.model.html Demonstrates how to create an Mplus model object using builtin data and run it using mplusModeler. This is a prerequisite for extracting confidence intervals. ```R test <- mplusObject( TITLE = "test the MplusAutomation Package;", MODEL = " mpg ON wt hp; wt WITH hp;", OUTPUT = "STANDARDIZED; CINTERVAL;", usevariables = c("mpg", "wt", "hp"), rdata = mtcars) res <- mplusModeler(test, "mtcars.dat", modelout = "model1.inp", run = 1L) ``` -------------------------------- ### Create and Plot Growth Mixture Models Source: https://github.com/michaelhallquist/mplusautomation/blob/master/docs/reference/plotGrowthMixtures.html Demonstrates creating a growth mixture model with 1 to 3 classes and then plotting the estimated and raw data trajectories. The time scale is explicitly defined for the plot. ```R mydat <- read.table("http://statmodel.com/usersguide/chap8/ex8.2.dat", header = FALSE)[, -6] res <- createMixtures(classes = 1:3, filename_stem = "ex8.2", model_overall = "i s | V1@0 V2@1 V3@2 V4@3; i s on V5;", rdata = mydat, OUTPUT = "tech11 tech14;", usevariables = c("V1", "V2", "V3", "V4", "V5"), run = 1L) plotGrowthMixtures(res, estimated = TRUE, rawdata = TRUE, time_scale = c(0, 1, 2, 3)) ```