new 'compute' flag to mxEval()

8 posts / 0 new
Offline
Joined: 07/31/2009 - 15:24
new 'compute' flag to mxEval()

If 'compute' is FALSE (the default), then MxAlgebra expressions returns their current value 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. Users will like this feature because it allows them to compare the result of algebraic expressions as computed by the back-end against those values computed by R. Developers will like this feature because we can compute all our algebra expressions before invoking the optimizer in order to check for any non-conformable matrices in our matrix operations (without having to explicitly check, R does the heavy lifting for us).

Offline
Joined: 07/30/2009 - 14:03
This provides an interesting

This provides an interesting function for testing before submitting a job. I am not sure that "compute" is the most intuitive argument name.

Online
Joined: 07/31/2009 - 14:25

i get two different answers from

mxEval(C, fit)
mxEval(modelB.C, fit)

the set up is

A <- mxMatrix('Full', 2, 2, values = c(1,3,2,4), name = 'A')
B <- mxAlgebra(A + A, name = 'B')
C <- mxMatrix('Full', 2, 2,
labels = c('modelA.B[2,2]', 'modelA.B[2,1]',
'modelA.B[1,2]', 'modelA.B[1,1]'),
byrow = TRUE, name = 'C')

modelA <- mxModel('modelA', A, B)
modelB <- mxModel('modelB', C)
model = mxModel('supermodel', modelA,modelB)
fit    = mxRun(model)


At which point this gives the expected result:

mxEval(modelB.C, fit)
[,1] [,2]
[1,]    8    6
[2,]    4    2


but this doesn't

mxEval(C, fit)
# FullMatrix 'C'
@labels
[,1]            [,2]
[1,] "modelA.B[2,2]" "modelA.B[2,1]"
[2,] "modelA.B[1,2]" "modelA.B[1,1]"

@values
[,1] [,2]
[1,]    0    0
[2,]    0    0

Offline
Joined: 07/31/2009 - 15:24
This is not a bug. The named

This is not a bug. The named entity 'C' has the full name 'modelB.C'. You can use the short name 'C' only within the model 'modelB'. So the following produce identical results:

mxEval(modelB.C, fit)
mxEval(C, fit$modelB) However when you call mxEval(C, fit) then 'fit' doesn't have an entity named 'C', but R does have a variable named C and so the R variable is returned when an entity is not found. Offline Joined: 07/31/2009 - 15:24 Use mxEval(...,show = TRUE) Use mxEval(...,show = TRUE) to see what is evaluated by mxEval(). > mxEval(modelB.C, fit, show = TRUE) fit[["modelB.C"]]@values > mxEval(C, fit$modelB, show = TRUE)
fit\$modelB[["C"]]@values
> mxEval(C, fit, show = TRUE)
C
Online
Joined: 07/31/2009 - 14:25
Hi Michael, I get the full

Hi Michael,
I get the full name behavior, but I wonder whether returning non-OpenMx objects which are not in the model is the right behavior for a function call mxEval()...?

I think it would reduce scripting errors if mxEval(objName,model) returned an error when it couldn't find an object called objName in the model - as it stands instead of getting an error when they make a mistake, people will get results that they can misinterpret.

Offline
Joined: 07/31/2009 - 15:24
mxEval() is a convenience

mxEval() is a convenience function that allows users to mix non-OpenMx entities with OpenMx entities to evaluate an arbitrary R expression. There's no way mxEval() should return an error when it can't find an object in the model. See ?mxEval for examples where non-OpenMx entities are mixed with OpenMx entities.

Online
Joined: 07/31/2009 - 14:25
Gotcha: I 've only used in

Gotcha: I 've only used in the simple "get this from the model" case.

cheers!,
t