lavaan
lavaan copied to clipboard
Issue with mplus2lavaan
Amazing package! So practical!
I am trying to translate mplus example 5.1 to lavaan syntax. However, I get the following error message:
Error in sub("^([^@]+)(@[\d-.]+)?$", "\2", v_post, perl = TRUE) : invalid regular expression '^([^@]+)(@[\d-.]+)?$' In addition: Warning message: In sub("^([^@]+)(@[\d-.]+)?$", "\2", v_post, perl = TRUE) : PCRE pattern compilation error 'invalid range in character class' at '-.]+)?$'
I downloaded example 5.1 directly from the Mplus website: https://www.statmodel.com/usersguide/chap5/ex5.1.inp
Kind regards, Martin
I think there is a similar problem in the mplus2lavaan.modelSyntax
.
The example code for this function gives me a similar error as @mhsteppan.
> syntax <- '
+ f1 BY x1*1 x2 x3;
+ x1 WITH x2;
+ x3 (1);
+ x2 (1);
+ '
> mplus2lavaan.modelSyntax(syntax)
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 did further digging into the code and I think that this particular error is in the function parseConstraints
. In this function, I get the error at this line:
cmd.nomodifiers <- paste0(gsub("(start\\([^\\)]+\\)\\*|[\\d-\\.]+\\*)", "", cmd.split, perl=TRUE), collapse=" ") #peel off premultiplication
I have notified the maintainer of mplus2lavaan() (Michael Hallquist). Hopefully, he will find time to fix this soon.
Hello all: I'm also getting the same error, both with the sample file and other files.
Has anyone managed a a fix? Alterantively, is there a known older version that runs without this error?
It would seem my email (to Michael Hallquist) was never sent. Not sure why. Sorry for the delay.
Hi all, sorry this issue has been unresolved for some time. It was just a small oversight in the regular expression -- I hadn't escaped the hyphen used to match negative numbers. The PR above fixes this and I verified the results with Mplus 5.1 and the example syntax above.
Could Mplus2lavaan read multi-group analysis files?
I get the following error message:
Error in gregexpr("(?!<(\\*|\\.))\\w+(?!(\\*|\\.))\\s*-\\s*(?!<(\\*|\\.))\\w+(?!(\\*|\\.))(@[\\d\\.-]+)?", :
My Mplus code is: `title: no days multigroup analysis; data: file is nodays.dat; vari: names are risk risk_cb12 ses gender age material space aut1 aut2 aut3 aut4 aur1 aur2 aur3 aur4 anx1 anx2 anx3 anx4 anx5; usev = risk_cb12 ses gender age material space aut1 aut2 aut3 aut4 aur1 aur2 aur3 aur4 anx1 anx2 anx3 anx4 anx5; grouping is risk_cb12(1 = low_medium 2 = high);
analysis: bootstrap = 10000;
model: inv by material space; aut by aut1 ant2 ant3 aut4; aur by aur1 aur2 aur3 aur4; anx by anx1 anx2 anx3 anx4 anx5;
inv on ses; aut on ses; aur on ses; anx on ses inv aut aur gender age; aut with aur;
model high:
inv on ses; aut on ses; aur on ses; anx on ses inv aut aur gender age; aut with aur;
output: cint(bcboot) stand;`
my R code is :
mplus2lavaan("nodays2.inp", run = F)
thank you guys
Hi there, I don't currently plan to extend mplus2lavaan to support multi-group models. The syntax between Mplus and lavaan diverges quite a bit in this setting and I don't have time to work on this at present.