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.
84 stars 46 forks source link

Error in summary() method #74

Open andreaphsz opened 6 years ago

andreaphsz commented 6 years ago

I have fitted the model as described in Chapter 9.9 in the MPlus User Guide titled "EXAMPLE 9.9: TWO-LEVEL SEM WITH CATEGORICAL FACTOR INDICATORS ON THE WITHIN LEVEL AND CLUSTER-LEVEL CONTINUOUS OBSERVED AND RANDOM INTERCEPT FACTOR INDICATORS ON THE BETWEEN LEVEL" and get the error by summarising the fitted object (see code below): Error in sprintf("CFI = %s, TLI = %s, SRMR = %s \n", CFI, TLI, SRMR) : Object 'SRMR' not found

library(MplusAutomation)

data <- read.table("ex9.9.dat")

model <- mplusObject(
  TITLE = "this is an example of a two-level SEM with categorical
           factor indicators on the within level and cluster-level
           continuous observed and random intercept factor indicators
           on the between level;",
  rdata = data,
  VARIABLE = "NAMES ARE u1-u6 y1-y4 x1 x2 w clus;
          CATEGORICAL = u1-u6;
          WITHIN = x1 x2;
              BETWEEN = w y1-y4;
              CLUSTER IS clus;",
   ANALYSIS = "TYPE IS TWOLEVEL;
               ESTIMATOR = WLSMV;",
   MODEL = "
    %WITHIN%
    fw1 BY u1-u3;
    fw2 BY u4-u6;
    fw1 fw2 ON x1 x2;
    %BETWEEN%
    fb BY u1-u6;
    f BY y1-y4;
    fb ON w f;
    f ON w;"
)

fit <-  mplusModeler(model, modelout = "model1.inp", run = 1L)

summary(fit)  # bugy
JWiley commented 6 years ago

Thanks, will work on a more flexible option here. The challenge I've had is getting a "generic" summary for all the diverse types of Mplus models. That said, at the least I can make it fail gracefully and print whatever it can and just silently skip the stuff that's missing.

cateh commented 3 years ago

hello - I have a related question. I have a latent growth model with a categorical dependent variable, which runs fine and produces an output file with all fit indices eg. AIC BIC etc, identical to running the input file in Mplus. But the mplusobject does not hold any of the fit statistics. Is this a problem with the package or with my code? Here is the code: (data is in an r dataframe called df) m<- mplusObject( TITLE ="LGC; ", VARIABLE = "IDVARIABLE IS id ;CATEGORICAL = y_1 y_2 y_3 ;", ANALYSIS = "ESTIMATOR = MLR ; LINK=PROBIT ; STARTS = 10 ; ITERATIONS=5000 ;", MODEL = " i s | y_1@0 y_2@1 y_3@2 ;", OUTPUT = "TECH1 TECH4 CINTERVAL TECH10 ;" , SAVEDATA= "results;", usevariables =c("id","y_1","y_2","y_3") , rdata=df, autov = TRUE ) res<-mplusModeler(m,modelout="m.inp", check=TRUE, run=1L)

cateh commented 3 years ago

update - as a workaround, I realised adding TECH2 to the output command as an update provided the fit statistics: m1<- update(m OUTPUT = ~ "TECH2;") res1 <- mplusModeler(latgrow, modelout = "m1.inp", run = 1L)

whereas adding TECH2 to the original model command did not....