Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lavaan-style syntax for OpenMx models #219

Open
jhorzek opened this issue Jul 31, 2023 · 2 comments
Open

lavaan-style syntax for OpenMx models #219

jhorzek opened this issue Jul 31, 2023 · 2 comments

Comments

@jhorzek
Copy link

jhorzek commented Jul 31, 2023

Hi,
I have recently spent some time on a side project, where I implemented a lavaan-like syntax for OpenMx in the R package mxsem. I've been made aware that there is already a somewhat similar syntax parser in umx (see here) and also one in metaSEM.
As mxsem is a small side project, I am not sure if it should remain a separate package or if integrating it in a bigger project would be better. I initially thought it could be interesting for OpenMx itself, but based on the feedback umx may be the better fit.
What would be your preference? Would you be interested in adding the mxsem functions to umx or would you prefer waiting for mxsem to be well tested as a separate package and then import it if necessary?

Demonstration

mxsem implements a custom syntax and does not rely on lavaan for the model parsing. I made this decision to easily extend the syntax in order to unlock some of the unique features of OpenMx while still keeping the syntax familiar to lavaan users. For instance, inspired by metaSEM, the current mxsem syntax allows for simple algebras and definition variables:

library(mxsem)
set.seed(9820)
dataset <- simulate_moderated_nonlinear_factor_analysis(N = 100)

model <- "
  # loadings
     xi =~ x1 + x2 + x3
     eta =~ y1 + y2 + y3
  # regression
     eta ~ {a0 + a1*data.k} * xi
"

mxsem(model = model,
      data = dataset) |>
  mxTryHard() |>
  summary()

Best,
Jannik

@lf-araujo
Copy link
Contributor

Definition variables can be added to the model with the below syntax, mixing with the lavaan syntax. Current implementation already accepts some algebra, if I am not mistaken.

m1 = umxRAM(data = mtcars, "#modelName
      mpg ~ wt + disp", umxPath(defn = "cyl"))
umxSummary(m1)

I think that it would be nice to expand the current code for parsing the lavaan syntax. Last word should be @tbates s, though.

@jhorzek
Copy link
Author

jhorzek commented Sep 20, 2023

Very interesting! Short update on mxsem: I've uploaded the package on CRAN because I wanted to share it easily with colleagues in a project I am currently working on. So, if you want to check out what mxsem can do, you can now install from CRAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants