I'm trying to spec out a least-squares based optimizer using the mxAlgebraObjective, but I've been unable to include data in an algebra. Is that possible/feasible, or do I need to move to mxRObjective?
I guess I would recommend using mxRObjective since that is what it is designed for: Building new objective function classes without having to touch any C coding.
The disadvantage is that it may take more time to code and certainly will estimate more slowly.
The advantage is that it may speed the translation of the objective function into a C function(s) in the backend.
My advice is predicated on the idea that WLS in the backend is your target.
An mxAlgebraObjective only runs on the matrices and algebras included in the model directly, and doesn't use data from the mxData command. If you're trying to calculate an algebra based on a covariance matrix, just include the covariance matrix in the model as an mxMatrix. You can use something like:
myData <- matrix(....)
model <- mxModel(
mxMatrix(type="Full", nrow=nrow(myData), ncol = ncol(myData), free=FALSE, values=myData, name="theData")
Is that what you're looking for?
Yeah Steve has some models where he would like to use data inside a mxAlgebra statement. His current workaround is to include the data in a mxMatrix object. We talked about allowing data access from an algebra in the post-1.0 release.