Referencing Data in an Algebra for mxAlgebraObjective

Posted on
Picture of user. Ryne Joined: 07/31/2009
Forums
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?
Replied on Mon, 08/23/2010 - 13:02
Picture of user. tbrick Joined: 07/31/2009

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")
)

and then just use "theData" in your objective algebra.

Is that what you're looking for?

Replied on Mon, 08/23/2010 - 13:05
Picture of user. mspiegel Joined: 07/31/2009

In reply to by tbrick

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.
Replied on Thu, 08/26/2010 - 22:02
Picture of user. Steve Joined: 07/30/2009

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.