You are here

how to test is a model is a RAM model

6 posts / 0 new
Last post
tbates's picture
Offline
Joined: 07/31/2009 - 14:25
how to test is a model is a RAM model

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

Ryne's picture
Offline
Joined: 07/31/2009 - 15:12
Haven't gotten this far in

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.

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
omxModelType()

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"){
}

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
Your same code would work if

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.

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
old | new

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

:-)

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
This passes with the current

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

Log in or register to post comments