lavaan icon indicating copy to clipboard operation
lavaan copied to clipboard

mplus2lavaan produces errow with string "ly1 BY pc1_1* (l1_1)"

Open njaalf opened this issue 3 years ago • 1 comments

Running mplus2lavaan() on the .inp file given below produces

Error in gsub("(start\([^\)]+\)\|[\d-\.]+\)", "", cmd.split, : invalid regular expression '(start([^)]+)*|[\d-.]+*)' In addition: Warning message: In gsub("(start\([^\)]+\)\|[\d-\.]+\)", "", cmd.split, : PCRE pattern compilation error 'invalid range in character class' at '-.]+*)'

I have isolated the problem:

> lavaan:::parseConstraints("ly1 BY pc1_1* (l1_1)") Error in gsub("(start\([^\)]+\)\|[\d-\.]+\)", "", cmd.split, : invalid regular expression '(start([^)]+)*|[\d-.]+*)' In addition: Warning message: In gsub("(start\([^\)]+\)\|[\d-\.]+\)", "", cmd.split, : PCRE pattern compilation error 'invalid range in character class' at '-.]+*)'

Here is the .inp file:

TITLE: Factor Models for Categorical Data

DATA: FILE IS mhs.dat;

VARIABLE: NAMES ARE id pcomp_1 pcomp_2 pcomp_3 pcomp_4 motiv_1 motiv_2 motiv_3 motiv_4 pc1_1 pc2_1 pc3_1 pc4_1 mot1_1 mot2_1 mot3_1 mot4_1 mot5_1 pc1_2 pc2_2 pc3_2 pc4_2 mot1_2 mot2_2 mot3_2 mot4_2 mot5_2 pc1_3 pc2_3 pc3_3 pc4_3 mot1_3 mot2_3 mot3_3 mot4_3 mot5_3 pc1_4 pc2_4 pc3_4 pc4_4 mot1_4 mot2_4 mot3_4 mot4_4 mot5_4 male female ;

      MISSING = . ;
      USEVAR = pc1_1 pc2_1 pc3_1 pc4_1 pc1_2 pc2_2 pc3_2 pc4_2 ;
      CATEGORICAL = pc1_1 pc2_1 pc3_1 pc4_1 pc1_2 pc2_2 pc3_2 pc4_2 ;

ANALYSIS: TYPE = MISSING H1 MEANSTRUCTURE; ESTIMATOR = WLSM ;

MODEL: !Creating Latent Variables ly1 BY pc1_1* (l1_1) ; ly1 BY pc2_1* (l2_1) ; ly1 BY pc3_1* (l3_1) ; ly1 BY pc4_1* (l4_1) ;

    ly2 BY pc1_2* (l1_2) ;
    ly2 BY pc2_2* (l2_2) ; 
    ly2 BY pc3_2* (l3_2) ;
    ly2 BY pc4_2* (l4_2) ;

    !Threshold Information
    [pc1_1$1] (tau1a_1); [pc1_1$2] (tau1b_1); [pc1_1$3] (tau1c_1);
    [pc2_1$1] (tau2a_1); [pc2_1$2] (tau2b_1); [pc2_1$3] (tau2c_1);
    [pc3_1$1] (tau3a_1); [pc3_1$2] (tau3b_1); [pc3_1$3] (tau3c_1);
    [pc4_1$1] (tau4a_1); [pc4_1$2] (tau4b_1); [pc4_1$3] (tau4c_1);

    [pc1_2$1] (tau1a_2); [pc1_2$2] (tau1b_2); [pc1_2$3] (tau1c_2);
    [pc2_2$1] (tau2a_2); [pc2_2$2] (tau2b_2); [pc2_2$3] (tau2c_2);
    [pc3_2$1] (tau3a_2); [pc3_2$2] (tau3b_2); [pc3_2$3] (tau3c_2);
    [pc4_2$1] (tau4a_2); [pc4_2$2] (tau4b_2); [pc4_2$3] (tau4c_2);

    !Latent Variables Means @0
    [ly1@0 ly2@0] ;

    !Latent Variables Variances
    ly1@1 ly2@1;

    !Latent Variables Covariances
    ly2 WITH ly1 ;

OUTPUT: STANDARDIZED ; !PLOT: TYPE = PLOT3;

njaalf avatar Apr 21 '21 07:04 njaalf

The author (Michael Hallquist) has been informed. Let's hope he finds some time to fix this soon.

yrosseel avatar Jun 22 '21 15:06 yrosseel

I believe this was already fixed in a prior update (a while ago) since in the CRAN version, the code you sent ran without issue. I did find a few syntax changes and variations that weren't well supported (converted strangely), so I fixed that in a pull request.

Long story short, this is fixed.

michaelhallquist avatar Mar 19 '23 00:03 michaelhallquist