Read Parameters of Model Results

295 views
Skip to first unread message

CHU-DING LING

unread,
Jun 26, 2017, 8:26:46 AM6/26/17
to MplusAutomation
Dear Dr. Hallquist, Dr. Wiley and colleagues,

 

I got to know the MplusAutomation package until yesterday. I feel so excited after practicing some examples provided in the vignette. So gorgeous! Thanks to Dr. Hallquist and Dr. Wiley, your work makes us more effective when doing data analysis with Mplus.

 

However, I am wondering whether I can realize some functions with MplusAutomation. More specifically, is it possible for me to read some parameters in the MODEL RESULTS section and then display them on the screen and/or save them in a HTML file? For example, considering a scenario of testing a moderating effect. Usually we run a path analysis with y as the dependent variable, and x, m, xm_int, c1, c2, c3 as the independent variable. In the independent variables, x, m and xm_int are focal variables, while c1, c2 and c3 are control variables. After running the model successfully, is it possible for me to keep the coefficients of x, m and xm_int on y, while drop the coefficients of c1, c2 and c3 on y? Furthermore, is it possible for me to display the selected coefficients on the screen and/or save them into a HTML file showSummaryTable and HTMLSummaryTable do?

 

I have searched the archives of the list and found someone suggest the MODEL CONSTRAINT command in Mplus. However, because of my limited experience of programing with R, I don’t know how to read the new added parameters from output of Mplus to R. Moreover, in the vignette, the author repeatedly mentions that the extracted parameters of single or multiple models are stored in data.frame. I guess we can read the data.frame and save it as a HTML or other types of file. Do you have any ideas?

 

I am looking forward to your suggestions. Thanks!

 

Best,

Chuding

Joshua Wiley

unread,
Jul 6, 2017, 3:44:40 PM7/6/17
to CHU-DING LING, MplusAutomation
Dear Chuding,

These days, I'm normally using screenreg() to print estimates to the screen or texreg() or htmlreg() for LaTeX or HTML versions of output (those three functions are interchangeable basically --- same arguments, just format output for screen, LaTeX, or HTML).  These functions come from the texreg R package, however, I have written methods for them to work with MplusAutomation.  Below are some examples of how it could work.  screenreg() and htmlreg() have an argument, omit.coefs = "" which takes a text string that is a regular expression of which coefficients to omit.  Note that the examples below require the development version of MplusAutomation.  If you don't have that, start by getting that as below:

install.packages("devtools")
install_github("michaelhallquist/MplusAutomation")


Once you have the devel version, the code below should work, and at least I think is the easiest way there is to interact with Mplus output for formatting and selecting different parts of the output you want to view.  I only show fit indices in the first example as they are somewhat silly in a multiple regression example, but I wanted to make it clear that you CAN request fit indices / summaries as well.


## assumes development version of MplusAutomation from GitHub
library(MplusAutomation)
library(texreg)

test <- mplusObject(
  MODEL = "mpg ON wt hp am vs;",
  OUTPUT = "CINTERVAL;",
  rdata = mtcars)
res <- mplusModeler(test, modelout = "model1.inp", run = 1L)

## all parameters
screenreg(res, cis = TRUE, single.row = TRUE,
          summaries = c("CFI", "RMSEA_Estimate"))


========================================
                  Model 1              
----------------------------------------
 MPG<-WT          -2.59 [-4.24; -0.94] *
 MPG<-HP          -0.03 [-0.05; -0.01] *
 MPG<-AM           2.42 [-0.07;  4.90] 
 MPG<-VS           1.79 [-0.60;  4.17] 
 MPG<-Intercepts  31.08 [24.97; 37.19] *
 MPG<->MPG         5.28 [ 2.69;  7.87] *
----------------------------------------
CFI                1.00                
RMSEA_Estimate     0.00                
========================================
* 0 outside the confidence interval



## omit unwanted parameters (e.g., AM and VS are covariates)
screenreg(res, cis = TRUE, single.row = TRUE,
          omit.coef = "(<-AM)|(<-VS)")

========================================
                  Model 1              
----------------------------------------
 MPG<-WT          -2.59 [-4.24; -0.94] *
 MPG<-HP          -0.03 [-0.05; -0.01] *
 MPG<-Intercepts  31.08 [24.97; 37.19] *
 MPG<->MPG         5.28 [ 2.69;  7.87] *
