Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract factor loadings from lavaan?

Tags:

r

r-lavaan

How can I get a table with all of the latent factors and the loading of each measurement item on all factors? I can't seem to find a way to pull this out of a fit lavaan model. Here is the general code I'm using to generate the model fit.

library(lavaan)
fit <- sem(mySemModel, data=df, std.ov=TRUE, std.lv=TRUE)
summary(fit, fit.measures=TRUE, rsq=TRUE, standardized=TRUE)

I'm looking for the same kind of output that you'd get from an EFA. For example, if I ran the code:

library(psych)
myFA <- fa(tpblatentData, 2)
print(myFA)

I would get something like this:

               PA1   PA2
Qitem1              0.74
Qitem2              0.82
Qitem3              0.87
Qitem4        0.98      
Qitem5        0.94      
Qitem6        0.89      
like image 440
Jim Avatar asked Feb 25 '14 19:02

Jim


2 Answers

You can get the standardized loadings of the model in matrix form by using the inspect function from the lavaan package. The following code will return the lambda (factor loadings), theta (observed error covariance matrix), psi (latent covariance matrix), and beta (latent paths) matrices.

inspect(fit,what="std")

It appears from your example that you are looking for the factor loadings, which are in the lambda matrix:

inspect(fit,what="std")$lambda

In like manner, you can extract unstandardized parameters by specifying "est" instead of "std".

like image 187
Joel Schneider Avatar answered Nov 09 '22 12:11

Joel Schneider


I found Joel's answer helpful. Another thing that might help is attributing the loadings result to a variable.

Since the inspect() function returns a list, this for me was useful:

model_loadings <- inspect(model_fit, what = "std")[["lambda"]]

Now I can use these values to calculate other interesting stuff.

like image 22
Gabriel Reis Avatar answered Nov 09 '22 13:11

Gabriel Reis