omx[Get/Set]Parameters with anonymous free parameters

Posted on
Picture of user. mspiegel Joined: 07/31/2009
Forums
Since we were cleaning up the saving and loading of models (see http://openmx.psyc.virginia.edu/thread/1385), on a related matter I decided to support anonymous free parameters in the utility functions omxGetParameters() and omxSetParameters(). Anonymous free parameters (free parameters that have a label of 'NA') are now identified by the string "modelname.matrixname[row,col]". This notation will be available as input to the function omxSetParameters(), which currently rejects anonymous free parameters. The following demo will work in OpenMx 1.3.

require(OpenMx)

data(demoOneFactor)
manifestVars <- names(demoOneFactor)

factorModel <- mxModel("One Factor",
    mxMatrix(type="Full", nrow=5, ncol=1, values=0.2, free=TRUE, name="A",
        labels=letters[1:5]),
    mxMatrix(type="Symm", nrow=1, ncol=1, values=1, free=FALSE, name="L"),

    # the "U" matrix has 5 anonymous free parameters
    mxMatrix(type="Diag", nrow=5, ncol=5, values=1, free=TRUE, name="U"),

    mxAlgebra(expression=A %*% L %*% t(A) + U, name="R"),
    mxMLObjective(covariance="R", dimnames=manifestVars),
    mxData(observed=cov(demoOneFactor), type="cov", numObs=500)
)

params <- omxGetParameters(factorModel)
newFactorModel <- omxSetParameters(factorModel, names(params), values = 1:10)
newParams <- omxGetParameters(newFactorModel)

(If the example used symmetric matrices, both the cell and the transpose of the cell would have been populated)