========================================
* 0 outside the confidence interval


## maybe you also do not want any variances / residual variances
screenreg(res, cis = TRUE, single.row = TRUE,
          omit.coef = "(<-AM)|(<-VS)|(<->)")

========================================
                  Model 1              
----------------------------------------
 MPG<-WT          -2.59 [-4.24; -0.94] *
 MPG<-HP          -0.03 [-0.05; -0.01] *
 MPG<-Intercepts  31.08 [24.97; 37.19] *
========================================
* 0 outside the confidence interval


## html version
htmlreg(res, cis = TRUE, single.row = TRUE,
        omit.coef = "(<-AM)|(<-VS)|(<->)")



--
You received this message because you are subscribed to the Google Groups "MplusAutomation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mplusautomation+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Joshua F. Wiley, Ph.D.
---
Lecturer
Monash Institute of Cognitive and Clinical Neurosciences 
School of Psychological Sciences
Monash University
---
Senior Partner, Elkhart Group Ltd.
http://elkhartgroup.com
Office: 260.673.5518

CHU-DING LING

unread,
Jul 8, 2017, 11:34:08 PM7/8/17
to Joshua Wiley, MplusAutomation

Dear Dr. Wiley,

 

Thanks for your information. Here I would like to share with another solution:

 

First I label all the coefficients I focus on, thus Mplus will put them in the “New Additional Parameters” section. And then read this section to a data frame. Finally, I write the results to a CSV or TXT file. Hope it is useful to the community!


library(MplusAutomation)


res <- readModels("D:/Examples/me_34.out", recursive=TRUE)


d <- res$parameters$unstandardized

newpara <- paramExtract(d, "new")


newpara <- as.data.frame(print(newpara))

write.table(newpara, "newpara.txt", sep="\t", quote=FALSE, na="NA")


CHU-DING LING

unread,
Jul 10, 2017, 8:41:23 AM7/10/17
to Joshua Wiley, MplusAutomation

Dear colleagues,

 

I have another question: is it possible to give a unique number for each input file both in the filename and in the TITLE section? For example, I have two iterators: DV and IV. And for DV, I have 4 types of measures; while for IV, I have 8 types of measures. So totally I have 4*8 = 32 types of alternative combinations. I am wondering whether we can insert the number “1” into the filename and TITLE section of “DV1-IV1.inp”. Similarly, can we insert number “32” into the filename and TITLE section of “DV4-IV8.inp”? Do you have any ideas? Thanks!

 

Best,

Chuding

Michael Hallquist

unread,
Jul 10, 2017, 10:51:46 AM7/10/17
to CHU-DING LING, Joshua Wiley, MplusAutomation
Hi Chuding,

This should be pretty standard using a template file. Here’s an example with one iterator, but it’s the same idea for 2. You can’t currently get the product of iterators (e.g., putting 32 in the filename in your case), but you could either name the files y each iterator, or if you like, switch to the mplusObject + mplusModeler approach, which gives you more programmatic control.

Best,
Michael

templateExample.txt

CHU-DING LING

unread,
Jul 18, 2017, 12:50:33 AM7/18/17
to MplusAutomation
Sorry, I forgot to send the mail to the list...

---------- Forwarded message ----------
From: CHU-DING LING <lingc...@gmail.com>
Date: 2017-07-18 10:46 GMT+08:00
Subject: Re: [MplusAutomation] Read Parameters of Model Results
To: Michael Hallquist <michael....@gmail.com>


Dear Dr. Hallquist and colleagues,

 

My friend has helped me worked out the syntax. You may have a look in the attachment. Hope it is useful to the community.

 

It indeed works in this simple example. However, I encounter another problem. I am undertaking a multilevel SEM analysis. And the command in the MODEL section is a little bit complex. I copy the model template into the MplusObject section and modify it according to the format of this function. But it doesn’t work out the results automatically for two reasons. One is the syntax cannot define the variables in the dataset automatically; the other is the character numbers in some lines exceed 90. I try to define the variables manually, and try to put those lines exceeding 90 characters into two lines. But both attempts fail. Do you have any ideas?

 

Thanks!

 

Best,

Chuding


TEST.R
Reply all
Reply to author
Forward
0 new messages