You are here

Creating a function that creates OpenMx models

4 posts / 0 new
Last post
rabil's picture
Offline
Joined: 01/14/2010 - 16:47
Creating a function that creates OpenMx models

I'm trying to write an R function that would create and run an OpenMx model. I can do this for a simple one factor model. I read in a data.frame for the data and construct all the paths and then do an mxRun. This works regardless of the number of variables in the data.frame. But I want to generate mxAlgebra statements (and other statements, like including parameters in an mxCI statement) which change depending on the number of variables. I've tried using "call" and can create individual mxAlgebra statements, but I cannot get mxModel to accept them when I try to generate them in a loop. What am I missing?

mspiegel's picture
Offline
Joined: 07/31/2009 - 15:24
I think this will help:

I think this will help: http://openmx.psyc.virginia.edu/thread/797

rabil's picture
Offline
Joined: 01/14/2010 - 16:47
Thanks but I'm not sure I

Thanks but I'm not sure I understand. I have no problem generating any number of mxAlgebra objects. The problem is, sometimes I might need 5 of them, sometimes 8, etc. I can write in a fixed number of mxAlgebra objects into the mxModel statement in the function. But how can I handle a variable number of mxAlgebra objects in the mxModel statement? Or do I have to construct the entire mxModel object in a similar fashion as you do for just the mxAlgebra object?

rabil's picture
Offline
Joined: 01/14/2010 - 16:47
Actually, I almost had it

Actually, I almost had it right. I had created the evaluated mxAlgebra's in a list but did not realize all I had to do was include the list name in the mxModel. (I was trying to use a loop through the list.) Your other comment that was referenced solved my problem. Thanks.