Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using runmplus

    A few of us enjoy the wonderful runmplus package, which makes it possible to run Mplus from Stata, and with Stata code.

    I struggle with a few things, though. I haven't figured out to use two-worded commands (like Mplus' MODEL CONSTRAINT) and I struggle with applying loops for running Mplus models from Stata. If anyone using rumplus is willing to share code that go beyond the most elementary use of runmplus, I'd be very thankful. The models I run in Mplus are complex, but my coding in Stata is still elementary and not always successful...

    Guest
    Last edited by sladmin; 11 Dec 2017, 09:34. Reason: anonymize poster

  • #2
    I have had a similar experience with runmplus -- there are commands that don't seem to be handled properly and I recall a couple of other posts on this issue. For that reason, I much prefer to use stata2mplus to generate a data set readable by Mplus and the basic code to read it in and then work within the Mplus environment to generate the analysis. You can use Stata to do whatever data transformations you need first and then pass the data to Mplus via stata2mplus.

    I think once you get used to the Mplus environment you will find it to be more efficient to debug and modify code that way than going back and forth from Stata to Mplus. I have not pinned down exactly which Mplus commands don't work and it is possible that there is some basic point that I don't understand, but it is not worth my time to run this down. I suggest that you contact the author of runmplus with examples of what does not work.
    Richard T. Campbell
    Emeritus Professor of Biostatistics and Sociology
    University of Illinois at Chicago

    Comment


    • #3
      Well, my experience is somewhat different, which may reflect that particular work I do. I find the Mplus programming language very unnatural--it just isn't how I think. So I dislike using Mplus and welcome aids that can overcome its/my limitations. (And now that Stata can do SEM, I use Mplus much less than before, though I still fall back on it for things that Stata's -sem- and -gsem- commands don't support.)

      I have found that creating an Mplus data set is only one of the advantages of -runmplus-. It is also helpful in the following situations:

      1. There is a suite of analyses or models that you want to run in Mplus, and these differ by the values of a parameter. Then you can write a Stata loop over those values with a -runmplus- command inside it, the parameter value appearing in the appropriate place(s) in the command. (An example would be latent class modeling where the number of classes is not fixed ahead of time and you want to try out several possibilities.) While you could do this directly in Mplus through a bunch of copy and paste operations, that is tedious at best, error-prone at worst, and at any rate still leaves you to manually re-launch Mplus for each analysis. (Which also means you need to sit there while it all runs instead of going off to lunch and coming back to results.)

      2. Even better is the situation where you are constructing a complicated model with a lot of paths and a lot of covariances, but they follow some regular patterns (e.g. X1 WITH X2; X2 WITH X3; ... X9 WITH X10; U1 WITH U2; U2 WITH U3;...U9 WITH U10; X1 ON U1 Y; X2 ON U2 Y;...etc.). You can use Stata to build up a macro that specifies the model, and then pass it through -runmplus-. To my knowledge, Mplus is completely incapable of doing this directly and leaves you to type in all the paths by hand, and hope that you get it all right.

      I have yet to find an Mplus command that I couldn't pass through -runmplus-; but perhaps I just have never needed them in my work. I have not used, for example, the MODEL CONSTRAINT command mentioned by Guest. But I suspect that if he just puts it inside the -model()- option in -runmplus- (including the words MODEL CONSTRAINT and with a semicolon at the end of the constraint statement) it will fly. I know that works with MODEL INDIRECT.

      By the way, another very useful Stata tool is David Roodman's excellent -cmp-. While it is not specifically an SEM program, it does handle many models that -sem- and -gsem- can't do and one might otherwise be tempted to turn to Mplus for (e.g. finite mixture models).
      Last edited by sladmin; 11 Dec 2017, 09:34. Reason: anonymize poster

      Comment


      • #4
        I too find it very convenient using Stata code to run Mplus, even though I have used Mplus for many years. In contrast, I find the SEM language in Stata nonintuitive and less tempting than programming within Mplus'. This also goes for the output from SEM analyses in Stata. For me, this is a paradox. Stata's code is great, but not its SEM code.

        However, let med point out that instead of using this code in Mplus (or -runmplus-):
        X1 WITH X2; X2 WITH X3; ... X9 WITH X10;

        ... you can write
        X1 X3 X5 X7 X9 PWITH X2 X4 X6 X8 X10;

        ... or try X1-X9 PWITH X2-X10
        If the latter solution works (I don't know), Mplus will display a warning (correlation of variable with itself is omitted from the model), but that would not be a problem.

        In a similar manner, you can write X1 X2 PON U1 U2 instead of the more complex code.

        Beyond that... I really hope for better latent variables analyses in Stata, both in terms of coding and speed.

        Comment


        • #5
          Guest,

          Thanks. That's interesting. I was not aware that Mplus can do that. But are you sure that X1 X3 X5 X7 X9 WITH X2 X4 X6 X8 X10 won't also give me the (unintended) X1 WITH X4, X1 with X6, etc. The sequence I'm looking for is Xi WITH Xi+1, i = 1,...9. (I realize, in retrospect, that that wasn't clear from my post).
          Last edited by sladmin; 11 Dec 2017, 09:34. Reason: anonymize poster

          Comment


          • #6
            Clyde, P in PWITH and PON stands for pairwise. So...
            X1 X2 PWITH X3 X4
            is the same as
            X1 WITH X3; X2 WITH X4
            This is handy when you have many correlated residuals (I enter them with PWIN in runmplus).

            However, you asked whether WITH will give you X1 WITH X4. It will. But add the P so you get PWITH (caps not needed) or PON for regression.

            Comment


            • #7
              Correction..
              This will obviously not work

              X1-X9 PWITH X2-X10
              So drop that particular idea...

              However, PON and PWITH work fine if you declare each variable by its name.

              Comment


              • #8
                Thanks, Guest. I was not aware of that.
                Last edited by sladmin; 11 Dec 2017, 09:34. Reason: anonymize poster

                Comment


                • #9
                  Hi All,

                  Some two word Mplus commands have single word runmplus shortcuts. For example "population(foo; ) " is used for the Mplus "MODEL POPULATION:" command. These are documented in the help file.

                  For those two word Mplus commands that don't have corresponding one-word runmplus commands, you can just stick the command in the runmplus model command as Clyde mentions. I'll given an example. The thread mentions "MODEL CONSTRAINT".

                  In the Mplus version 7 user's Guide, example 3.10 is the first one to use "MODEL CONSTRAINT". You can run this using runmplus with:
                  runmplus u , ///
                  title(This is an example of non-linear constraint on the logit parameters of an unordered categorical (nominal) variable) ///
                  variable( nominal = u ; ) ///
                  model([u#1] (p1) ; [u#2] (p2) ; [u#3] (p2) ; model constraint: p2 = log ((exp (p1) - 1) /2 - 1) ; )
                  But that's too easy here's Example 5.20. It's a little more complicated and illustrates another quirk in translating between runmplus and Mplus

                  * This is MPUG example 5.20
                  * The MPUG example uses
                  * MODEL: f1 BY y1
                  * y2-y3(lam2-lam3);
                  * f2 BY y4
                  * y5-y6(lam5-lam6);
                  * And this kind of code won't fly with runmplus, because
                  * Mplus uses the line breaks between y1/y2 and y4/y5 to
                  * assign the parameter labels (lam2-lam3).
                  * So with runmplus we change those and add some new labels
                  * that end up not getting used, but don't hurt
                  runmplus y1-y6 , ///
                  title(this is an example of a cfa with parameter constraints) ///
                  model( ///
                  f1 by y1-y3 (lam1-lam3) ; /// this line different from MPUG
                  f2 by y4-y6 (lam4-lam6) ; /// this line different from MPUG
                  f1 (vf1) ; ///
                  f2 (vf2) ; ///
                  y1-y3 (ve1-ve3) ; ///
                  y4-y6 (ve4-ve6) ; ///
                  model constraint: new(rel2 rel5 stan3 stan6) ; ///
                  rel2 = lam2**2*vf1/(lam2**2*vf1 + ve2) ; ///
                  rel5 = lam5**2*vf2/(lam5**2*vf2 + ve5) ; ///
                  rel5 = rel2; stan3 = lam3*sqrt(vf1) /sqrt(lam3**2*vf1 + ve3) ; ///
                  stan6 = lam6*sqrt(vf2) /sqrt(lam6**2*vf2 + ve6) ; ///
                  0 = stan6 - stan3; ///
                  ve2 > ve5; ///
                  ve4 > 0 ; ) /// Note this is the close of the runmplus model command
                  standardized
                  runmplus parses commands at the ";" or ":" in the model command as input by the user. So you can pretty much put anything in there you'd like as far as two word commands goes.

                  Thanks to Christopher Bratt for finding my email in the help file and alerting me to this thread on Statalist.

                  Rich
                  Last edited by Rich Jones; 26 Feb 2015, 08:51.

                  Comment


                  • #10
                    Clyde Schechter mentioned some of the neat things you can do with runmplus.

                    One thing missing that I find very useful, and Dick Campbell might not now about, is that runmplus also reads the output file and saves estimation results and model fit statistics and other stuff. This is really handy for two things. First is if you're doing things like automatic document production or whatever in the spirit of reproducible research. No longer do you have to copy and paste from an OUT file to an excel file to build tables of your results. Some of my colleagues and I use LaTeX (Ben Jann's texdoc is really nice for this) to automatically build reports, tables, etc. Second is if you want to do a simulation and the Mplus simulation functionality can't be used.

                    I'm constantly updating runmplus, and periodically post updates to the cloud, and every rarely post updates to SSC. The best way to keep current is to

                    net install runmplus , from(https://s3.amazonaws.com/runmplusbucket) force

                    Unfortunately, I'm a lousy software programmer and don't adhere to good practices or even know what they are for version control etc. So if you're not current on your Mplus license, updating runmplus might be a bad idea. But if you run into trouble drop me a line. I have all the old ados saved and we can get you running again.

                    Rich



                    Comment


                    • #11
                      Rich... Thanks for the input! Very much appreciated.

                      A few things are missing in -return list- for runmplus. Like SRMR?

                      Guest
                      Last edited by sladmin; 11 Dec 2017, 09:35. Reason: anonymize poster

                      Comment


                      • #12
                        Hi Chris and others,
                        I just updated runmplus to report SRMR. Thanks for the heads up. The SSC version is not updated but the one on my AWS is.
                        To update your runmplus run:
                        net install runmplus , from(https://s3.amazonaws.com/runmplusbucket) force

                        Another recent addition is the reading and returning of the results of MODEL INDIRECT.

                        Please don't hesitate to send requests like this to my email noted in the help file.

                        Thanks
                        Rich


                        Comment

                        Working...
                        X