New to OpenMx

7 replies [Last post]
mrubin's picture
Offline
Joined: 10/28/2011

Hi All-

I am new to OpenMx with some experience with biological path analysis using AMOS. I want to create a starting model (with all possible biological meaningful paths set as optional) and have OpenMx permute the model to test all possible combinations of optional paths. Then I will use one of the test statistics to select my final model for testing with independent data sets. I have been looking over the tutorials but have no idea where to even begin (i.e. which models,e ct.). If anyone could point me into the correct direction it would be greatly appreciated.

Best~
mrubin

Ryne's picture
Offline
Joined: 07/31/2009
Hello and welcome! While I'm

Hello and welcome!

While I'm not sure what the range of biological meaningful models is, what you're discussing seems to be very possible with OpenMx and R. The documentation chapters on multiple regression using either paths (http://openmx.psyc.virginia.edu/docs/OpenMx/latest/Regression_Path.html) or matrices (http://openmx.psyc.virginia.edu/docs/OpenMx/latest/Regression_Matrix.html) should be good places to start to learn about the path modeling capabilities of OpenMx. There are companion demo scripts already built into R; just type 'demo()' to see a list of script demos in all of the libraries you have loaded (they won't all be OpenMx demos), then something like 'demo(MultipleRegression_PathRaw)' to run any particular demo. Feel free to ask the forums for help on this.

Once you have built your starting model, you'll want to systematically edit your saturated model to change various parameters. You can look to the documentation chapter on mixture models for a little help on this, as that chapter makes a bunch of copies of a template model, then edits those copies to fit different models or change starting values. The 'omxSetParameters()' function takes a model and a list of names parameters (please name your free parameters, it'll make editing the template much easier) and allows you to change and edit those parameters to make new models.

Hopefully that will get you started, and let us know how we can help!

ryne

mrubin's picture
Offline
Joined: 10/28/2011
Thanks for the suggestions

Thanks for the suggestions Ryne, I will start with these tutorials today. The range of biologically meaningful models is likely to be very high for this project. Is is possible for R to automatically test all possible models given a starting model with all optional paths?

Best~
M

Ryne's picture
Offline
Joined: 07/31/2009
Sure. I can be more specific

Sure. I can be more specific with how to implement if you tell me more about your data, your "all possible" model and how much sophistication you want to/can include in your R scripts.

General workflow will go like this:
-Make template/"all possible paths" model. Store this in an object.
-Decide on what other models you'd like to test.
-Build a loop, lapply or other method to copy and edit your template once for every model to be fitted.
-Run the models, preferably by including them all in one giant container/holder model and run them all in parallel on a machine with a few cores.

Write some amount of code to let us know what you're trying to do and we'll help you fix it.

mrubin's picture
Offline
Joined: 10/28/2011
Model Comments 1

Hi Ryne-

Below is my code and I have attached my data file. The code is rough and I still do not really know what I am doing or what functions I should be running. I am going to outline, what I am trying to do in works since there will likely be no way you will get it from my code:

The data file contains geneotypic means for 82 genotypes and 4 traits of interest: Period, Phase, tGR1 and Rel Lifespan. The saturated model (starting model) should have arrow from Period to Rel Lifespan, Period to tGR1, Phase to Rel Lifespan, Phase to tGR1 and tGR1 to Rel Lifespan. All traits should also have an error term assoicates with then (I think this is mxPath, from=trait, arrow=2 in OpenMx). All arrows are free or optional, meaning that they can be included or dropped from the model. Starting with the saturated model, I want to test every possible combination of the optional arrows and save the Information Criteria for each model to a file that I can later sort on whichever paramater I choose for model selection. This model testing step needs to be automated and have the ability to be spread across a cluster. This current model will run quickly but the upcomming models have upwards of 20 variables which will result in a vary large number of possible models to test.

Also, here are some other questions that I have:

Period and Phase are highly correlated in this data set, so I put a doule-sided arrow connecting them (this is what I would do in AMOS but I am not sure what to do in OpenMx).

