OpenMx for R users

Wiki home page

Please 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 number of changes between R and OpenMx, mostly easy to learn.

In OpenMx, most objects have an internal "name" slot. It is this name which other OpenMX functions use in modelling. So it is not sufficient in OpenMx to assign an OpenMx object to a variable and then use this variable name in a model.

ie. this won't work:

  A <- mxModel('Full', 1,1,T,1)
  sum = mxAlgebra(A+A)
  mxModel(A,sum)

but this does
  Anything <- mxModel('Full', 1,1,T,1, name='A')
  sumthing = mxAlgebra(A+A, name='sum')
  mxModel(Anything, sumthing)

If you are familiar with R modeling functions such as lm() you will be expecting
1. To specify your model using a formula
2. That specifying the model in lm will also run it
3. That subsequent changes will be made via update()
4. That you might compare models with Anova(model1-model2)

SEM models can 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 is then 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 or remove, then you would typically call mxRun() on this new model:

so instead of

fit1 <-mxModel(model1)
update(fit,...)

You would say:
fit1 <-mxRun(model1)
model2 <-mxModel(model1, ...)
fit2 <-mxRun(model2)