Submodel testing: Dropping single parameters in a matrix

Posted on
Picture of user. trinewa Joined: 11/30/2009

Hi,
I am testing submodels under a multivariate (3 variables) common pathways ADE model. I want to run a submodel where I drop the specific d for the first of the three variables, but I keep getting error messages. I hope someone could help me out with this.

I have tried various versions of the procedure below:

multiComPathAEad1eModel <- mxModel(ADE_Common_Fit, name="multiComPathAEad1e",
mxModel(ADE_Common_Fit$ADE,
mxMatrix( type="Diag", nrow=nvar, ncol=nvar, free[1,1]=FALSE, values[1,1]=0, name="ds" )
)
)
multiComPathAEad1eFit <- mxRun(multiComPathAEad1eModel)

The error messages I keep getting are:

Error: unexpected '=' in:
" mxModel(ADE_Common_Fit$ADE,
mxMatrix( type="Diag", nrow=nvar, ncol=nvar, free[1,1]="
> )
Error: unexpected ')' in " )"
> )
Error: unexpected ')' in ")"

Replied on Fri, 11/12/2010 - 09:02
Picture of user. mspiegel Joined: Jul 31, 2009

When invoking a function, the syntax foo(a = 1, b = 2, c = 3) assigns the values 1, 2, and 3 to the variables a, b, and c. Since the function invocation binds a value to a variable, the square brackets cannot be used on the left-hand side of the binding.

One method to drop a free parameter would be to do the following:

multiComPathAEad1eModel <- mxRename(ADE_Common_Fit,     "multiComPathAEad1e")
multiComPathAEad1eModel$ADE.ds@free[1,1] <- FALSE
multiComPathAEad1eModel$ADE.ds@values[1,1] <- 0

Replied on Mon, 11/15/2010 - 03:32
Picture of user. trinewa Joined: Nov 30, 2009

In reply to by mspiegel

Thank you, that way it works.

One follow-up question:
I seem to be having trouble getting confidence intervals on the parameters within the new model. using the following syntax:

multiComPathAEad1eModel <- mxRename(ADE_Common_Fit, "multiComPathAEad1e")
multiComPathAEad1eModel$ADE.ds@free[1,1] <- FALSE
multiComPathAEad1eModel$ADE.ds@values[1,1] <- 0

mxCI(c('multiComPathAEad1eModel$ADE.al', 'multiComPathAEad1eModel$ADE.dl','multiComPathAEad1eModel$ADE.el', 'multiComPathAEad1eModel$ADE.f','multiComPathAEad1eModel$ADE.as', 'multiComPathAEad1eModel$ADE.ds','multiComPathAEad1eModel$ADE.es'))
multiComPathADEad1eFit <- mxRun(multiComPathAEad1eModel,intervals=T)

This is the only output I get :
MxInterval
@reference: multiComPathAEad1eModel$ADE.al multiComPathAEad1eModel$ADE.dl multiComPathAEad1eModel$ADE.el multiComPathAEad1eModel$ADE.f multiComPathAEad1eModel$ADE.as multiComPathAEad1eModel$ADE.ds multiComPathAEad1eModel$ADE.es
@lowerdelta: 3.841459
@upperdelta: 3.841459

This syntax produces the same result:
mxCI(c('ADE.al', 'ADE.dl','ADE.el', 'ADE.f','ADE.as', 'ADE.ds','ADE.es'))

Any idea what's wrong?

Replied on Wed, 11/17/2010 - 03:09
Picture of user. trinewa Joined: Nov 30, 2009

In reply to by mspiegel

I have tried the same syntax in order to drop the common D:

multiComPathAEad2eModel <- mxRename(ADE_Common_Fit, "multiComPathAEad2e")
multiComPathAEad2eModel$ADE.d1@free <- FALSE
multiComPathAEad2eModel$ADE.d1@values <- 0

but I get a new error message:

> multiComPathAEad2eModel$ADE.d1@free <- FALSE
Error in checkSlotAssignment(object, name, value) :
"free" is not a slot in class "NULL"
> multiComPathAEad2eModel$ADE.d1@values <- 0
Error in checkSlotAssignment(object, name, value) :
"values" is not a slot in class "NULL"

Writing free[1,1]
and values [1,1] does not help.

Why is this different, and what can I do if I want to drop one common factor and one of the parameters in the specific factors within the same sub model?

Replied on Wed, 11/17/2010 - 04:07
Picture of user. tbates Joined: Jul 31, 2009

In reply to by trinewa

whenever an assignment like that doesn't work, the thing to do is to try and access (rather than set) the path of interest, to make sure that you are addressing it correctly. Then if that is broken, go back up the chain of names to see where things are going wrong.

So if I saw
> multiComPathAEad2eModel$ADE.d1

return the error "free" is not a slot in class "NULL"

Then I think "so, d1 is coming back NULL - it doesn't exist." You can see this by saying:

   multiComPathAEad2eModel$ADE.d1

Then I would try

   multiComPathAEad2eModel$ADE

and see what is in there. My guess is the object you want is not called 'd1' but something else?

Finally, I bet you'd have a lot more luck doing this directly by building new matrices that do what you want and replacing the existing ones. So

newModel = mxModel(oldModel,name="new name",
mxMatrix( type="Diag", nrow=nvar, ncol=nvar, free=F, values=0, name="d1" )
)

that will give new a new model, with the d1 matrix fixed to 0 in place of whatever used to be there

best, tim

Replied on Wed, 11/17/2010 - 08:21
Picture of user. Steve Joined: Jul 30, 2009

In reply to by tbates

I would second Tim's advice. That's the way to go about it. Each line encapsulates its meaning so that you have the best chance of understanding your script when you go back and read it years later.

In general, I would avoid directly changing parameters by using the @ syntax unless you _really_ know what you're doing. We have these functions like "mxMatrix" or "mxPath" in order to reduce the time you spend poking around trying to find what to change and to reduce the chance that you might break your model by not updating all of the parts of a matrix in consistent ways.