A residuals(model) function
Posted on

Forums
I think the subject says it, but I think it's awkward to have to type:
cov2cor(data.matrix(data)) - cov2cor(model$objective@info$expCov)
It seems like it would be simple to have a class (is that the term?) for the residuals function that operates on an mxobject. I often find myself looking at the residual covariance matrix to see where misfit lies.
umx::residuals.MxModel
Let me know how it works for you
library(devtools)
install_github("tbates/umx")
library(umx)
data(demoOneFactor)
latents = c("g")
manifests = names(demoOneFactor)
m1 <- mxModel("One Factor", type = "RAM",
manifestVars = manifests, latentVars = latents,
mxPath(from = latents, to = manifests),
mxPath(from = manifests, arrows = 2),
mxPath(from = latents, arrows = 2, free = F, values = 1.0),
mxData(cov(demoOneFactor), type = "cov", numObs = 500)
)
m1 = umxRun(m1, setLabels = T, setValues = T)
residuals(m1)
residuals(m1, digits = 3)
residuals(m1, digits = 3, suppress = .005)
a = residuals(m1);
a
Log in or register to post comments
In reply to umx::residuals.MxModel by tbates
Great! Thanks for doing that.
Log in or register to post comments
Have things changed??
My previous code for extracting residuals quit working. I remembered starting this topic and it seems that tbates's code no longer works either. Has OpenMx changed (again) how one calls the expected covariance matrix? If so, how do I access it? Is there a way to call it that won't change in the future? (I've got a package that depends on that and would hate to have to change it with each OpenMx update).
Log in or register to post comments
In reply to Have things changed?? by fife
After a whole lot of
model$objective[[2]]@info$expCov
So, we've got an S3 object (expCov) within an S4 object (info) within a list ([[2]]) within an S3 object (objective). Weird. By the way, I'm on R 3.1.1 and OpenMx_999.0.0-3473. I'm not sure if this is the most recent version, but I'm afraid I'll break everything if I update. :)
Log in or register to post comments
In reply to After a whole lot of by fife
Okay....I bit the bullet and
model$objective@info$expCov
Log in or register to post comments
In reply to Okay....I bit the bullet and by fife
avoid objective and @
Log in or register to post comments
In reply to avoid objective and @ by jpritikin
That doesn't work for me.
Log in or register to post comments