Search code examples
rr-lavaanstructural-equation-model

how test the difference in factor loadings of latent variable using lavaan package in R


How can I calculate the estimate of factor loading for latent variables between different data frames?

I have 3 data frames related to 1 latent variable (the same variables A B C D) but in different intervals.

  • dataframe1 (100-120 days). (1550 records)
  • dataframe2 (120-150 days). (1780 records)
  • dataframe3 (180-250 days). (1670 records)

package (lavaan)

model1 <- 'latent_variable1 =~ A + B + C + D
A~~B'
output1 <- cfa(model1, data=datafram1, std.lv=TRUE)
output2 <- cfa(model1, data=datafram2, std.lv=TRUE)
output3 <- cfa(model1, data=datafram3, std.lv=TRUE)

Now I would like to calculate the difference on the estimate between the 3 latent variables using SEM. Someone could help me?

example:

model<- 'latent_variable1 ~ latent_variable2 ~ latent_variable3'
output4<-sem(model, dataframe =????, std.lv=TRUE)

Solution

  • If I understood correctly, your aim is mainly to test the differences on the factor loadings on these 3 datasets. And, in fact, you do not have 3 latent variables, but just one, but applied in 3 different contexts. This is a specific type of the assessment for measurement invariance for latent variable.

    So, what you need is:

    1. merge the datasets into just one dataset, but an indication of their origin. Let's call it group
    datafram1$group<-"G1"
    datafram2$group<-"G2"
    datafram3$group<-"G3"
    
    df<-rbind(datafram1,datafram2)
    df<-rbind(df,datafram3)
    
    1. run a multi group assessment, using this group variable
    output1 <- cfa(model1, data=df, std.lv=TRUE, group="group")
    

    This will return 3 outputs, one per group, similar to assessing in the 3 different dataframes.

    1. You can now constrain the loadings to be equal
    output2 <- cfa(model1, data=df, std.lv=TRUE, group="group",group.equal="loadings")
    
    1. and we can assess the significance of the differences between them:
    anova(output1, output2)