I am facing a problem concerning the output of standardized residuals for a fitted lavaan (sem)-object. As far as I do not include “cluster = ” in the fitting function, I can easily obtain the standardized residuals
But, as soon as include the cluster-argument (to take into account clustered data and correct the standard errors), I got this error message:
Fehler in Q %% ACOV.obs[[g]] : verlangt numerische/komplexe Matrix/Vektor-Argumente*
I played around with the Demo.twolevel-data included in lavaan, since I first thought it could be a problem with my data, but same here:
##packages
library(lavaan)
##models
# a) without cluster-variable
model <- '
fw =~ y1 + 1*y2 + y3
fw ~ x1 + x2 + x3
'
fit3 <- sem(model, data = Demo.twolevel)
summary(fit3, standardized=TRUE, fit.measures = TRUE)
lavResiduals(fit3, zstat = TRUE, se = TRUE) #works fine
Output:
lavResiduals(fit3o, zstat = TRUE, se = TRUE)#works fine
$type
[1] “cor.bentler”$cov
y1 y2 y3 x1 x2 x3
y1 0.079
y2 0.016 -0.081
y3 0.075 -0.074 0.000
x1 0.025 -0.032 0.015 0.000
x2 0.026 -0.030 0.011 0.000 0.000
x3 0.011 -0.015 0.007 0.000 0.000 0.000$cov.se
y1 y2 y3 x1 x2 x3
y1 0.010
y2 0.003 0.010
y3 0.010 0.009 0.000
x1 0.010 0.010 0.012 0.000
x2 0.010 0.010 0.012 0.000 0.000
x3 0.010 0.010 0.013 0.000 0.000 0.000$cov.z
y1 y2 y3 x1 x2 x3
y1 7.918
y2 4.800 -7.918
y3 7.253 -8.040 0.000
x1 2.406 -3.153 1.247 0.000
x2 2.520 -2.948 0.845 0.000 0.000
x3 1.078 -1.406 0.543 0.000 0.000 0.000
# b) with cluster-variable
model <- '
fw =~ y1 + 1*y2 + y3
fw ~ x1 + x2 + x3
'
fit3c <- sem(model, data = Demo.twolevel, cluster = "cluster")
summary(fit3c, standardized=TRUE, fit.measures = TRUE)
lavResiduals(fit3c, zstat = TRUE, se = TRUE) #does not work
residuals (fit3c, type= "cor.bentler")
Output:
lavResiduals(fit3, zstat = TRUE, se = TRUE)#does not work
Fehler in Q %*% ACOV.obs[[g]] :
verlangt numerische/komplexe Matrix/Vektor-Argumente
It seems that lavaan does not compute the statistics. I can still obtain the unstandardized residuals (but now, he gives $mean
in the output:
residuals (fit3o, type= "cor.bentler")
Output:
residuals (fit3o, type= “cor.bentler”)
$type
[1] “cor.bentler”$cov
y1 y2 y3 x1 x2 x3
y1 0.079
y2 0.016 -0.081
y3 0.075 -0.074 0.000
x1 0.025 -0.032 0.015 0.000
x2 0.026 -0.030 0.011 0.000 0.000
x3 0.011 -0.015 0.007 0.000 0.000 0.000$mean
y1 y2 y3 x1 x2 x3
0 0 0 0 0 0
My question is: How can I obtain the standardized residuals for the model with clustered data? At least, how can I obtain the corrected standard errors to manually compute the standardized residuals? (To my knowledge, the formula would be: unstandardized residual/corrected standard error).
Kindly, Marcus
PS: R-version: 4.2.0, lavaan-version: 0.6-17
Marcus P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.