You are here

Referencing Data in an Algebra for mxAlgebraObjective

4 posts / 0 new
Last post
Ryne's picture
Joined: 07/31/2009 - 15:12
Referencing Data in an Algebra for mxAlgebraObjective

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?

tbrick's picture
Joined: 07/31/2009 - 15:10
An mxAlgebraObjective only

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?

mspiegel's picture
Joined: 07/31/2009 - 15:24
Yeah Steve has some models

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.

Steve's picture
Joined: 07/30/2009 - 14:03
I guess I would recommend

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.