Published on *OpenMx* (http://openmx.psyc.virginia.edu)

Wiki home page [1]

[toc list: ol; title: Table of Contents; minlevel: 1; maxlevel: 3; attachments: 1;]

Please add material here as you learn...

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

The purpose of mxEval() is to allow you to evaluate arbitrary R statements which may include data from inside a model.

mxEval() takes two essential parameters: the statement you want to evaluate, and a model in which to look for objects.

Optionally, you can include "compute=TRUE" to evaluate an OpenMx statement using R and "show=TRUE" to show where how mxEval translated your statement into full references to R and model objects

The simplest and most common use of mxEval is to extract a matrix from a model:

mxEval(M, model)

--> matrix M from model

*note*: If M is not found in the model, but an object called M exists in your R environment, mxEval will return that object. To avoid misleading results, use full object names, for instance, if the name of model is "model", this statement will only return M if model.M exists

mxEval(model.M, model)

--> matrix M from model

To refer to objects in submodels, use the submodel name

mxEval(mz.M+ dz.M, model)

--> sum of 'M' matrices found in submodels mz and dz

You can also do algebra and arithmetic inside mxEval, so this works:

mxEval(2 %x% **M**, model)

--> 2.**M**

Lastly, if there are definition variables in the model, then the results of mxEval() will by default be evaluated for the first row (which is what is in the output). To change which row of the dataset the mxEval() applies to, use its optional arguments, e.g.,

mxEval(mz.thresholds, **defvar.row=100, compute=TRUE, **model)

would evaluate the threshold algebra (or matrix) for the 100th row of the dataset supplied in the mxData() of the model.

**Links:**

[1] http://openmx.psyc.virginia.edu/wiki/main-page