mxRowObjective() interface

2 posts / 0 new
Offline
Joined: 07/31/2009 - 15:24
mxRowObjective() interface

At the last developers meeting, we discussed changes to the mxRowObjective() interface that are intended to simplify the treatment of NA values in the backend. Currently there are no legitimate methods for inducing a NA value into a MxMatrix or MxAlgebra object. Any operation that produces a NA value (such as division by zero) should be throwing an error even if it currently does not. However, the mxRowObjective() objective function could allow definition variables to be populated with NA values.

To eliminate NA values in definition variables, the mxRowObjective() function will contain two additional MxMatrix objects. "filteredDataRow" is a row vector that contains all the non-NA values in each row of a full information calculation. "filteredDataRow" may change size for each row of the calculation. "existenceVector" is a fixed length vector of 1.0s and 0.0s that contains 0.0 iff the data set contains an NA value for that specific row and column. "existenceVector" can be used to filter the expected covariance matrix. We will provide several selection functions that can be combined with "existenceVector" to do the filtering. Can't use the [] operator to perform the filtering because OpenMx does not support logical types only numeric types.

At the conclusion of the dev meeting, it was decided that the new signature of mxRowObjective() would be the following:

mxRowObjective <- function(rowAlgebra, dimnames, rowResults = NA, filteredDataRow = NA,
&nbsp;&nbsp;&nbsp;existenceVector = NA, reduceAlgebra = NA)

"rowResults", "filteredDataRow", and "existenceVector" are MxMatrix objects that are created by the call to mxRun() and a specific names can be assigned to them. "reduceAlgebra" is entirely optional. One alternative would be to require fixed names for the three arguments.

Here is a compromise alternative. A default name for the three arguments is provided, but can be overwritten by the user:

mxRowObjective <- function(rowAlgebra, dimnames, rowResults = "rowResults", filteredDataRow
&nbsp;&nbsp;&nbsp;= "filteredDataRow", existenceVector = "existenceVector", reduceAlgebra = NA)
Offline
Joined: 07/31/2009 - 15:24
I've changed the signature of

I've changed the signature of mxRowObjective to the following:

mxRowObjective <- function(rowAlgebra, reduceAlgebra, dimnames, rowResults = "rowResults",
&nbsp;&nbsp;&nbsp;filteredDataRow = "filteredDataRow", existenceVector = "existenceVector")

Otherwise it is way too easy to leave off the reduceAlgebra from the objective function, and insert a reduceAlgebra into your model that is silently ignored. Our test case for the row objective function now looks like this (it doesn't handle missing data yet):

rmod <- mxModel("EZRowObjectiveTest",
mxData(observed=xdat, type="raw"),
mxAlgebra(sum(filteredDataRow), name="rowAlgebra"),
mxAlgebra(sum(rowResults), name="reduceAlgebra"),
mxRowObjective("rowAlgebra", "reduceAlgebra", dimnames = c("a", "b"))
)

If your row objective function will not perform a reductive step, then insert the algebra mxAlgebra(rowResults, name = "reduceAlgebra") into your model.