how to test is a model is a RAM model

Posted on
Picture of user. tbates Joined: 07/31/2009

The new 2-part objectives in OpenMx mean an older method for testing if a model is a RAM model don't work

I used to say this:

(isS4(obj) && is(obj, "MxModel") && class(obj$objective)[1] == "MxRAMObjective")

What code do people recommend for backward (and preferably forward compatible testing of model type? Do we need to add a type= field to MXModel?

best, tim

Replied on Tue, 03/05/2013 - 16:25
Picture of user. Ryne Joined: 07/31/2009

Haven't gotten this far in the Expectation/Fit split, but it'll likely be as simple as replacing references to objective to references to expectation. I'll look into this more as we get closer to beta release.

Replied on Tue, 03/05/2013 - 17:08
Picture of user. tbates Joined: 07/31/2009

In reply to by Ryne

maybe an OpenMx supported function to maintain a robust backward compatible test for users. Perhaps allowing


omxModelType <- function(obj, typeList= (c("RAM", "LISREL", "MATRIX"){
# test each requested item
}

# typically called with one test case
if(omxModelType(m1, "RAM"){
}

Replied on Thu, 03/07/2013 - 17:12
Picture of user. mhunter Joined: 07/31/2009

In reply to by tbates

Your same code would work if you replace $objective with $expectation, and "MxRAMObjective" with "MxExpectationRAM". I'm not sure if that's the best practice, but it would work currently.

Replied on Thu, 03/07/2013 - 17:46
Picture of user. tbates Joined: 07/31/2009

In reply to by mhunter

this fails for current OpenMx.

class(obj$expectation)[1] == "MxExpectationRAM"

so the "good today, great tomorrow" test is

isModel = isS4(obj) & is(obj, "MxModel")
isRAM_Model = (class(obj$objective)[1] == "MxRAMObjective" | class(obj$expectation)[1] == "MxExpectationRAM")
isModel & isRAM_Model

:-)

Replied on Thu, 03/07/2013 - 18:16
Picture of user. mhunter Joined: 07/31/2009

In reply to by tbates

This passes with the current *source* build.

(isS4(obj) && is(obj, "MxModel") && class(obj$expectation)[1] == "MxExpectationRAM")

where obj is a fitted OpenMx model. I used demo/LatentGrowthCurveModel_PathRaw.R as a test case.


source("demo/LatentGrowthCurveModel_PathRaw.R")
obj <- growthCurveFit
(isS4(obj) && is(obj, "MxModel") && class(obj$expectation)[1] == "MxExpectationRAM")