Hi everyone,
I am writing an R function which can create and run an OpenMx model. I can do it in a simple way. Partial codes are shown below. However, I have over 20 definition variables and for each I need corresponding mxAlgebra. I may want to write a function/a loop to generate mxMatrix and mxAlgebra. I've tried a couple of methods, yet none of them worked. The mainly problem is that in the expression of mxAlgebra, I need call the name of corresponding mxMatrix. Thank you in advance!
mxMatrix("Full", 1, 1, free = T, values = 7, labels = "mu", name = "g"),
mxMatrix("Full", 1, 1, free = F, labels = "data.T1", name = "t1"),
mxMatrix("Full", 1, 1, free = F, labels = "data.T2", name = "t2"),
mxMatrix("Full", 1, 1, free = F, labels = "data.T3", name = "t3"),
mxMatrix("Full", 1, 1, free = F, labels = "data.T4", name = "t4"),
...
mxAlgebra(abs(t1 - g), name = "L20"),
mxAlgebra(abs(t2 - g), name = "L21"),
mxAlgebra(abs(t3 - g), name = "L22"),
mxAlgebra(abs(t4 - g), name = "L23"),
...
Does this solve your need?
Yes, it is my need. Thanks for your advice.
To elaborate on what Joshua wrote
This creates
mlist
, a list of MxMatrix objects, andalist
, a list of MxAlgebra objects.Thanks for your kind advice. I really appreciate it.