9

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      
Jim
  • 11,229
  • 20
  • 79
  • 114
  • You can pull the estimates out using parameterEstimates(fit) – user20650 Feb 25 '14 at 20:26
  • parameterEstimates(fit) shows me the estimates of the items on the factors that I specified in the model, but it doesn't show me how items load on the other factors (unless I'm missing something). – Jim Feb 25 '14 at 21:29
  • More likely i am missing something. Yes you will only get loadings for the factors and items you specify. But I am assuming that you are doing an EFA (in a CFA framework) as you are comparing to fa in the psych package. So in lavaan i assume you will specify each item on each factor. So each estimate in the parameterEstimates returns the loadings on each factor. They are displayed long ways. This is how i would do an esem in Mplus - which is similar. Can you show your model – user20650 Feb 25 '14 at 22:34

2 Answers2

20

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".

W. Joel Schneider
  • 1,711
  • 13
  • 14
  • Thanks, i've tried your suggestion, but i found the lambda value is an integer. It should be a decimal number. – Fendi Tri Cahyono May 28 '17 at 03:24
  • All variables in my model are observed, no have laten variable. – Fendi Tri Cahyono May 28 '17 at 04:31
  • 1
    If all your variables are observed, the lambda matrix is irrelevant. Instead, look up the beta matrix: inspect(fit,what = "std")$beta – W. Joel Schneider May 29 '17 at 11:24
  • Thank's Joel, I have a SEM model without latent variable, but I have a problem to find a MLE or lambda, do you have solution for me? :D – Fendi Tri Cahyono May 29 '17 at 11:35
  • I am not sure what you mean. In the context of SEM with lavaan, lambda refers to the matrix of the observed variables' loadings on the latent variables. Because you have no latent variables, the lambda matrix should not matter. Perhaps you are referring to a different meaning of lambda? – W. Joel Schneider May 30 '17 at 11:54
  • Sorry, I wrote it's wrong. That I mean is Loading Factor. I have used factanal, but the result is different with estimation from lavaan when I'm multiply loading factor, L*L' (from factanal) – Fendi Tri Cahyono May 31 '17 at 09:37
2

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.

Martin Gal
  • 16,640
  • 5
  • 21
  • 39