Fri, 11/12/2010 - 05:10

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 ")"

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:

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?

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

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

You were right - the object's name was dl, not d1. Thanks for your patience, I will by me a new pair of glasses.

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.

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?

won't this work?

model = mxModel(model, mxCI(c('ADE.al', 'ADE.dl','ADE.el', 'ADE.f','ADE.as', 'ADE.ds','ADE.es')) ) # add CIs to model

fit = mxRun(model, intervals=T)

summary(fit)

Oops. Yes, Tim Bates suggestion is simpler and it will work.

Thanks to both - that solved the problems with the confidence intervals!

Only one argument per confidence interval for now. So you need to do:

`intervals <- lapply(c('ADE.al', 'ADE.dl','ADE.el', 'ADE.f','ADE.as', 'ADE.ds','ADE.es'), mxCI)`