# Appending mxAlgebra expressions

3 posts / 0 new
Offline
Joined: 02/24/2010 - 19:14
Appending mxAlgebra expressions

Hello,

I am trying to generate mxAlgebra expressions from a size variable. I have a variable amount of mx submodels and am trying to add the objectives from these together for a full model objective. I have tried things like
mxAlgebra(sum(get(paste("submodel",1:x,".objective",sep=""))),
name="TotObj")
and other various methods. I also tried the method described on
but don't think this will help in my particular situation.
Any suggestions?

Best,
-LLL

Offline
Joined: 07/31/2009 - 15:24
The trick is to construct the

The trick is to construct the expression outside of the mxAlgebra() call and then feed the expression into mxAlgebra(). The mxAlgebra() will only recognize matrix operators or functions, so it barfs on the get() and the paste(). Try this:

modelnames <- c("model1", "model2", "model3")
objectives <- paste(modelnames, "objective", sep = ".")
objectives <- paste(objectives, collapse = " + ")
expression <- paste("mxAlgebra(", objectives, ", name = 'TotObj')", sep = "")
algebra <- eval(parse(text=expression))
Offline
Joined: 02/24/2010 - 19:14
Thanks a bunch. This did the

Thanks a bunch. This did the trick.