Specifying a SEM mode from Mplusl in rstan

Hi everyone,

I am new to rstan. I am trying to make a structural equation model in rstan that I already created in Mplus - would appreciate any help on how to do this.

Also, I assume I can just import the datafile directly as a csv file?

In Mplus, the syntax is:

[ DP17 ] (P1) ;
[ BREAMEAN ] (P2) ;
[ PAMEAN ] (P3);
[ ALKMEAN ] (P4);
[ SMOKMEAN ] (P5);
[ ASES ] (P6);
[ GENDER ] (P7);
[ PUTD ] (P8);
[ PINNT ] (P9);
[ DEPMEAN ] (P10);
DP17 ON BREAMEAN (P11);
DP17 ON PAMEAN (P12);
DP17 ON ALKMEAN (P13);
DP17 ON SMOKMEAN (P14);
DP17 ON ASES (P15);
DP17 ON GENDER (P16);
DP17 ON PUTD (P17);
DP17 ON PINNT (P18);
DP17 ON DEPMEAN (P19);
BREAMEAN ON GENDER (P20);
BREAMEAN ON PUTD (P21);
BREAMEAN ON PINNT (P22);
PAMEAN ON GENDER (P23);
PAMEAN ON PUTD (P24);
PAMEAN ON PINNT (P25);
ALKMEAN ON GENDER (P26);
ALKMEAN ON PUTD (P27);
ALKMEAN ON PINNT (P28);
SMOKMEAN ON GENDER (P29);
SMOKMEAN ON PUTD (P30);
SMOKMEAN ON PINNT (P31);
ASES ON PUTD (P32);
ASES ON PINNT (P33);
DP17 (P34);
BREAMEAN (P35);
PAMEAN WITH BREAMEAN (P36);
PAMEAN (P37);
ALKMEAN WITH BREAMEAN (P38) ;
ALKMEAN WITH PAMEAN (P39);
ALKMEAN (P40);
SMOKMEAN WITH BREAMEAN (P41);
SMOKMEAN WITH PAMEAN (P42);
SMOKMEAN WITH ALKMEAN (P43);
SMOKMEAN (P44);
ASES (P45);
GENDER (P46);
PUTD WITH GENDER (P47);
PUTD (P48);
PINNT WITH GENDER (P49);
PINNT WITH PUTD (P50);
PINNT (P51);
DEPMEAN WITH BREAMEAN (P52);
DEPMEAN WITH PAMEAN (P53);
DEPMEAN WITH ALKMEAN (P54);
DEPMEAN WITH SMOKMEAN (P55);
DEPMEAN WITH GENDER (P56);
DEPMEAN WITH PUTD (P57);
DEPMEAN WITH PINNT (P58);
DEPMEAN (P59);

With this prior for all parameters:
N(0.000,infinity) (normal distribution(mean, variance))

expect for parameter 34 and 45 which have:
IG(-1.000,0.000)

Hi, @MJO and welcome to the Stan forums.

You can import data into an R data frame that way, but then you need to put it into the appropriate structured list object to give to Stan. I’d recommend starting with a simpler model and getting that running first to understand the API.

Stan doesn’t allow you to explicitly provide improper priors. If you declare a parameter and do not provide a distribution, it’s assumed to be uniform on its support (e.g., uniform on all of real numbers or on positive real numbers). We generally recommend at least weakly informative priors to establish the relevant scale of the answer.

I don’t know Mplus or SEM, so can’t help you with that. If you could write down the corresponding log density, we could help translate.

1 Like

Specifying SEM models can be quite tricky. However, your model is not actually an SEM - since that involves regressions between latent variables. Your Mplus syntax appears to specify a path analysis model (regressions between observed variables only), which you can specify using brms. I’d recommend reading the vignettes and tutorials which introduce the syntax for specifying regressions and correlations between variables: Bayesian Regression Models using Stan • brms

2 Likes

As @andrjohns pointed out, there aren’t any latent variables in your code (using the BY keyword in MPlus), so you should be able to estimate the model easily enough in brms. That said, if you’re going to extend this to include latent variables, you should look into blavaan, which takes lavaan syntax and estimates the model using Stan. Here is a helpful article. I’ve never used it, but it looks like lavaan has the function mplus2lavaan, which converts MPlus code to lavaan.