You are here

mxRun help

Primary tabs

Wiki home page

Please add material here as you learn...

The job of mxRun() is to send a Model to the Optimizer, which will optimize the model, i.e. will seek out values for all the free parameters in your model which maximise the likelihood of an objective function (which you also have to provide)

You call mxRun as follows:


where "model" is an mxModel object to be optimized. After it has run, mxRun returns a model, with the free parameters now set to their optimized values, and an "@output" component or "slot" with the results of the optimization.

Unlike much some other functions and packages you may be used to in R, OpenMx package separates the process of assembling your model and submodels from the the process of running the model. Imagine that instead of saying

  lm(x~y, data=mydata)

you said

  myModel <- lmModel(lmFormula(x~y), lmData(mydata), lmMethod="qr")

And you get the idea somewhat. . This lets you define a model without running it, and define sub-models which can be assembled into a supermodel before being run.

An Example

# Create a model that includes data, matrices A, S and F, and an objective function

  data <- mxData(mydata, type="cov", numObs = 100)
  objective <- mxRAMObjective('A', 'S', 'F')
  model <- mxModel("mymodel", A, S, F, data, objective)

# Use mxRun to optimize the free parameters in the matrices A and S

  model <- mxRun(model)

#print the output


Common Problems:
While OpenMx does a valiant job at error-checking the components of a model as they are created, much of the validity of a model cannot be assessed until it is run. Problems in your model which mxRun may highlight include:

  • Not including an appropriate objective function.
      The solution to this error is usually to ensure the top-level model includes the objective functions of its submodels, as well as an additional objective function describing how the results of the first two should be combined.
  • Including models which are dependent on or shares parameters with another model which is not included.
      The solution to this is include each of these models as arguments in another MxModel object which is passed to mxRun()