Non Linear Modeling

Posted on
No user picture. linx Joined: 11/09/2010
Dear all:

I am new to OpenMx. I have a question non-linear modeling in openMx. I have been trying to utilize a framework that observed measurement variables determine latent variable, and latent variables impact observed outcome variable. The thing is that the way latent variables impact outcome variable is non linear. Is there a way to modify the mxPath command to allow nonlinear estimations?

Thanks!

-Lin

Replied on Fri, 11/12/2010 - 09:42
Picture of user. Steve Joined: 07/30/2009

Yes. The trick is to create an mxAlgebra that evaluates the nonlinear function and results in a 1x1 matrix. Then give the name of the mxAlgebra as the label for the chosen mxPath.

Replied on Mon, 11/15/2010 - 03:20
Picture of user. tbates Joined: 07/31/2009

In reply to by Steve

Hi Steve,
I added an mxAlgebra to a simple x->y model, calculating x^2

With the path free, I get
Error: In model 'play' the following are both named entities and free parameters: 'nonlin'
But fixing the path, I get
Error: In model 'play' the following are both named entities and fixed parameters: 'nonlin'

Catch 22? Or is a constraint needed, rather than matching labels?

Model code


x = 1:100; y = x^2; 
xy = data.frame(x=x,y=y)
manifests <- names(xy)

modelNon <- mxModel("play", type="RAM", manifestVars = manifests,
    mxPath(manifests, arrows=2),   # residual variance on manifests
	mxPath(from="x", to="y", arrows=1, free=T, values=1, labels="nonlin"),
	mxAlgebra(data.x^2, name="nonlin"),
    mxPath("one", to=manifests, arrows=1, free=T, values=1, labels=c("meanx", "beta0")),
	mxData(xy, type="raw")
)
fit1= mxRun(model); summary(fit1)

modelNon <- mxModel("play", type="RAM", manifestVars = manifests,
    mxPath(manifests, arrows=2),   # residual variance on manifests
	mxPath("x", to="y", arrows=1, free=T, values=1, labels="nonlin"),
	mxAlgebra(data.x^2, name="nonlin"),
    mxPath("one", to=manifests, arrows=1, free=T, values=1, labels=c("meanx", "beta0")),
	mxData(xy, type="raw")
)
fit2= mxRun(modelNon); summary(fit2)
Replied on Mon, 11/15/2010 - 07:36
Picture of user. mspiegel Joined: 07/31/2009

In reply to by tbates

Oops. Steve's advice is slightly outdated. We changed the rule so that free and fixed parameters would not be confused with matrices and algebras. You need to use square-brackets, like so:

modelNon <- mxModel("play", type="RAM", manifestVars = manifests,
    mxPath(manifests, arrows=2),   # residual variance on manifests
    mxPath("x", to="y", arrows=1, free=FALSE, values=1, 
         labels="nonlin[1,1]"),
    mxAlgebra(data.x^2, name="nonlin"),
    mxPath("one", to=manifests, arrows=1, free=T, values=1, 
          labels=c("meanx", "beta0")),
    mxData(xy, type="raw")
)
fit <- mxRun(modelNon); summary(fit2)
Replied on Mon, 11/15/2010 - 08:04
Picture of user. tbates Joined: 07/31/2009

In reply to by mspiegel

Thanks Mike: Very clear.

Would be helpful to update the error message from the existing one to:

Error: In model ''. '' is used in both a named entity (mxAlgebra) and a parameter label.

Or to be super-duper helpful, add. "If you want to fix a path to the value of an mxAlgebra, refer to the Algebra with square-bracket notation: i.,e, instead of
labels="nonlin"
use
labels="nonlin[1,1]"

Replied on Mon, 11/15/2010 - 11:51
Picture of user. neale Joined: 07/31/2009

In reply to by tbates

I like the super-duper helpful error message! My philosophy with error messages is that they should be somewhat similar to the steel barriers in the middle of highways. These are designed a) to stop the vehicle going, e.g., across the central reservation into oncoming traffic (like a bad software error) and b) to guide the vehicle back onto its likely intended path.