Hey everyone! I’m working on a Confirmatory Factor Analysis project using the Lavaan package in R. I’ve managed to extract the shared variance among my observed variables to generate factor scores, but now I’m having trouble isolating the unique variance for each indicator.
I noticed that while the summary shows the mean variances for my indicators, I can’t extract them in the same way I did for the factor scores. Below is a revised version of my approach:
library(lavaan)
# Define a new model
my_model <- '
factorA =~ var1 + var2 + var3
factorB =~ var4 + var5 + var6
'
# Fit the model with your dataset
fit_model <- cfa(my_model, data = dataset)
# Obtain factor scores
factor_scores <- lavPredict(fit_model)
# Incorporate the scores back into your dataset
dataset$scoreFactorA <- factor_scores[, 'factorA']
dataset$scoreFactorB <- factor_scores[, 'factorB']
Can anyone suggest how to extract the unique or residual variance for each observed variable? I’d appreciate any pointers or suggestions. Thanks a lot!
Hey Luke87! Interesting question you’ve got there about CFA residuals.
Have you tried using the inspect() function yet? It’s pretty nifty for digging into the nitty-gritty of your Lavaan model. Something like this might work:
residual_variances <- inspect(fit_model, what = "rsquare")
This should give you a list of R-squared values for each indicator. From there, you can calculate the residual variance as 1 minus the R-squared. It’s like reverse engineering the shared variance, you know?
Oh, and while we’re on the topic, have you considered looking at modification indices? They can sometimes point to unexpected relationships between your indicators that might be messing with your residuals.
What’s your take on using residuals vs. modification indices for model improvement? I’m always curious to hear different approaches!
I have used Lavaan in similar projects and found that obtaining the individual indicator residuals helps assess the model fit more comprehensively. Once you fit your model, you can simply call the residuals function with the appropriate option. For example, after fitting your model with cfa(…), you can do:
res ← residuals(fit_model, type = “raw”)
The diagonal values of the resulting matrix represent each indicator’s residual variance, that is, the unique variance not captured by the latent factors. Incorporating these values into your dataset can provide additional insights into the measurement properties, helping you evaluate the contributions and specific behavior of each observed variable. This approach has worked well for me and could enhance your model interpretation.
hey there luke87! ive done similar stuff before. for individual residuals, try using the resid() function on ur fitted model. it should give u a matrix with the residuals. like this:
residuals <- resid(fit_model)
then u can extract the diagonals for each indicators unique variance. hope this helps!