michaelhallquist / MplusAutomation

The MplusAutomation package leverages the flexibility of the R language to automate latent variable model estimation and interpretation using Mplus, a powerful latent variable modeling program developed by Muthen and Muthen (www.statmodel.com). Specifically, MplusAutomation provides routines for creating related groups of models, running batches of models, and extracting and tabulating model parameters and fit statistics.
81 stars 46 forks source link

Error when using readModels(): object 'ChiSqM_Value' not found #190

Closed KaiyeeHe closed 1 year ago

KaiyeeHe commented 1 year ago

While attempting to use readModels function to read models from Mplus output file, I received the following error message [Error in sprintf("Model: Chi2(df = %s) = %s, p = %s \n", ChiSqM_DF, ChiSqM_Value, : object 'ChiSqM_Value' not found].

Upon searching for a solution, I stumbled upon a similar problem posted on [https://github.com/michaelhallquist/MplusAutomation/issues/38]. I attempted to use the output file ex11.8part2.txt shared in the post, but still encountered the same error.

For your reference, I am using Mplus version 8.3 (Mac) and I have installed the MplusAutomation package in version 1.1.0 (R 4.2.1).

PS. Thank you for creating such a fantastic package!

KaiyeeHe commented 1 year ago

This issue has been solved by assigning the readModels() result to a variable instead of running readModels() directly. I have attached the codes below and hope it helps someone who meets the same error.

Previous: readModels(here("ex11.8part2.out"))

Current codes that work well. a <- readModels(here("ex11.8part2.out")) a$summaries

cjvanlissa commented 1 year ago

Hey @KaiyeeHe that doesn't solve the error, the error is in the print function ;)

Can you try to run:

install.packages("remotes")
remotes::install_github("michaelhallquist/MplusAutomation@fix190")

And then run your original code that errored?

linem7 commented 2 months ago

Hello both,

Thank you for your contributions to this matter. Despite trying the method suggested by @KaiyeeHe and @cjvanlissa, I am still unable to resolve my issue with extracting model fit information (such as CFI, TLI, etc.). The summaries within the object do not include the model chi2 and other indices. Could you advise on what steps I should take? Below is a snippet of my results. Thank you, everyone.


> readModels("./Mplus_Med/Execution/p1_acc", what = "summaries")

$p1_acc_mi_step1.out
p1_accuracy_mi_step1 

Estimated using ML 
Number of obs: 177, number of (free) parameters: 24 

Model: Chi2(df = 66) = 619.203, p = 0 
Baseline model: Chi2(df = 66) = 619.203, p = 0 

Fit Indices: 

CFI = 0, TLI = 0, SRMR = 0.302 
RMSEA = 0.218, 90% CI [0.202, 0.233], p < .05 = 0 
AIC = 3369.428, BIC = 3445.655 
NULL

$p1_acc_mi_step2.out
p1_accuracy_fiml 

Estimated using ML 
Number of obs: 177, number of (free) parameters: 40 

Fit Indices: 

CFI = NA, TLI = NA, SRMR = NA 
RMSEA = NA, 90% CI [NA, NA], p < .05 = NA 
AIC = NA, BIC = NA 
NULL

attr(,"class")
[1] "mplus.model.list" "list"  
` ``
linem7 commented 2 months ago

After consulting the Mplus support team. They informed me that as of version 8.10, Mplus only provides a single value for each fit index for continuous outcomes using maximum likelihood estimation, rather than detailed proportions and percentiles. Does this change affect how "MplusAutomation" retrieves and formats output from Mplus? Below is a snippet of my fit results for your reference, thank you guys!

Number of Free Parameters                       40

Loglikelihood

          H0 Value                       -2127.141
          H1 Value                       -1747.253

*   The loglikelihood cannot be used directly for chi-square testing with
    imputed data.

Information Criteria

          Akaike (AIC)                    4334.282
          Bayesian (BIC)                  4454.707
          Sample-Size Adjusted BIC        4328.115
            (n* = (n + 2) / 24)

Chi-Square Test of Model Fit

          Value                             56.175
          Degrees of Freedom                    48
          P-Value                           0.1953

RMSEA (Root Mean Square Error Of Approximation)

          Estimate                           0.034
          90 Percent C.I.                    0.000  0.066
          Probability RMSEA <= .05           0.768

CFI/TLI

          CFI                                0.890
          TLI                                0.849

Chi-Square Test of Model Fit for the Baseline Model

          Value                            140.614
          Degrees of Freedom                    66
          P-Value                           0.0000

SRMR (Standardized Root Mean Square Residual)

          Value                              0.588