library(lavaan)
setwd(mypath)  # change it to the path of your own data folder

repeat.data <- read.delim("ENGLISHchinese2.txt", sep = "\t", header = F)

colnames(repeat.data) <- c('read1', 'read3', 'list1', 'list3',
                           'speak1', 'speak3', 'write1', 'write3')

repeat.model <- '

# define the latent variables

english1 =~ 1*read1 + b*speak1 + c*write1
english3 =~ 1*read3 + b*speak3 + c*write3

# residual covariances

read1 ~~ read3
speak1 ~~ speak3
write1 ~~ write3

# intercepts

read1 ~ d*1
read3 ~ d*1
speak1 ~ f*1
speak3 ~ f*1
write1 ~ g*1
write3 ~ g*1

english1 ~ 0*1
english3 ~ NA*1


'

repeat.fit <- sem(repeat.model, data = repeat.data)
summary(repeat.fit, fit.measures = T, standardized = T)
## lavaan 0.6.15 ended normally after 93 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        23
##   Number of equality constraints                     5
## 
##   Number of observations                            86
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 1.663
##   Degrees of freedom                                 9
##   P-value (Chi-square)                           0.996
## 
## Model Test Baseline Model:
## 
##   Test statistic                               354.791
##   Degrees of freedom                                15
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.036
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1323.402
##   Loglikelihood unrestricted model (H1)      -1322.571
##                                                       
##   Akaike (AIC)                                2682.804
##   Bayesian (BIC)                              2726.982
##   Sample-size adjusted Bayesian (SABIC)       2670.191
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                    0.998
##   P-value H_0: RMSEA >= 0.080                    0.001
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.023
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   english1 =~                                                           
##     read1             1.000                               4.722    0.675
##     speak1     (b)    0.419    0.055    7.639    0.000    1.978    0.666
##     write1     (c)    0.941    0.117    8.044    0.000    4.445    1.050
##   english3 =~                                                           
##     read3             1.000                               4.573    0.641
##     speak3     (b)    0.419    0.055    7.639    0.000    1.916    0.632
##     write3     (c)    0.941    0.117    8.044    0.000    4.304    1.043
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##  .read1 ~~                                                              
##    .read3            12.787    3.716    3.441    0.001   12.787    0.452
##  .speak1 ~~                                                             
##    .speak3            2.971    0.704    4.218    0.000    2.971    0.571
##  .write1 ~~                                                             
##    .write3           -4.164    1.577   -2.641    0.008   -4.164   -2.516
##   english1 ~~                                                           
##     english3         20.379    5.301    3.844    0.000    0.944    0.944
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .read1      (d)   16.290    0.719   22.655    0.000   16.290    2.328
##    .read3      (d)   16.290    0.719   22.655    0.000   16.290    2.282
##    .speak1     (f)   17.674    0.310   57.029    0.000   17.674    5.953
##    .speak3     (f)   17.674    0.310   57.029    0.000   17.674    5.828
##    .write1     (g)   18.039    0.454   39.774    0.000   18.039    4.261
##    .write3     (g)   18.039    0.454   39.774    0.000   18.039    4.370
##     english1          0.000                               0.000    0.000
##     english3          2.269    0.357    6.356    0.000    0.496    0.496
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .read1            26.669    4.327    6.163    0.000   26.669    0.545
##    .speak1            4.899    0.798    6.141    0.000    4.899    0.556
##    .write1           -1.837    1.817   -1.011    0.312   -1.837   -0.102
##    .read3            30.035    4.708    6.380    0.000   30.035    0.590
##    .speak3            5.525    0.868    6.362    0.000    5.525    0.601
##    .write3           -1.491    1.775   -0.840    0.401   -1.491   -0.088
##     english1         22.296    5.779    3.858    0.000    1.000    1.000
##     english3         20.909    5.475    3.819    0.000    1.000    1.000

© Copyright 2024 @Yi Feng and @Gregory R. Hancock.