equivalent of DROP in OpenMx interface
Posted on

There's been some discussion among the beta testers to support setting a free parameter to a fixed parameter across an entire model, or setting a fixed parameter to a free parameter across an entire model. Here's a function in R that will accomplish the transformation. The 'model argument is a MxModel object. The 'labels' argument is a vector of parameter names. The 'free' argument is either a NA or a single TRUE or FALSE. The 'value' argument is either a NA or a single numeric value. If 'free' is not NA, then all the parameters with name 'labels' will have their free/fixed status changed to 'free'. If 'value' is not NA, then all the parameters with name 'labels' with have their starting values changed to 'value'.
setParameters <- function(model, labels, free = NA, value = NA) { if(missing(model) || !is(model, "MxModel")) { stop("The 'model' argument must be a MxModel object") } if(missing(labels) || typeof(labels) != "character") { stop("The 'labels' argument must be a vector of characters") } if(!is.na(free) && (typeof(free) != "logical" || length(free) != 1)) { stop("The 'free' argument must be a single boolean value") } if(!is.na(value) && (!is.numeric(value) || length(value) != 1)) { stop("The 'value' argument must be a single numeric value") } return(setParametersHelper(model, labels, free, value)) } setParametersHelper <- function(model, labels, free, value) { model@matrices <- lapply(model@matrices, setParametersMatrix, labels, free, value) model@submodels <- lapply(model@submodels, setParametersHelper, labels, free, value) return(model) } setParametersMatrix <- function(matrix, labels, free, value) { select <- apply(matrix@labels, c(1,2), function(x) {!is.na(x) && x %in% labels}) if (!is.na(free)) { matrix@free[select] <- free } if (!is.na(value)) { matrix@values[select] <- value } return(matrix) }
Is this implemented in the
Is this implemented in the latest build? Do you have an example?
Thanks!
Log in or register to post comments
In reply to Is this implemented in the by Hermine
The functions are not part of
The functions are not part of OpenMx, so to implement it, you would simply paste the function code into your demo scripts: then it is available to be called.
I added an example using this (univariate ACE, dropping c by label)
trunk/models/passing/univACE_drop_helper.R
It would be great if this type of syntax worked
model = setParameters(model, labels=c("share.c1"), free = FALSE, value = 0)
i.e., pointing into a sub-model
also this highlights how helpful this parameter of summary() (or perhaps mxRun) would be
summary(fit, sat=xxx)
then the AIC would be computed between the old and new models.
Log in or register to post comments
In reply to The functions are not part of by tbates
setParameters() recursively
setParameters() recursively transforms all the parameters in the model hierarchy. To transform only a sub-tree the following would work:
To write a non-recursive version of setParameters, delete the second line in the setParametersHelper function.
Log in or register to post comments