Extracting Residual Varaince from Observed Indicators in CFA (Lavaan)

211 views
Skip to first unread message

Zach

unread,
Aug 31, 2022, 2:51:36 PM8/31/22
to lavaan
Hello All,
I posted this on another website but I think I may have better luck here. The over-arching goal of this question is to look at how variables in my main data frame associate with my broad latent factor vs narrower dimensions. Reproducible code is within the link.


Jasper Bogaert

unread,
Aug 31, 2022, 3:34:31 PM8/31/22
to lavaan
Hi Zach,

If all you want to do is extract the residual variance of observed indicators, you can just use:

lavInspect(mod.cfa, "est")$theta
or 
diag(lavInspect(mod.cfa, "est")$theta) 
if you want them as a named vector.

However, I am not sure whether this is what you meant.

Best wishes,

Jasper

Op woensdag 31 augustus 2022 om 20:51:36 UTC+2 schreef Zach:

Zach

unread,
Aug 31, 2022, 3:54:04 PM8/31/22
to lavaan
Hi Jasper,
Thanks so much for the reply. I believe you are very close, because theta is indeed the parameter I am interested in. My only concern is that this function returns me a single value, the estimate,  for each indicator. I am wondering if maybe I can get estimates for each observation used - Just as I did for the factor scores.

See this mention in Kim et al., 2021's Publication on Internalizing Dimensions and All-Cause Mortality :
 
"To model the transdiagnostic internalizing factor, we used confirmatory factor analysis (CFA), including four indicators (MDD, GAD, panic disorder, and neuroticism) assessed at MIDUS 1. After modeling internalizing, we saved the factor scores to include them in the main Cox regression model."
"In order to compare the predictive validity of internalizing versus disorder‐unique variance, we parameterized an explicit residual variance factor for each of the three internalizing disorders and neuroticism (i.e., the unique variance remaining in each indicator after the common variance is accounted for by the latent internalizing variable). We then saved the factor scores from transdiagnostic internalizing and the four construct residual factors, and regressed survival time on both internalizing and the residual factor scores simultaneously."

This is what I am trying to accomplish. Just as I used that for loop that gives me factor score estimates for each observation, I wish to do the same with residual variances for use in regression with an outside variable. Perhaps I can insert your suggested function in my for loop? Let me know your thoughts.

-Zach

Yves Rosseel

unread,
Sep 1, 2022, 6:56:31 AM9/1/22
to lav...@googlegroups.com
Zach,

You can reparameterize the model so that the 'residual errors' become
explicit latent variables in the model. Suppose the original model is

model <- '
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
'
fit <- cfa(model, data = HolzingerSwineford1939)

Then you can write it like this (using the lavaan() function to make
clear which parameters are included; everything else is fixed to zero):

model2 <- '
visual =~ 1*x1 + x2 + x3
textual =~ 1*x4 + x5 + x6

visual ~~ visual + textual
textual ~~ textual

fe1 =~ 1*x1; fe1 ~~ fe1
fe2 =~ 1*x2; fe2 ~~ fe2
fe3 =~ 1*x3; fe3 ~~ fe3
fe4 =~ 1*x4; fe4 ~~ fe4
fe5 =~ 1*x5; fe5 ~~ fe5
fe6 =~ 1*x6; fe6 ~~ fe6
'
fit2 <- lavaan(model2, data = HolzingerSwineford1939)

This will provide the same fit.

But now you can extract the 'factor scores', including those for the
residual variances:

lavPredict(fit2)

Yves.

Zach

unread,
Sep 1, 2022, 8:58:30 AM9/1/22
to lavaan
Hi Yves,
This is exactly what I have been looking for. This is also a great method because it still allows flexibility on how one may extract the factor scores,  e.g., lavPredict or fsr. Thanks so much for the help !

-Zach
Reply all
Reply to author
Forward
0 new messages