Example Script for LDE estimation

Posted on
Picture of user. Steve Joined: 07/30/2009

Here is a very basic script for a univariate second order differential equation that Pascal Deboeck and I wrote yesterday. This is the infamous damped linear oscillator.

In order to give you some sample data to run it on, I have attached a data file and used a read.table file that accesses the data file in this post using its URL.

If you have comments, I'd like to hear them!

Replied on Mon, 12/22/2014 - 13:49
Picture of user. amullings09 Joined: 12/21/2014

Hey,

I am a new graduate student and am interested in using this model for my thesis. I am trying to practice with your demo oscillator data, and then plan on testing it with some of my own data. So far the function provided has worked, except it seems that one part of the function is outdated:

Warning message:
In mxMLObjective("R") :
Objective functions like mxMLObjective() have been deprecated in favor of expectation and fit functions.
Please use mxExpectationNormal(covariance= , ...) instead, and add a call to mxFitFunctionML()
See examples at help(mxExpectationNormal)

I was wondering whether someone could direct/guide me on what fit function would be best to use for the LDE estimator? I am new to SEM (e.g., First year MA candidate), so I am at a bit of a learning curve working with these functions in R.

Replied on Mon, 12/22/2014 - 14:31
Picture of user. mhunter Joined: 07/31/2009

In reply to by amullings09

You can ignore the warning if you want. The model still works fine. If the warning message bothers you, then you can replace the line

mxMLObjective("R"),

with the pair of lines

mxExpectationNormal("R"),
mxFitFunctionML(),

The single line above and the pair of lines are exactly equivalent in terms of the modeling procedures performed by OpenMx. You can verify this for yourself by running the model both ways and comparing the results.

We made the expectation-fit split in 2.0 because we realized that things like the mxMLObjective were really making two decisions: one, the model is for a covariance matrix "R" with a normal distribution (expectation normal), and two, we're going to fit the normal distribution with maximum likelihood (fit function ML).

Replied on Tue, 12/04/2018 - 18:18
No user picture. Hayafh Joined: 12/01/2018

Hi,
I tried running the LDE model using the code and the dataset given. However, I get the following warnings.
Warning message:
In mxMLObjective("R") :
Objective functions like mxMLObjective() have been deprecated in favor of expectation and fit functions.
Please use mxExpectationNormal(covariance= , ...) instead, and add a call to mxFitFunctionML()
See examples at help(mxExpectationNormal)
> ldeModel1Fit <- mxRun(ldeModel1)
Running LDE_Model_1 with 11 parameters
Warning message:
In model 'LDE_Model_1' Optimizer returned a non-zero status code 5. The Hessian at the solution does not appear to be convex. See ?mxCheckIdentification for possible diagnosis (Mx status RED).

With these warnings, I get extreme values for eta and zeta (I’m assuming that is what the estimates for matrix A are): -8 and -70, and there are NA’s for standard errors.

I have tried mxCheckIdentification(ldeModel1Fit) and got the following:
Model is locally identified
$status
[1] TRUE

$non_identified_parameters
[1] "LDE_Model_1.A[3,1]" "LDE_Model_1.A[3,2]" "LDE_Model_1.S[1,1]" "LDE_Model_1.S[1,2]" "LDE_Model_1.S[2,2]"
[6] "LDE_Model_1.S[3,3]" "LDE_Model_1.U[3,3]" "LDE_Model_1.U[4,4]" "LDE_Model_1.U[5,5]"

Replied on Fri, 12/07/2018 - 11:02
Picture of user. AdminNeale Joined: 03/01/2013

In reply to by Hayafh

Not sure what your version of OpenMx is (?), but the example works fine for me once I changed the url for the data from

demoOscillator <- read.table("http://openmx.psyc.virginia.edu/sites/default/files/demoOscillator.txt", col.names="x")

to

demoOscillator <- read.table("http://openmx.ssri.psu.edu/sites/default/files/demoOscillator.txt", col.names="x")

:

> mxCheckIdentification(ldeModel1Fit)
Model is locally identified
$status
[1] TRUE

$jacobian
LDE_Model_1.A[3,1] LDE_Model_1.A[3,2] LDE_Model_1.S[1,1] LDE_Model_1.S[1,2] LDE_Model_1.S[2,2] LDE_Model_1.S[3,3] LDE_Model_1.U[1,1] LDE_Model_1.U[2,2]
cov1_1 1.054973e-01 -0.0083329529 1.322023938 45.5491149 392.338181 0.164025 1 0
...snip...

$non_identified_parameters
[1] "None"

Replied on Fri, 12/07/2018 - 10:58
Picture of user. mhunter Joined: 07/31/2009

For the warning about mxMLObjective see the previous solution provided.

For the Mx status RED, I'd recommend setting a lower bound of about -10 or so on eta and zeta.

Replied on Sun, 12/09/2018 - 11:51
Picture of user. tbates Joined: 07/31/2009

Updated for modern fit function and new URL, and adding mxTryhard for code Red, I get this error


ldeModel1Fit <- mxTryHard(ldeModel1)
Fit attempt 0, fit=-1521.67613260047, new current best! (was 201.317056439741)
Error in eigen(fit$output$calculatedHessian, symmetric = T, only.values = T) :
infinite or missing values in 'x'

Guessing that the error should be suppressed in mxTryHard?

OpenMx version: 2.11.5 [GIT v2.11.5]
R version: R version 3.5.1 (2018-07-02)
MacOS: 10.14.2

Replied on Sun, 12/09/2018 - 14:04
Picture of user. AdminRobK Joined: 01/24/2014

In reply to by tbates

I reproduce the behavior you report.

Guessing that the error should be suppressed in mxTryHard?

Arguably, yes. But historically, I don't believe it ever has been. It probably only looks strange when you're running in an interactive session (in which case, nowadays, argument `silent` to `mxTryHard()` defaults to `TRUE`).