# mxCompare function

11 posts / 0 new
Offline
Joined: 09/05/2013 - 09:49
mxCompare function

Hi,

I tried to compare two CFA models using the mxCompare function. Unfortunately, I received the message:

Error in refSummary$modelName :$ operator is invalid for atomic vectors

At first I thought I had some code error but I run an example located in the help for mxCompare function, that is:

data(demoOneFactor)
manifests <- names(demoOneFactor)
latents <- c("G1")
model1 <- mxModel(model="One Factor", type="RAM",
manifestVars = manifests,
latentVars = latents,
mxPath(from = latents, to=manifests),
mxPath(from = manifests, arrows = 2),
mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),
mxData(cov(demoOneFactor), type = "cov", numObs = 500)
)

fit1 <- mxRun(model1)

latents <- c("G1", "G2")
model2 <- mxModel(model="Two Factor", type="RAM",
manifestVars = manifests,
latentVars = latents,
mxPath(from = latents[1], to=manifests[1:3]),
mxPath(from = latents[2], to=manifests[4:5]),
mxPath(from = manifests, arrows = 2),
mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),
mxData(cov(demoOneFactor), type = "cov", numObs=500)
)
fit2 <- mxRun(model2)

mxCompare(fit1, fit2)

In this situation, I received the same error message.
Error in refSummary$modelName :$ operator is invalid for atomic vectors
What's wrong?

best regards,
Krzysztof

Offline
Joined: 12/12/2012 - 12:15
version?

Which version of OpenMx are you using? What is the output of mxVersion() ? Here is what I get for your example,

> mxCompare(fit1, fit2)
base comparison ep  minus2LL df         AIC   diffLL diffdf  p
1 One Factor       <NA> 10 -3660.597  5   -2.606207       NA     NA NA
2 One Factor Two Factor 10 -2456.240  5 1201.750901 1204.357      0 NA
Offline
Joined: 09/05/2013 - 09:49
mxVersion

The output of mxVersion() is

OpenMx version: 2.6.9 [GIT v2.6.9]
R version: R version 3.2.5 (2016-04-14)
Platform: x86_64-w64-mingw32
Default optimiser: SLSQP

Offline
Joined: 12/12/2012 - 12:15
2.8.3

Can you upgrade to 2.8.3 and try again?

Offline
Joined: 09/05/2013 - 09:49

> mxVersion()
OpenMx version: 2.8.3 [GIT v2.8.3]
R version: R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32
Default optimiser: CSOLNP
NPSOL-enabled?: No
OpenMP-enabled?: No

But it doesn't help.

Krzysztof

Offline
Joined: 12/12/2012 - 12:15
specifically?

Can you post a script that demonstrates what doesn't work?

Offline
Joined: 01/24/2014 - 12:15
I'm also curious to see a

I'm also curious to see a complete script that demonstrates the issue. Are you loading a saved R workspace, or any .RData file, before you encounter this issue? Also, please make sure your script makes clear the exact order in which packages are loaded into R's workspace.

Offline
Joined: 09/05/2013 - 09:49

Yes, I was loading a saved R workspace and the trying to compare two models. When I created a completely new project and re-run my models, the previously reported problem disappeared. Thank you for your help!
Krzysztof

Offline
Joined: 01/24/2014 - 12:15
OK, good

OK, good, I'm glad it's resolved and working for you.

Offline
Joined: 03/01/2013 - 14:09
Rebuild models after upgrading OpenMx Version

IMO, we don't do a good enough job telling users that models will likely have to be re-run with a new version of OpenMx, i.e., mxModels in .Rdata files will likely not be compatible with a new version. It would be better if we could reliably tell users when that would be necessary - because we have changed the structure of mxModel objects to the point of incompatibility with prior versions. We might even consider using our upgrade numbering system to validate what would and what would not work from a prior version - version changes in the z of version x.y.z would not require re-running models, whereas changes of x or y would require it. That is not, I think, the way we use it now. This change would, of course, require a test...

Offline
Joined: 12/12/2012 - 12:15
some improvement

See v2.8.3-7-ga05220da3 for some improvement in this direction.