You are here

Revision of Running models multiple times with different data or parameters from Fri, 08/28/2009 - 08:17

Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.

R allows you to create loops so that you can do things such as read in files one at a time and run a model on each of them.

For a model
myModel <- mxModel( blah blah blah ) # define a FIML model but don't put any data in it.

myParameters <- matrix(NA, 100, 5) # suppose 100 files and you want to save 5 parameters from each run

for (i in 1:100) {
tempFileName <- paste("myFile",i,".dat", sep=0) # Suppose files name myFile1.dat, myFile2.dat, etc.
tempData <- read.table(tempFileName) # Options to read.table would need to be set for your case.
tempResults <- mxRun(mxModel(myModel, mxData(tempData, type="raw")) #run OpenMx on one file
myParameters[i,] <- mxEval(A, tempResults)[1:5,6] #Suppose the parameters are in rows 1-5 of col 6 of A
Now you have a matrix, myParameters, that has just the parameters you wanted after 100 runs of OpenMx.

Multiple imputation and other resampling ideas
R has several helpful packages supporting this type of processing including 'pan', 'kmi', 'mitools', and 'MICE' under the "packages" link and search for multiple imputation