mxEval {OpenMx}R Documentation

Evaluate Values in MxModel


This function can be used to evaluate an arbitrary R expression that includes named entities from a MxModel object, or labels from a MxMatrix object.


mxEval(expression, model, compute = FALSE, show = FALSE, defvar.row = 1)



An arbitrary R expression.


The model in which to evaluate the expression.


If TRUE then compute the value of algebra expressions.


If TRUE then print the translated expression.


The row number for definition variables when compute=TRUE.


The argument ‘expression’ is an arbitrary R expression. Any named entities that are used within the R expression are translated into their current value from the model. Any labels from the matrices within the model are translated into their current value from the model. Finally the expression is evaluated and the result is returned. To enable debugging, the ‘show’ argument has been provided. The most common mistake when using this function is to include named entities in the model that are identical to R function names. For example, if a model contains a named entity named ‘c’, then the following mxEval call will return an error: mxEval(c(A, B, C), model).

If ‘compute’ is FALSE, then MxAlgebra expressions return their current values as they have been computed by the optimization call (using mxRun). If the ‘compute’ argument is TRUE, then MxAlgebra expressions will be calculated in R. Any references to an objective function that has not yet been calculated will return a 1 x 1 matrix with a value of NA.


The OpenMx User's guide can be found at

See Also

mxAlgebra to create algebraic expressions inside your model and mxModel for the model object mxEval looks inside when evaluating.


matrixA <- mxMatrix("Full", nrow = 1, ncol = 1, 
	values = 1, name = "A")
algebraB <- mxAlgebra(A + A, name = "B")

model <- mxModel(matrixA, algebraB)
model <- mxRun(model)
start <- mxEval(-pi * A, model)

## Not run: 
mxEval(plot(sin, start, B * pi), model)

# The statement above is equivalent to:

plot(sin, -pi, 2 * pi)

## End(Not run)

[Package OpenMx version 1.2.0-1931 Index]