I’m working on a confirmatory factor analysis using the lavaan package in R. I’ve set up a model with three factors: visual, textual, and speed. Each factor has three indicators. Here’s a snippet of my code:
library(psychometrics)
model_structure <- '
factor1 =~ indicator1 + indicator2 + indicator3
factor2 =~ indicator4 + indicator5 + indicator6
factor3 =~ indicator7 + indicator8 + indicator9
'
results <- confirmatory_analysis(model_structure, dataset = example_data)
summary(results)
I can easily get the factor loadings, but I’m stuck on how to extract the error variances for each individual indicator. Is there a straightforward way to do this in lavaan? I’ve looked through the documentation but couldn’t find a clear answer. Any help would be appreciated!
To extract individual item error variances in lavaan, you can use the ‘inspect’ function after fitting your model. Here’s how you can modify your code:
library(lavaan)
model_structure <- '
factor1 =~ indicator1 + indicator2 + indicator3
factor2 =~ indicator4 + indicator5 + indicator6
factor3 =~ indicator7 + indicator8 + indicator9
'
fit <- sem(model_structure, data = example_data)
error_variances <- inspect(fit, 'theta')
The ‘theta’ argument in the inspect function retrieves the error variances. You’ll get a matrix where the diagonal elements represent the error variances for each indicator.
If you want to see these in the context of your overall model results, you can also use:
summary(fit, standardized = TRUE)
This will give you a comprehensive output including standardized estimates, which can be useful for interpreting your results in relation to the error variances.
Remember to check the model fit indices to ensure your CFA model is appropriate before interpreting these values.
yo dude, i think i can help u out. after u fit ur model, try this:
fit <- sem(model_structure, data = example_data)
error_variances <- inspect(fit, 'theta')
this should grab those error variances for ya. The diagonal of ‘error_variances’ is what ur after. hope that helps! lemme kno if u need anything else
Hey there, BrilliantCoder23! 
I totally get your frustration with extracting those pesky error variances. Lavaan can be a bit tricky sometimes, right? 
Have you tried digging into the fit object after running your model? Something like this might work:
fit <- sem(model_structure, data = example_data)
error_variances <- inspect(fit, 'est')$theta
This should give you a matrix with the error variances on the diagonal. Pretty neat, huh?
I’m curious though - what’s the end goal of your analysis? Are you comparing models or just trying to get a better understanding of your data? It’d be cool to hear more about your project!
Also, have you considered using standardized estimates? They can sometimes give a clearer picture of what’s going on with your indicators.
Let me know if this helps or if you need any more pointers. Always happy to brainstorm CFA stuff! 