I am not sure what to do with traits that may reciprically effect each other, i.e. Period may effect tGR1 and tGR1 may effect Period. I would think that I should put a single-headed arrow in both directions and allow them to be dropped systimatically in and out of the model but again I am not sure.

Also, I am not sure as mentioned above what higher level function I shouls be using (i.e. factor Model vs others). I would love your suggestions on this given my model description above.

Thanks for all your help Ryne!

Best~
mrubin

require(OpenMx)

data<-read.csv("Fall2008.csv")

factorModel <- mxModel(name="Fall2008.Model1",
type="RAM",

###Specified Paths in the saturated model
mxPath(from=data$tGR1, to=Data$Rel Lifespan),
mxPath(from=data$Period, to=data$Rel Lifespan),
mxPath(from=data$Phase, to=data$Rel Lifespan),
mxPath(from=data$tGR1, to=data$Rel Lifespan),
mxPath(from=data$Period, to=data$tGR1),
mxPath(from=data$Phase, to=data$tGR1),
###Error Paths for each variable
mxPath(from=data$tGR1, arrows=2),
mxPath(from=data$tRel Lifespan, arrows=2),
mxPath(from=data$tPeriod, arrows=2),
mxPath(from=data$tPhase, arrows=2)
mxData(observed=cov(data), type="cov", numObs=82)
)
###Want to run all possible models and print Information Criteria to a text file

AttachmentSize
Fall2008.csv 7.28 KB
Ryne's picture
Offline
Joined: 07/31/2009
Nice work. There are a few

Nice work. There are a few ways to do this, and I'll present the way I would do it.

You've done a good job setting up your initial saturated model. Here are a few tips to help you along
-you forgot to include a

manifestVars<\code> statement that identifies your variables
-you don't need to say <code>data$VarName<\code>; just the variable name will do
-spaces in variable names makes everything very complex. Rename "Rel Lifespan" to something like "Life". Remember that R is case sensitive
-future steps will be easier if you give your parameters labels
-you can do multiple paths in a single mxPath statement, like so:
 
<code>
mxPath(from=c("tGR1", "Period", "Phase"), to="Life", arrows=1,
free=TRUE, labels=c("b1", "b2", "b3"))
<\code>
 
-don't forget about starting values. While you don't need to worry too much about slow optimizations with a covariance matrix as data, you need to remember to give the variance terms non-zero starting values, less your optimization start with an expected covariance matrix of all zeros (which will fail to invert and crash the optimization).
-if you're going to test the direction of the arrows, you have to deal with model identification issues. i'd also make the parameters and label them for those extra paths, but set them to free=FALSE and values=0. 
-you're free to test the period-phase relationships using any type of association you want. The reason you may have heard to use a covariance rather than a regression is that all regressions in this type of multivariate model are conditional on the other parameters.
 
Once you have your saturated/template model, you can edit using the <code>omxSetParameters()<\code> function. View the help page for more info, but you'll do things of the following form, where we take the old model, and change some characteristics of the names parameters ("b1" is now set to free=FALSE).
 
<code>
newModel <- omxSetParameters(factorModel, labels="b1", free=FALSE)
 
Do that a bunch of times and run all of the models. If you feel you're far enough along to run either a for loop or run multiple models in parallel, we can help you with that too, but I don't want to overwhelm you or write your code for you. There exist a series of functions to yield all combinations (combinat or something. google it) of a set of numbers, which is one way to build a table or matrix of all possible parameter values/freedoms.

mrubin's picture
Offline
Joined: 10/28/2011
Thanks Ryne- I will put

Thanks Ryne- I will put together what I can, which will be rough. Can I email it to you? This is data that has not yet been published, so I would rather not post my data sets online.

Thanks for all your help!

Best~
Matthew

mdewey's picture
Offline
Joined: 01/21/2011
Are you thinking about

Are you thinking about modification indexes/indices?

http://openmx.psyc.virginia.edu/thread/1019