How do I update scripts from OpenMx 1 to OpenMx 2?

86 Views Asked by At

I have an example OpenMx script written a few years ago to do twin modelling.

It was written for OpenMx version 1.0 (script linked here )

When I run it, there are some warnings about updating fit functions and objectives. How should I update it to use OpenMx 2.0 fit function calls?

1

There are 1 best solutions below

0
On

There are a small number of changes from OpenMx 1.0 to 2.0 and higher. Nearly all scripts will run fine, but some pre-2012 or will benefit in features if you update for OpenMx 2.x

An example is referenced here

The user had hassles with:

1. No path to the helper functions

This is a more generic robustness issue for example R code: better to include web urls rather than disk-based file paths.

source("http://www.vipbg.vcu.edu/~vipbg/Tc24/GenEpiHelperFunctions.R")

A better solution is CRAN-based helper packages like umx. These are easier to keep up to date and accessible.

2. Old-style objectives (instead of expectations and fit functions)

Calls like this one are deprecated:

objMZ<- mxFIMLObjective(covariance="expCovMZ", means="expMean", dimnames=selVars)

It’s easy to update these across a stack of scripts, replacing mxFIMLObjective with mxExpectationNormal + a call to mxFitFunctionML

In addition, in old-style multiple-group objectives like this:

minus2ll <- mxAlgebra( expression = MZ.objective + DZ.objective, name="m2LL")
obj  <- mxAlgebraObjective("m2LL")

You should replace mxAlgebraObjective with mxFitFunctionAlgebra

However, OpenMx 2 has a neat Multigroup function which handles this in one line and enables identification checks, reference model generation etc.

So just replace the whole thing with (for example):

mxFitFunctionMultigroup(c("MZ", "DZ"))}