mxEval {OpenMx} | R Documentation |

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, cache = new.env(parent = emptyenv()), cacheBack = FALSE) mxEvalByName(name, model, compute = FALSE, show = FALSE, defvar.row = 1, cache = new.env(parent = emptyenv()), cacheBack = FALSE)

`expression` |
An arbitrary R expression. |

`model` |
The model in which to evaluate the expression. |

`compute` |
If TRUE then compute the value of algebra expressions. |

`show` |
If TRUE then print the translated expression. |

`defvar.row` |
The row number for definition variables when compute=TRUE. |

`cache` |
An R environment of matrix values used to speedup computation. |

`cacheBack` |
If TRUE then return the list pair (value, cache). |

`name` |
The character name of an object to evaluate. |

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)`

.

The `mxEvalByName`

function is a wrapper around `mxEval`

that takes a character instead of an R expression.

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 ‘cache’ is used to speedup calculation by storing previously computing values. The cache is a list of matrices, such that names(cache) must all be of the form “modelname.entityname”. Setting ‘cacheBack’ to TRUE will return the pair list(value, cache) where value is the result of the mxEval() computation and cache is the updated cache.

The OpenMx User's guide can be found at http://openmx.psyc.virginia.edu/documentation.

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

library(OpenMx) # Set up a 1x1 matrix matrixA <- mxMatrix("Full", nrow = 1, ncol = 1, values = 1, name = "A") # Set up an algebra algebraB <- mxAlgebra(A + A, name = "B") # Put them both in a model testModel <- mxModel(model="testModel", matrixA, algebraB) # Even though the model has not been run, we can evaluate the algebra # given the starting values in matrixA. mxEval(B, testModel, compute=TRUE) # If we just print the algebra, we can see it has not been evaluated testModel$B

[Package *OpenMx* version 2.1.0 Index]