MplusAutomation包的使用 一

1、准备数据

prepareMplusData(my_data, "C:/Data_Analysis/Prepare Mplus.dat", keepCols=c("id", "item1", "item3", "item6"))

prepareMplusData(my_other_data, "C:/Data_Analysis/Prepare Dropped Mplus.dat", dropCols=c("baditem1", "baditem2", "baditem7"))

keepCols=: data.frame中的需要提取出来的数据

dropCols=:不需要的数据

如果不赋值,则输出整个data,但是没有特定的名字。

2、runModels(): 运行同一路径下的一组相关模型

> runModels("C:/Program Files/Mplus/Mplus Examples/Addendum Examples")

 3、Sometimes it is useful to organize models into one or more subdirectories where each subdirectory contains models for a particular outcome or analytic approach. 此时就需要将不同目的的文件夹分别放在不同的路径下。

> runModels("C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE)

 use the recursive parameter of runModels

4、运行日志的设置

> runModels("C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE, logFile="C:/CFALCA-Comparison-Log.txt")
Here, the file C:/CFALCA-Comparison-Log.txt will be created in the directory C:/.
To specify that no log file should be created, pass logFile=NULL to runModels.
> runModels("C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE, logFile=NULL)

5、是否跳过:如果路径中存在某个模型的outputfile。

> runModels("C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE, replaceOutfile="always")#default
> runModels("C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE, replaceOutfile="never")
> runModels("C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE, replaceOutfile="modifiedDate")

“modifiedDate”决定了给定输入文件是否存在现有的输出文件。 如果有的话,它会检查输入文件的修改日期是否比存在的输出文件新。 如果输入文件较新,则运行模型。 否则跳过。

6、 Displaying R output in the console

> runModels("C:/Data_Analysis/ComparingLCAvCFA", recursive=TRUE, showOutput=TRUE)

7、交互界面

> runModels_Interactive()

用于指定要运行的模型

8、readModels: Extracting all supported data from Mplus output

allOutput <- readModels("C:/Data_Files/CFANesting", recursive=TRUE)
#assuming there are multiple files in this directory, just model summaries could retained as a data.frame as follows: library(plyr) justSummaries <- do.call("rbind.fill",sapply(allOutput,"[", "summaries"))

The rbind.fill function is provided by the plyr package and is used to combine data.frames where the columns do not align perfectly (as happens when Mplus output files differ in the form of their summary statistics). The sapply call is used to extract only the summaries element from each top-level element (i.e., file).

 

posted @ 2017-04-17 00:20  JoAnna_L  阅读(939)  评论(0编辑  收藏  举报