You are here

OpenMx for R users

Primary tabs

Wiki home pagePlease add material here as you learn...

If you have questions not answers, then add those here: That's how a wiki works.

There are a few differences between OpenMx and the way other R packages handle some things: they're easy to learn, but important to know about.

First, many OpenMx objects have an internal "name" slot. When you refer to the object in modelling, it is this internal name which other OpenMX functions need to use, not the "name" of the variable in the R sense. To give an example:

This won't work:

  myAmatrix = mxMatrix('Full', nrow=1, ncol= 1, name='A')
  sum = mxAlgebra(myAmatrix+myAmatrix)
  mxModel(myAmatrix, sum)

but this will:

  myAmatrix = mxModel('Full', 1,1,T,1, name='A')
  sum = mxAlgebra(A+A)
  mxModel(myAmatrix, sum)

Next up, if you are familiar with R modeling functions such as lm() you might be expecting:

  1. To specify your model using a formula.
  2. Specify data using data =.
  3. That simply specifying the model in lm will also run it.
  4. That subsequent changes will be made via update().

SEM models are not be specified with formulae: instead you describe your model using mxModel to bring together necessary matrices or path statements, algebra, data, and objective function, and sub-models.

This model must then be run using mxRun(), which returns a fitted model.

Instead of updating an existing model, you provide it as the first parameter of an mxModel() statement, followed by the components you wish to add, overwrite, or remove, then you would call mxRun() on this new model:

so instead of

fit1 = mxModel(model1)

You would say:

fit1 = mxRun(model1)
model2 = mxModel(model1, ...)
fit2 = mxRun(model2)

Note, many convenience R functions do work: e.g. anova is an alias for mxCompare, so anova(model1, model2) works.

Note also, the umx package implements functions in OpenMx which work more like R users may be expecting. So umxRAM takes data in the data = parameter, runs the model by default, and supports S3 functions like plot. It also supports much of the syntax of lavaan, which can be useful for bringing models from that package into OpenMx.