A residuals(model) function

2 replies [Last post]
fife's picture
Offline
Joined: 07/01/2010

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.

tbates's picture
Offline
Joined: 07/31/2009
umx::residuals.MxModel

the umx helper package (now) has an S3 function implementing residuals()

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

fife's picture
Offline
Joined: 07/01/2010
Great! Thanks for doing that.

Great! Thanks for doing that.