# Non Linear Modeling

9 posts / 0 new
Offline
Joined: 11/09/2010 - 21:12
Non Linear Modeling

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

Offline
Joined: 07/30/2009 - 14:03
Yes. The trick is to create

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.

Offline
Joined: 11/09/2010 - 21:12
Thanks!

Thanks!

Offline
Joined: 12/17/2012 - 05:31
Thanks

nice..

Offline
Joined: 07/31/2009 - 14:25
Hi Steve, I added an

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)

Offline
Joined: 07/31/2009 - 15:24
Oops. Steve's advice is

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)
Offline
Joined: 07/31/2009 - 14:25
Thanks Mike: Very

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

Offline
Joined: 07/31/2009 - 15:14
I like the super-duper

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.

Offline
Joined: 12/16/2010 - 10:11
tbates, Thansk for

tbates, Thansk for Information