lavResiduals and robust estimators

156 views
Skip to first unread message

Maurus Küttel

unread,
Nov 17, 2022, 2:18:40 AM11/17/22
to lavaan
Hello

I fitted the following model, whitch worked great.

model <- '
            level: 1
            PoPWsum~PrPWsum
           
            level: 2
            PoPWsum~PrPWsum+P1+P2+P3+P4.1+P4oP4.1'

fit <- sem(model, MLC, cluster="ID_C", missing="fiml")

summary(fit, standardized=TRUE, rsquare=TRUE)
lavInspect(fit,"icc")


After that I tried to acess the residuals with lavResiduals(fit), to decide whether or not I 've got some problems with non-normality or heteroscedasticity of the residuals. 

What I got is an error message, which I do not understand: Error in GG %*% ACOV.res[[g]] : non-conformable arguments

My question: How can I access the Residuals of my model?


I tried also to fit the model with a robust estimator (as Yves proposed to do in a workshop):

model <- '
            level: 1
            PoPWsum~PrPWsum
           
            level: 2
            PoPWsum~PrPWsum+P1+P2+P3+P4.1+P4oP4.1'

fit <- sem(model, MLC, cluster="ID_C",estimator = "MLR", missing = "ml")

summary(fit, standardized=TRUE, rsquare=TRUE)
lavInspect(fit,"icc")

Unfortunatly this call caused 40 warnings. But just one of them is displayed when I access them with the warnings(fit)-call. This one does not seem to be harmful:

1: In lav_data_full(data = data, group = group, cluster = cluster,  ... :
  lavaan WARNING: 34 cases were deleted due to missing values in
          exogenous variable(s), while fixed.x = TRUE. Error in cat("1: In lav_data_full(data = data, group = group, cluster = cluster,  ... :\n  lavaan WARNING: 34 cases were deleted due to missing values in \n\t\t  exogenous variable(s), while fixed.x = TRUE.",  :
  argument 2 (type 'S4') cannot be handled by 'cat'

My question: Where have all the warnings gone? Should I care for the other 39 undisplayed warnings?


Thank you so much!! lavaan is great!

Maurus
 






Terrence Jorgensen

unread,
Dec 1, 2022, 8:33:52 AM12/1/22
to lavaan
I tried to acess the residuals with lavResiduals(fit), to decide whether or not I 've got some problems with non-normality or heteroscedasticity of the residuals. 

I think you are expecting residuals per row of data (differences between observed y and predicted y-hat).  But this function provides covariance/correlation residuals (differences between observed and model-implied covariance matrices).  SEM software is not in the business of providing y-hat values, like regression software would.


What I got is an error message, which I do not understand: Error in GG %*% ACOV.res[[g]] : non-conformable arguments

This is probably a result of only having a single outcome in your model, but I can't be sure.  Try fitting an analogous model with the Demo.twolevel example in lavaan, to see if you can replicate the error.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

 

Maurus Küttel

unread,
Dec 5, 2022, 4:40:47 AM12/5/22
to lavaan
Yes, thank you! I've just replicated the error with Demo.twolevel. So I draw the conclusiion, that this function is not available in the case of two level models. 

Yves Rosseel

unread,
Dec 30, 2022, 11:53:43 AM12/30/22
to lav...@googlegroups.com
On 12/5/22 10:40, Maurus Küttel wrote:
> Yes, thank you! I've just replicated the error with Demo.twolevel. So I
> draw the conclusiion, that this function is not available in the case of
> two level models.

There is only partial support. This will work:

lavResiduals(fit, zstat = FALSE, summary = FALSE)

But no 'standardized' values, or standard errors, ...

Yves.
Reply all
Reply to author
Forward
0 new messages