You are here

Error: Cannot add the following item(s) into the model

Hi,
Not sure if this is by deisgn/necessity or something we can alter.

It is illegal to create variables other than mxModel components inside an mxModel. Therefore things like this fail (with errors that will be cryptic to users):
lboundList = c(rep(-3,times=nVar), rep(.0001,times=nVar*(maxThresholds-1))),
mxMatrix("Full", maxThresholds, nVar, free=T, lbound = lboundList, values=.5, name="baseAndIncrements"),

Because OpenMx tries to add the items of lboundList to the model:
Error: Cannot add the following item(s) into the model: -3Cannot add the following item(s) into the model: -3...

This is fine:

mxMatrix("Full", maxThresholds, nVar, free=T, lbound =c(rep(-3,times=nVar), rep(.0001,times=nVar*(maxThresholds-1))), values=.5, name="baseAndIncrements"),

But clumsy. Is there a way to say "make this in the global space so I can use it shortly", or do we have to make all our variables outside the model, then use them?

Reporter: 
Created: 
Thu, 07/29/2010 - 13:10
Updated: 
Fri, 07/30/2010 - 14:33

Comments

Umm, remove the comma between the lboundList variable declaration and the call to mxMatrix(). Then it works for me (assuming that nVar and maxThresholds are defined).

Hi Mike: thanks: that was not intuitive to me:
Perhaps it is just that OpenMx gets you in the habit of putting commas behind everything because you are inside a function... but it never occured to me that it would then be ok to sneak in variable definitions as statements between comma-delimitted parameters, esp. given the error.
I won't make the mistake again, but I imagine some users will follow in my footsteps...
Oh well.

t

Based on your code snippet, you might be trying to do the following:

mxModel('name', stuff = c(1,2,3,4,5), mxMatrix(values = stuff)).

However, the "=" operator in R serves two purposes. It can be either the assignment operator "<-" or the function call parameter operator. In this context, the "=" operator is interpreted the second way. Like I said, I can't be sure that you were trying to do that. But I'm trying to guess as to why you had commas in between the two expressions.

yes,

mxModel('name',
stuff = c(1,2,3,4,5),
mxMatrix(values = stuff)
).

OK: So in this situation, one needs to do assignment. That would explain why I had felt this used to work: will have been using <- previously.

Never seen a case before where <- and = had different outcomes. Now I have ;-)