library(lavaan)
#https://lavaan.ugent.be/tutorial/growth.html
dta<-read.csv("D://GSdata_20211113.csv", head=T, fileEncoding = "UTF-8-BOM")  
summary(dta)
 Placeofliving        Age           Gender          Weight      
 Min.   :1.000   Min.   :17.0   Min.   :1.000   Min.   : 40.00  
 1st Qu.:1.000   1st Qu.:20.0   1st Qu.:1.000   1st Qu.: 52.00  
 Median :1.000   Median :21.0   Median :2.000   Median : 58.00  
 Mean   :1.241   Mean   :21.6   Mean   :1.612   Mean   : 61.74  
 3rd Qu.:1.000   3rd Qu.:23.0   3rd Qu.:2.000   3rd Qu.: 70.00  
 Max.   :3.000   Max.   :30.0   Max.   :2.000   Max.   :135.00  
 NA's   :105                                                    
     Height           BMI            Major           TFEQ1r     
 Min.   :145.0   Min.   :15.35   Min.   :1.000   Min.   :1.000  
 1st Qu.:159.0   1st Qu.:19.53   1st Qu.:1.000   1st Qu.:2.000  
 Median :165.0   Median :21.60   Median :2.000   Median :2.000  
 Mean   :165.5   Mean   :22.39   Mean   :1.738   Mean   :2.415  
 3rd Qu.:171.0   3rd Qu.:24.30   3rd Qu.:2.000   3rd Qu.:3.000  
 Max.   :185.0   Max.   :47.86   Max.   :2.000   Max.   :4.000  
                                                                
     TFEQ2r          TFEQ3r          TFEQ4r          TFEQ5r     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
 Median :2.000   Median :2.000   Median :2.000   Median :2.000  
 Mean   :2.228   Mean   :2.372   Mean   :2.258   Mean   :2.378  
 3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:3.000  
 Max.   :4.000   Max.   :4.000   Max.   :4.000   Max.   :4.000  
                                                                
     TFEQ6r          TFEQ7r          TFEQ8r          TFEQ9r     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:2.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000  
 Median :2.000   Median :2.000   Median :2.000   Median :2.000  
 Mean   :2.215   Mean   :2.468   Mean   :2.089   Mean   :1.994  
 3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:3.000  
 Max.   :4.000   Max.   :4.000   Max.   :4.000   Max.   :4.000  
                                                                
    TFEQ10r         TFEQ11r         TFEQ12r         TFEQ13r     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:1.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000  
 Median :2.000   Median :2.000   Median :2.000   Median :2.000  
 Mean   :2.203   Mean   :2.274   Mean   :1.914   Mean   :2.031  
 3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:2.000   3rd Qu.:2.000  
 Max.   :4.000   Max.   :4.000   Max.   :4.000   Max.   :4.000  
                                                                
     TFEQ14          TFEQ15          TFEQ16          TFEQ17     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
 Median :2.000   Median :2.000   Median :3.000   Median :2.000  
 Mean   :2.258   Mean   :2.292   Mean   :2.637   Mean   :2.012  
 3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:2.000  
 Max.   :4.000   Max.   :4.000   Max.   :4.000   Max.   :4.000  
                                                                
    TFEQ18c          IPAQ0           IPAQ1           IPAQ2         IPAQ3      
 Min.   :1.000   Min.   :1.000   Min.   :0.000   Min.   :  0   Min.   :0.000  
 1st Qu.:2.000   1st Qu.:2.000   1st Qu.:0.000   1st Qu.:  0   1st Qu.:0.000  
 Median :2.000   Median :3.000   Median :1.000   Median : 15   Median :2.000  
 Mean   :2.135   Mean   :2.409   Mean   :1.563   Mean   : 35   Mean   :1.991  
 3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:2.000   3rd Qu.: 60   3rd Qu.:3.000  
 Max.   :4.000   Max.   :3.000   Max.   :7.000   Max.   :300   Max.   :7.000  
                                                                              
     IPAQ4            IPAQ5           IPAQ6             IPAQ7       
 Min.   :  0.00   Min.   :0.000   Min.   :   0.00   Min.   :  0.00  
 1st Qu.:  0.00   1st Qu.:4.000   1st Qu.:  20.00   1st Qu.:  6.00  
 Median : 24.00   Median :6.000   Median :  30.00   Median :  8.00  
 Mean   : 34.78   Mean   :5.348   Mean   :  61.74   Mean   : 19.85  
 3rd Qu.: 50.00   3rd Qu.:7.000   3rd Qu.:  60.00   3rd Qu.: 12.00  
 Max.   :300.00   Max.   :7.000   Max.   :2046.00   Max.   :360.00  
                                                                    
     IPAQ7c        IPAQtotalMET   IPAQexerciselevel   Attitude1a   
 Min.   : 0.000   Min.   :    0   Min.   :1.000     Min.   :2.000  
 1st Qu.: 5.000   1st Qu.:  560   1st Qu.:1.000     1st Qu.:4.000  
 Median : 8.000   Median : 1386   Median :2.000     Median :5.000  
 Mean   : 8.138   Mean   : 2008   Mean   :2.022     Mean   :5.117  
 3rd Qu.:10.000   3rd Qu.: 2613   3rd Qu.:3.000     3rd Qu.:6.000  
 Max.   :24.000   Max.   :17598   Max.   :3.000     Max.   :7.000  
                                                                   
   Attitude1b      Attitude1c    Attitude1d      Attitude1e      Attitude1f   
 Min.   :3.000   Min.   :1.0   Min.   :3.000   Min.   :2.000   Min.   :1.000  
 1st Qu.:6.000   1st Qu.:6.0   1st Qu.:5.000   1st Qu.:6.000   1st Qu.:4.000  
 Median :7.000   Median :7.0   Median :6.000   Median :7.000   Median :5.000  
 Mean   :6.354   Mean   :6.4   Mean   :6.083   Mean   :6.298   Mean   :4.818  
 3rd Qu.:7.000   3rd Qu.:7.0   3rd Qu.:7.000   3rd Qu.:7.000   3rd Qu.:6.000  
 Max.   :7.000   Max.   :7.0   Max.   :7.000   Max.   :7.000   Max.   :7.000  
                                                                              
   Attitude1g      Attitude1h      Attitude2a      Attitude2b   
 Min.   :1.000   Min.   :3.000   Min.   :2.000   Min.   :3.000  
 1st Qu.:4.000   1st Qu.:6.000   1st Qu.:5.000   1st Qu.:6.000  
 Median :5.000   Median :7.000   Median :6.000   Median :7.000  
 Mean   :4.935   Mean   :6.274   Mean   :5.471   Mean   :6.289  
 3rd Qu.:6.000   3rd Qu.:7.000   3rd Qu.:7.000   3rd Qu.:7.000  
 Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
                                                                
   Attitude2c      Attitude2d     Attitude2e      Attitude2f      Attitude2g   
 Min.   :3.000   Min.   :3.00   Min.   :4.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:6.000   1st Qu.:5.00   1st Qu.:6.000   1st Qu.:4.000   1st Qu.:5.000  
 Median :7.000   Median :6.00   Median :7.000   Median :5.000   Median :6.000  
 Mean   :6.363   Mean   :6.12   Mean   :6.292   Mean   :5.298   Mean   :5.557  
 3rd Qu.:7.000   3rd Qu.:7.00   3rd Qu.:7.000   3rd Qu.:7.000   3rd Qu.:7.000  
 Max.   :7.000   Max.   :7.00   Max.   :7.000   Max.   :7.000   Max.   :7.000  
                                                                               
   Attitude2h    Subjectivenorm1 Subjectivenorm2 Subjectivenorm3
 Min.   :3.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:6.000   1st Qu.:3.000   1st Qu.:4.000   1st Qu.:2.000  
 Median :7.000   Median :5.000   Median :5.000   Median :4.000  
 Mean   :6.302   Mean   :4.477   Mean   :4.603   Mean   :3.751  
 3rd Qu.:7.000   3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:5.000  
 Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
                                                                
 Subjectivenorm4 Subjectivenorm5 Subjectivenorm6      PBC1      
 Min.   :1.000   Min.   :1.0     Min.   :1.000   Min.   :1.000  
 1st Qu.:2.000   1st Qu.:2.0     1st Qu.:3.000   1st Qu.:4.000  
 Median :3.000   Median :4.0     Median :4.000   Median :5.000  
 Mean   :3.477   Mean   :3.8     Mean   :4.234   Mean   :4.868  
 3rd Qu.:5.000   3rd Qu.:5.0     3rd Qu.:6.000   3rd Qu.:6.000  
 Max.   :7.000   Max.   :7.0     Max.   :7.000   Max.   :7.000  
                                                                
      PBC2            PBC3            PBC4            PBC5      
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:5.000   1st Qu.:3.000   1st Qu.:4.000   1st Qu.:4.000  
 Median :6.000   Median :4.000   Median :5.000   Median :5.000  
 Mean   :5.825   Mean   :3.945   Mean   :4.686   Mean   :4.935  
 3rd Qu.:7.000   3rd Qu.:5.000   3rd Qu.:6.000   3rd Qu.:6.000  
 Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
                                                                
      PBC6            PBC7            PBC8            PBC9      
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000  
 Median :5.000   Median :5.000   Median :4.000   Median :4.000  
 Mean   :4.582   Mean   :4.655   Mean   :4.188   Mean   :4.385  
 3rd Qu.:6.000   3rd Qu.:6.000   3rd Qu.:5.000   3rd Qu.:6.000  
 Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :7.000  
                                                                
     PBC10       Behavioralintention1 Behavioralintention2 Behavioralintention3
 Min.   :1.000   Min.   :1.000        Min.   :1.000        Min.   :1.000       
 1st Qu.:3.000   1st Qu.:4.000        1st Qu.:4.000        1st Qu.:4.000       
 Median :5.000   Median :5.000        Median :5.000        Median :5.000       
 Mean   :4.606   Mean   :4.495        Mean   :4.714        Mean   :4.726       
 3rd Qu.:6.000   3rd Qu.:5.000        3rd Qu.:6.000        3rd Qu.:6.000       
 Max.   :7.000   Max.   :7.000        Max.   :7.000        Max.   :7.000       
                                                                               
 Behavioralintention4 Behavioralintention5 Behavioralintention6     WBIS1      
 Min.   :1.000        Min.   :1.000        Min.   :1.000        Min.   :1.000  
 1st Qu.:3.000        1st Qu.:4.000        1st Qu.:4.000        1st Qu.:3.000  
 Median :5.000        Median :5.000        Median :5.000        Median :4.000  
 Mean   :4.631        Mean   :4.757        Mean   :4.809        Mean   :3.443  
 3rd Qu.:6.000        3rd Qu.:6.000        3rd Qu.:6.000        3rd Qu.:4.000  
 Max.   :7.000        Max.   :7.000        Max.   :7.000        Max.   :5.000  
                                                                               
     WBIS2           WBIS3           WBIS4           WBIS5      
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
 Median :3.000   Median :3.000   Median :4.000   Median :3.000  
 Mean   :3.009   Mean   :3.163   Mean   :3.372   Mean   :2.858  
 3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
                                                                
     WBIS6           WBIS7           WBIS8           WBIS9      
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000  
 Median :3.000   Median :2.000   Median :2.000   Median :3.000  
 Mean   :2.982   Mean   :1.895   Mean   :1.997   Mean   :3.262  
 3rd Qu.:4.000   3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
                                                                
     WBIS10          WBIS11          WSSQ1           WSSQ2      
 Min.   :1.000   Min.   :1.000   Min.   :0.000   Min.   :0.000  
 1st Qu.:1.000   1st Qu.:1.000   1st Qu.:0.000   1st Qu.:1.000  
 Median :2.000   Median :2.000   Median :2.000   Median :3.000  
 Mean   :2.182   Mean   :2.169   Mean   :1.803   Mean   :2.557  
 3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
                                                                
     WSSQ3           WSSQ4           WSSQ5           WSSQ6      
 Min.   :0.000   Min.   :0.000   Min.   :0.000   Min.   :0.000  
 1st Qu.:1.000   1st Qu.:0.000   1st Qu.:1.000   1st Qu.:1.000  
 Median :2.000   Median :1.000   Median :2.000   Median :3.000  
 Mean   :2.212   Mean   :1.498   Mean   :2.068   Mean   :2.437  
 3rd Qu.:4.000   3rd Qu.:2.000   3rd Qu.:3.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
                                                                
     WSSQ7           WSSQ8           WSSQ9           WSSQ10     
 Min.   :0.000   Min.   :0.000   Min.   :0.000   Min.   :0.000  
 1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:0.000  
 Median :3.000   Median :1.000   Median :1.000   Median :2.000  
 Mean   :2.628   Mean   :1.658   Mean   :1.542   Mean   :1.914  
 3rd Qu.:4.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:3.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
                                                                
     WSSQ11          WSSQ12       Weight_group     WBIS1_r         WBIS9_r     
 Min.   :0.000   Min.   :0.000   Min.   :1.00   Min.   :1.000   Min.   :1.000  
 1st Qu.:0.000   1st Qu.:1.000   1st Qu.:1.00   1st Qu.:2.000   1st Qu.:2.000  
 Median :1.000   Median :1.000   Median :1.00   Median :2.000   Median :3.000  
 Mean   :1.529   Mean   :1.535   Mean   :1.32   Mean   :2.557   Mean   :2.738  
 3rd Qu.:2.000   3rd Qu.:3.000   3rd Qu.:2.00   3rd Qu.:3.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :2.00   Max.   :5.000   Max.   :5.000  
                                                                               
 WBIS_Total_Score WSSQ_Q1to6_Total WSSQ_Q7to12_Total WSSQ_Total_Score
 Min.   :11.00    Min.   : 0.00    Min.   : 0.00     Min.   : 0.00   
 1st Qu.:22.00    1st Qu.: 7.00    1st Qu.: 6.00     1st Qu.:12.00   
 Median :30.00    Median :14.00    Median :12.00     Median :25.00   
 Mean   :28.92    Mean   :12.58    Mean   :10.81     Mean   :23.38   
 3rd Qu.:36.00    3rd Qu.:18.00    3rd Qu.:16.00     3rd Qu.:33.00   
 Max.   :55.00    Max.   :28.00    Max.   :28.00     Max.   :53.00   
                                                                     
   TFEQ_Total    Attitude_Eat     Attitude_PA      SubNorm_Eat    
 Min.   :12.0   Min.   : 47.92   Min.   : 41.67   Min.   :  0.00  
 1st Qu.:22.0   1st Qu.: 70.83   1st Qu.: 72.92   1st Qu.: 38.89  
 Median :26.0   Median : 81.25   Median : 83.33   Median : 55.56  
 Mean   :26.7   Mean   : 79.75   Mean   : 82.69   Mean   : 54.62  
 3rd Qu.:31.0   3rd Qu.: 89.58   3rd Qu.: 95.83   3rd Qu.: 72.22  
 Max.   :45.0   Max.   :100.00   Max.   :100.00   Max.   :100.00  
                                                                  
   SubNorm_PA        PBC_Eat           PBC_PA          Int_Eat      
 Min.   :  0.00   Min.   :  0.00   Min.   :  0.00   Min.   :  0.00  
 1st Qu.: 27.78   1st Qu.: 58.33   1st Qu.: 37.50   1st Qu.: 50.00  
 Median : 50.00   Median : 66.67   Median : 58.33   Median : 66.67  
 Mean   : 47.28   Mean   : 67.97   Mean   : 59.28   Mean   : 60.75  
 3rd Qu.: 66.67   3rd Qu.: 79.17   3rd Qu.: 83.33   3rd Qu.: 77.78  
 Max.   :100.00   Max.   :100.00   Max.   :100.00   Max.   :100.00  
                                                                    
     Int_PA       IPAQtotalMET2   
 Min.   :  0.00   Min.   :  0.00  
 1st Qu.: 50.00   1st Qu.:  5.60  
 Median : 66.67   Median : 13.86  
 Mean   : 62.21   Mean   : 20.08  
 3rd Qu.: 83.33   3rd Qu.: 26.13  
 Max.   :100.00   Max.   :175.98  
                                  

先複習一下模型建立(CFA)

#factor1 =~ PBC1+PBC2+PBC3+PBC4+PBC5
#factor2 =~ PBC6+PBC7+PBC8+PBC9+PBC10
#做出第一個模型 PCB.model
PBC.model <-
' 
  factor1 =~ PBC1+PBC2+PBC3+PBC4+PBC5   
  factor2 =~ PBC6+PBC7+PBC8+PBC9+PBC10   
'  
fit<-cfa(PBC.model, data=dta)
summary(fit,fit.measures=T, standardized=T)
lavaan 0.6-9 ended normally after 38 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        21
                                                      
  Number of observations                           325
                                                      
Model Test User Model:
                                                      
  Test statistic                               165.095
  Degrees of freedom                                34
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              2216.449
  Degrees of freedom                                45
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.940
  Tucker-Lewis Index (TLI)                       0.920

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4940.755
  Loglikelihood unrestricted model (H1)      -4858.208
                                                      
  Akaike (AIC)                                9923.510
  Bayesian (BIC)                             10002.971
  Sample-size adjusted Bayesian (BIC)         9936.360

Root Mean Square Error of Approximation:

  RMSEA                                          0.109
  90 Percent confidence interval - lower         0.093
  90 Percent confidence interval - upper         0.126
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.068

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
  factor1 =~                                                            
    PBC1              1.000                               0.989    0.683
    PBC2              0.301    0.064    4.674    0.000    0.298    0.273
    PBC3             -0.423    0.091   -4.649    0.000   -0.418   -0.271
    PBC4              1.253    0.088   14.241    0.000    1.239    0.901
    PBC5              1.210    0.085   14.292    0.000    1.196    0.913
  factor2 =~                                                            
    PBC6              1.000                               1.592    0.913
    PBC7              0.916    0.037   24.907    0.000    1.458    0.880
    PBC8             -0.228    0.058   -3.942    0.000   -0.363   -0.219
    PBC9              1.037    0.034   30.232    0.000    1.650    0.944
    PBC10             1.015    0.037   27.562    0.000    1.616    0.914

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2           0.799    0.116    6.915    0.000    0.508    0.508

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              1.119    0.096   11.671    0.000    1.119    0.534
   .PBC2              1.102    0.087   12.652    0.000    1.102    0.926
   .PBC3              2.198    0.174   12.653    0.000    2.198    0.926
   .PBC4              0.354    0.058    6.084    0.000    0.354    0.188
   .PBC5              0.285    0.053    5.411    0.000    0.285    0.166
   .PBC6              0.503    0.052    9.676    0.000    0.503    0.166
   .PBC7              0.617    0.058   10.685    0.000    0.617    0.225
   .PBC8              2.605    0.205   12.718    0.000    2.605    0.952
   .PBC9              0.332    0.043    7.757    0.000    0.332    0.109
   .PBC10             0.513    0.053    9.642    0.000    0.513    0.164
    factor1           0.977    0.144    6.773    0.000    1.000    1.000
    factor2           2.534    0.237   10.675    0.000    1.000    1.000
#factor1 =~ PBC1+PBC2+PBC6+PBC7
#factor2 =~ PBC3+PBC4+PBC5+PBC8+PBC9+PBC10  
#做出第2個模型 PCB2.model
PBC2.model <-
' 
  factor1=~ PBC1+PBC2+PBC6+PBC7
  factor2=~ PBC3+PBC4+PBC5+PBC8+PBC9+PBC10   
'  
fit2<-cfa(PBC2.model, data=dta)
summary(fit2,fit.measures=T, standardized=T)
lavaan 0.6-9 ended normally after 340 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        21
                                                      
  Number of observations                           325
                                                      
Model Test User Model:
                                                      
  Test statistic                               622.136
  Degrees of freedom                                34
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              2216.449
  Degrees of freedom                                45
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.729
  Tucker-Lewis Index (TLI)                       0.642

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -5169.276
  Loglikelihood unrestricted model (H1)      -4858.208
                                                      
  Akaike (AIC)                               10380.552
  Bayesian (BIC)                             10460.012
  Sample-size adjusted Bayesian (BIC)        10393.402

Root Mean Square Error of Approximation:

  RMSEA                                          0.231
  90 Percent confidence interval - lower         0.215
  90 Percent confidence interval - upper         0.247
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.143

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
  factor1 =~                                                            
    PBC1              1.000                               0.488    0.337
    PBC2              0.565    0.152    3.714    0.000    0.276    0.253
    PBC6              3.263    0.525    6.215    0.000    1.593    0.914
    PBC7              3.015    0.487    6.190    0.000    1.473    0.889
  factor2 =~                                                            
    PBC3              1.000                               0.026    0.017
    PBC4            -25.413   83.909   -0.303    0.762   -0.673   -0.490
    PBC5            -24.853   82.058   -0.303    0.762   -0.658   -0.502
    PBC8             13.320   44.096    0.302    0.763    0.353    0.213
    PBC9            -62.526  206.354   -0.303    0.762   -1.655   -0.947
    PBC10           -60.855  200.843   -0.303    0.762   -1.611   -0.911

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2          -0.013    0.042   -0.303    0.762   -0.988   -0.988

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              1.858    0.147   12.663    0.000    1.858    0.886
   .PBC2              1.115    0.088   12.703    0.000    1.115    0.936
   .PBC6              0.498    0.058    8.595    0.000    0.498    0.164
   .PBC7              0.574    0.058    9.870    0.000    0.574    0.209
   .PBC3              2.372    0.186   12.747    0.000    2.372    1.000
   .PBC4              1.436    0.114   12.561    0.000    1.436    0.760
   .PBC5              1.283    0.102   12.547    0.000    1.283    0.748
   .PBC8              2.613    0.205   12.719    0.000    2.613    0.955
   .PBC9              0.314    0.045    7.049    0.000    0.314    0.103
   .PBC10             0.529    0.055    9.614    0.000    0.529    0.169
    factor1           0.239    0.078    3.057    0.002    1.000    1.000
    factor2           0.001    0.005    0.151    0.880    1.000    1.000
fitmeasures(fit)
               npar                fmin               chisq                  df 
             21.000               0.254             165.095              34.000 
             pvalue      baseline.chisq         baseline.df     baseline.pvalue 
              0.000            2216.449              45.000               0.000 
                cfi                 tli                nnfi                 rfi 
              0.940               0.920               0.920               0.901 
                nfi                pnfi                 ifi                 rni 
              0.926               0.699               0.940               0.940 
               logl   unrestricted.logl                 aic                 bic 
          -4940.755           -4858.208            9923.510           10002.971 
             ntotal                bic2               rmsea      rmsea.ci.lower 
            325.000            9936.360               0.109               0.093 
     rmsea.ci.upper        rmsea.pvalue                 rmr          rmr_nomean 
              0.126               0.000               0.164               0.164 
               srmr        srmr_bentler srmr_bentler_nomean                crmr 
              0.068               0.068               0.068               0.075 
        crmr_nomean          srmr_mplus   srmr_mplus_nomean               cn_05 
              0.075               0.068               0.068              96.677 
              cn_01                 gfi                agfi                pgfi 
            111.360               0.913               0.860               0.565 
                mfi                ecvi 
              0.817               0.637 
fitmeasures(fit2)
               npar                fmin               chisq                  df 
             21.000               0.957             622.136              34.000 
             pvalue      baseline.chisq         baseline.df     baseline.pvalue 
              0.000            2216.449              45.000               0.000 
                cfi                 tli                nnfi                 rfi 
              0.729               0.642               0.642               0.628 
                nfi                pnfi                 ifi                 rni 
              0.719               0.543               0.731               0.729 
               logl   unrestricted.logl                 aic                 bic 
          -5169.276           -4858.208           10380.552           10460.012 
             ntotal                bic2               rmsea      rmsea.ci.lower 
            325.000           10393.402               0.231               0.215 
     rmsea.ci.upper        rmsea.pvalue                 rmr          rmr_nomean 
              0.247               0.000               0.286               0.286 
               srmr        srmr_bentler srmr_bentler_nomean                crmr 
              0.143               0.143               0.143               0.158 
        crmr_nomean          srmr_mplus   srmr_mplus_nomean               cn_05 
              0.158               0.143               0.143              26.390 
              cn_01                 gfi                agfi                pgfi 
             30.286               0.722               0.551               0.447 
                mfi                ecvi 
              0.405               2.043 
#AIC越小越好、BIC越小越好

巢套模型=等價模型()

使用卡方差異檢定,看△CFI △TLI △RSMEA △SRMR full invariance: partial invariance:抓出不恆等的題目,在兩個族群當中某些面向的題目不恆等,建議使用在兩個不同族群時

full invariance作法 做3個模型 1.Model-0:configual model自由估計 2.Model-1:factor loading+configual model 3.Model-2:factor loading+item intercept+configual model

比較Modle-0和Model-1→如果兩個沒差異,表示可以接受model-1 筆Model-1和Model-2→如果沒差異,表示可以接受model-2

#factor1 =~ PBC1+PBC2+PBC3+PBC4+PBC5
#factor2 =~ PBC6+PBC7+PBC8+PBC9+PBC10
#以group做分組,做出第一個模型 PCB.model
PBC.model <-
' 
  factor1 =~ PBC1+PBC2+PBC3+PBC4+PBC5   
  factor2 =~ PBC6+PBC7+PBC8+PBC9+PBC10   
'  
fit3<-cfa(PBC.model, 
         data=dta, 
         group="Gender")
summary(fit3,fit.measures=T, standardized=T)
lavaan 0.6-9 ended normally after 54 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        62
                                                      
  Number of observations per group:                   
    2                                              199
    1                                              126
                                                      
Model Test User Model:
                                                      
  Test statistic                               194.743
  Degrees of freedom                                68
  P-value (Chi-square)                           0.000
  Test statistic for each group:
    2                                          104.254
    1                                           90.489

Model Test Baseline Model:

  Test statistic                              2133.931
  Degrees of freedom                                90
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.938
  Tucker-Lewis Index (TLI)                       0.918

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4896.279
  Loglikelihood unrestricted model (H1)      -4798.908
                                                      
  Akaike (AIC)                                9916.559
  Bayesian (BIC)                             10151.156
  Sample-size adjusted Bayesian (BIC)         9954.497

Root Mean Square Error of Approximation:

  RMSEA                                          0.107
  90 Percent confidence interval - lower         0.090
  90 Percent confidence interval - upper         0.125
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.063

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured


Group 1 [2]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 =~                                                            
    PBC1              1.000                               0.942    0.651
    PBC2              0.316    0.091    3.467    0.001    0.297    0.262
    PBC3             -0.471    0.118   -4.004    0.000   -0.444   -0.304
    PBC4              1.254    0.123   10.207    0.000    1.181    0.892
    PBC5              1.211    0.118   10.231    0.000    1.140    0.906
  factor2 =~                                                            
    PBC6              1.000                               1.568    0.913
    PBC7              0.895    0.050   17.802    0.000    1.404    0.851
    PBC8             -0.281    0.067   -4.197    0.000   -0.441   -0.295
    PBC9              1.009    0.045   22.471    0.000    1.582    0.933
    PBC10             0.994    0.048   20.767    0.000    1.559    0.906

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2           0.665    0.136    4.887    0.000    0.450    0.450

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              4.734    0.103   46.136    0.000    4.734    3.271
   .PBC2              5.714    0.081   70.969    0.000    5.714    5.031
   .PBC3              3.869    0.104   37.368    0.000    3.869    2.649
   .PBC4              4.422    0.094   47.136    0.000    4.422    3.341
   .PBC5              4.688    0.089   52.595    0.000    4.688    3.728
   .PBC6              4.166    0.122   34.201    0.000    4.166    2.424
   .PBC7              4.271    0.117   36.533    0.000    4.271    2.590
   .PBC8              4.176    0.106   39.312    0.000    4.176    2.787
   .PBC9              3.899    0.120   32.446    0.000    3.899    2.300
   .PBC10             4.176    0.122   34.245    0.000    4.176    2.428
    factor1           0.000                               0.000    0.000
    factor2           0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              1.208    0.131    9.191    0.000    1.208    0.577
   .PBC2              1.201    0.121    9.899    0.000    1.201    0.931
   .PBC3              1.937    0.196    9.870    0.000    1.937    0.908
   .PBC4              0.357    0.076    4.665    0.000    0.357    0.204
   .PBC5              0.282    0.069    4.094    0.000    0.282    0.178
   .PBC6              0.493    0.068    7.235    0.000    0.493    0.167
   .PBC7              0.748    0.087    8.569    0.000    0.748    0.275
   .PBC8              2.051    0.207    9.926    0.000    2.051    0.913
   .PBC9              0.370    0.059    6.273    0.000    0.370    0.129
   .PBC10             0.530    0.071    7.467    0.000    0.530    0.179
    factor1           0.887    0.179    4.953    0.000    1.000    1.000
    factor2           2.460    0.296    8.321    0.000    1.000    1.000


Group 2 [1]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 =~                                                            
    PBC1              1.000                               1.042    0.732
    PBC2              0.218    0.089    2.464    0.014    0.227    0.229
    PBC3             -0.469    0.147   -3.186    0.001   -0.488   -0.296
    PBC4              1.165    0.119    9.826    0.000    1.214    0.899
    PBC5              1.130    0.115    9.869    0.000    1.177    0.908
  factor2 =~                                                            
    PBC6              1.000                               1.405    0.895
    PBC7              0.944    0.061   15.461    0.000    1.326    0.899
    PBC8             -0.222    0.120   -1.845    0.065   -0.312   -0.167
    PBC9              1.028    0.060   17.093    0.000    1.445    0.936
    PBC10             1.050    0.066   15.897    0.000    1.475    0.909

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2           0.698    0.166    4.194    0.000    0.477    0.477

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              5.079    0.127   40.062    0.000    5.079    3.569
   .PBC2              6.000    0.088   67.891    0.000    6.000    6.048
   .PBC3              4.063    0.147   27.626    0.000    4.063    2.461
   .PBC4              5.103    0.120   42.430    0.000    5.103    3.780
   .PBC5              5.325    0.115   46.121    0.000    5.325    4.109
   .PBC6              5.238    0.140   37.434    0.000    5.238    3.335
   .PBC7              5.262    0.131   40.027    0.000    5.262    3.566
   .PBC8              4.206    0.167   25.191    0.000    4.206    2.244
   .PBC9              5.151    0.137   37.462    0.000    5.151    3.337
   .PBC10             5.286    0.145   36.567    0.000    5.286    3.258
    factor1           0.000                               0.000    0.000
    factor2           0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              0.940    0.134    7.027    0.000    0.940    0.464
   .PBC2              0.932    0.118    7.895    0.000    0.932    0.947
   .PBC3              2.488    0.316    7.865    0.000    2.488    0.913
   .PBC4              0.349    0.088    3.985    0.000    0.349    0.191
   .PBC5              0.293    0.080    3.660    0.000    0.293    0.175
   .PBC6              0.492    0.078    6.303    0.000    0.492    0.200
   .PBC7              0.418    0.067    6.220    0.000    0.418    0.192
   .PBC8              3.415    0.431    7.926    0.000    3.415    0.972
   .PBC9              0.294    0.059    5.028    0.000    0.294    0.124
   .PBC10             0.457    0.076    5.980    0.000    0.457    0.173
    factor1           1.085    0.234    4.630    0.000    1.000    1.000
    factor2           1.975    0.308    6.407    0.000    1.000    1.000

結論: 會分兩組,各自估計,做出兩個卡方值,自由度也是兩組都加起來df=68

fit4<-cfa(PBC.model, 
         data=dta, 
         group="Gender",
         group.equal=c("loadings"))
summary(fit4,fit.measures=T)
lavaan 0.6-9 ended normally after 48 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        62
  Number of equality constraints                     8
                                                      
  Number of observations per group:                   
    2                                              199
    1                                              126
                                                      
Model Test User Model:
                                                      
  Test statistic                               196.398
  Degrees of freedom                                76
  P-value (Chi-square)                           0.000
  Test statistic for each group:
    2                                          104.919
    1                                           91.479

Model Test Baseline Model:

  Test statistic                              2133.931
  Degrees of freedom                                90
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.941
  Tucker-Lewis Index (TLI)                       0.930

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4897.107
  Loglikelihood unrestricted model (H1)      -4798.908
                                                      
  Akaike (AIC)                                9902.214
  Bayesian (BIC)                             10106.540
  Sample-size adjusted Bayesian (BIC)         9935.257

Root Mean Square Error of Approximation:

  RMSEA                                          0.099
  90 Percent confidence interval - lower         0.082
  90 Percent confidence interval - upper         0.116
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.064

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured


Group 1 [2]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  factor1 =~                                          
    PBC1              1.000                           
    PBC2    (.p2.)    0.269    0.064    4.226    0.000
    PBC3    (.p3.)   -0.468    0.091   -5.136    0.000
    PBC4    (.p4.)    1.211    0.086   14.163    0.000
    PBC5    (.p5.)    1.174    0.083   14.217    0.000
  factor2 =~                                          
    PBC6              1.000                           
    PBC7    (.p7.)    0.915    0.038   23.774    0.000
    PBC8    (.p8.)   -0.268    0.059   -4.560    0.000
    PBC9    (.p9.)    1.015    0.036   28.269    0.000
    PBC10   (.10.)    1.014    0.039   26.164    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  factor1 ~~                                          
    factor2           0.679    0.132    5.126    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .PBC1              4.734    0.104   45.589    0.000
   .PBC2              5.714    0.080   71.447    0.000
   .PBC3              3.869    0.104   37.303    0.000
   .PBC4              4.422    0.094   47.251    0.000
   .PBC5              4.688    0.089   52.632    0.000
   .PBC6              4.166    0.121   34.461    0.000
   .PBC7              4.271    0.118   36.233    0.000
   .PBC8              4.176    0.106   39.485    0.000
   .PBC9              3.899    0.120   32.551    0.000
   .PBC10             4.176    0.123   33.980    0.000
    factor1           0.000                           
    factor2           0.000                           

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .PBC1              1.203    0.131    9.175    0.000
   .PBC2              1.205    0.121    9.919    0.000
   .PBC3              1.935    0.196    9.868    0.000
   .PBC4              0.361    0.070    5.135    0.000
   .PBC5              0.280    0.063    4.440    0.000
   .PBC6              0.497    0.067    7.371    0.000
   .PBC7              0.746    0.087    8.566    0.000
   .PBC8              2.053    0.207    9.932    0.000
   .PBC9              0.370    0.058    6.384    0.000
   .PBC10             0.527    0.071    7.460    0.000
    factor1           0.942    0.154    6.115    0.000
    factor2           2.411    0.278    8.674    0.000


Group 2 [1]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  factor1 =~                                          
    PBC1              1.000                           
    PBC2    (.p2.)    0.269    0.064    4.226    0.000
    PBC3    (.p3.)   -0.468    0.091   -5.136    0.000
    PBC4    (.p4.)    1.211    0.086   14.163    0.000
    PBC5    (.p5.)    1.174    0.083   14.217    0.000
  factor2 =~                                          
    PBC6              1.000                           
    PBC7    (.p7.)    0.915    0.038   23.774    0.000
    PBC8    (.p8.)   -0.268    0.059   -4.560    0.000
    PBC9    (.p9.)    1.015    0.036   28.269    0.000
    PBC10   (.10.)    1.014    0.039   26.164    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  factor1 ~~                                          
    factor2           0.688    0.157    4.384    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .PBC1              5.079    0.125   40.702    0.000
   .PBC2              6.000    0.089   67.178    0.000
   .PBC3              4.063    0.147   27.703    0.000
   .PBC4              5.103    0.121   42.278    0.000
   .PBC5              5.325    0.116   46.072    0.000
   .PBC6              5.238    0.142   36.924    0.000
   .PBC7              5.262    0.130   40.402    0.000
   .PBC8              4.206    0.168   25.008    0.000
   .PBC9              5.151    0.138   37.283    0.000
   .PBC10             5.286    0.143   37.023    0.000
    factor1           0.000                           
    factor2           0.000                           

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .PBC1              0.950    0.133    7.147    0.000
   .PBC2              0.932    0.118    7.881    0.000
   .PBC3              2.489    0.316    7.874    0.000
   .PBC4              0.352    0.082    4.277    0.000
   .PBC5              0.288    0.074    3.874    0.000
   .PBC6              0.487    0.078    6.273    0.000
   .PBC7              0.421    0.067    6.322    0.000
   .PBC8              3.418    0.431    7.921    0.000
   .PBC9              0.293    0.058    5.071    0.000
   .PBC10             0.463    0.075    6.130    0.000
    factor1           1.012    0.184    5.510    0.000
    factor2           2.049    0.289    7.085    0.000
anova(fit3, fit4)
Chi-Squared Difference Test

     Df    AIC   BIC  Chisq Chisq diff Df diff Pr(>Chisq)
fit3 68 9916.6 10151 194.74                              
fit4 76 9902.2 10106 196.40     1.6549       8     0.9898

自由估計的時候,factor1裡面有5個變項,其中一個是Anchor,自由度是4,所以

fit5<-cfa(PBC.model, 
         data=dta, 
         group="Gender",
         group.equal=c("loadings", "intercepts"))
summary(fit5,fit.measures=T, standardized=T)
lavaan 0.6-9 ended normally after 78 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        64
  Number of equality constraints                    18
                                                      
  Number of observations per group:                   
    2                                              199
    1                                              126
                                                      
Model Test User Model:
                                                      
  Test statistic                               212.283
  Degrees of freedom                                84
  P-value (Chi-square)                           0.000
  Test statistic for each group:
    2                                          110.639
    1                                          101.644

Model Test Baseline Model:

  Test statistic                              2133.931
  Degrees of freedom                                90
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.937
  Tucker-Lewis Index (TLI)                       0.933

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4905.050
  Loglikelihood unrestricted model (H1)      -4798.908
                                                      
  Akaike (AIC)                                9902.099
  Bayesian (BIC)                             10076.155
  Sample-size adjusted Bayesian (BIC)         9930.247

Root Mean Square Error of Approximation:

  RMSEA                                          0.097
  90 Percent confidence interval - lower         0.081
  90 Percent confidence interval - upper         0.113
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.066

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured


Group 1 [2]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 =~                                                            
    PBC1              1.000                               0.945    0.651
    PBC2    (.p2.)    0.297    0.064    4.667    0.000    0.280    0.247
    PBC3    (.p3.)   -0.422    0.090   -4.671    0.000   -0.399   -0.274
    PBC4    (.p4.)    1.251    0.087   14.370    0.000    1.182    0.893
    PBC5    (.p5.)    1.208    0.084   14.423    0.000    1.142    0.907
  factor2 =~                                                            
    PBC6              1.000                               1.541    0.908
    PBC7    (.p7.)    0.917    0.036   25.287    0.000    1.413    0.853
    PBC8    (.p8.)   -0.239    0.056   -4.245    0.000   -0.368   -0.248
    PBC9    (.p9.)    1.035    0.034   30.296    0.000    1.595    0.935
    PBC10   (.10.)    1.017    0.037   27.766    0.000    1.567    0.907

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2           0.659    0.128    5.151    0.000    0.453    0.453

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1    (.24.)    4.659    0.091   51.097    0.000    4.659    3.209
   .PBC2    (.25.)    5.774    0.063   91.819    0.000    5.774    5.094
   .PBC3    (.26.)    4.003    0.088   45.674    0.000    4.003    2.749
   .PBC4    (.27.)    4.437    0.092   48.279    0.000    4.437    3.351
   .PBC5    (.28.)    4.694    0.088   53.447    0.000    4.694    3.728
   .PBC6    (.29.)    4.145    0.117   35.288    0.000    4.145    2.442
   .PBC7    (.30.)    4.249    0.111   38.225    0.000    4.249    2.567
   .PBC8    (.31.)    4.258    0.092   46.133    0.000    4.258    2.870
   .PBC9    (.32.)    3.937    0.119   33.062    0.000    3.937    2.308
   .PBC10   (.33.)    4.161    0.119   34.844    0.000    4.161    2.408
    factor1           0.000                               0.000    0.000
    factor2           0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              1.215    0.132    9.231    0.000    1.215    0.576
   .PBC2              1.206    0.122    9.911    0.000    1.206    0.939
   .PBC3              1.961    0.198    9.894    0.000    1.961    0.925
   .PBC4              0.355    0.070    5.045    0.000    0.355    0.203
   .PBC5              0.282    0.063    4.465    0.000    0.282    0.178
   .PBC6              0.506    0.068    7.463    0.000    0.506    0.176
   .PBC7              0.746    0.087    8.585    0.000    0.746    0.272
   .PBC8              2.066    0.208    9.942    0.000    2.066    0.939
   .PBC9              0.364    0.058    6.248    0.000    0.364    0.125
   .PBC10             0.531    0.071    7.508    0.000    0.531    0.178
    factor1           0.893    0.146    6.125    0.000    1.000    1.000
    factor2           2.374    0.272    8.741    0.000    1.000    1.000


Group 2 [1]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 =~                                                            
    PBC1              1.000                               0.979    0.705
    PBC2    (.p2.)    0.297    0.064    4.667    0.000    0.290    0.287
    PBC3    (.p3.)   -0.422    0.090   -4.671    0.000   -0.413   -0.249
    PBC4    (.p4.)    1.251    0.087   14.370    0.000    1.225    0.900
    PBC5    (.p5.)    1.208    0.084   14.423    0.000    1.182    0.911
  factor2 =~                                                            
    PBC6              1.000                               1.420    0.897
    PBC7    (.p7.)    0.917    0.036   25.287    0.000    1.302    0.894
    PBC8    (.p8.)   -0.239    0.056   -4.245    0.000   -0.339   -0.179
    PBC9    (.p9.)    1.035    0.034   30.296    0.000    1.470    0.938
    PBC10   (.10.)    1.017    0.037   27.766    0.000    1.444    0.904

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2           0.666    0.151    4.393    0.000    0.479    0.479

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1    (.24.)    4.659    0.091   51.097    0.000    4.659    3.356
   .PBC2    (.25.)    5.774    0.063   91.819    0.000    5.774    5.709
   .PBC3    (.26.)    4.003    0.088   45.674    0.000    4.003    2.415
   .PBC4    (.27.)    4.437    0.092   48.279    0.000    4.437    3.262
   .PBC5    (.28.)    4.694    0.088   53.447    0.000    4.694    3.616
   .PBC6    (.29.)    4.145    0.117   35.288    0.000    4.145    2.618
   .PBC7    (.30.)    4.249    0.111   38.225    0.000    4.249    2.919
   .PBC8    (.31.)    4.258    0.092   46.133    0.000    4.258    2.251
   .PBC9    (.32.)    3.937    0.119   33.062    0.000    3.937    2.513
   .PBC10   (.33.)    4.161    0.119   34.844    0.000    4.161    2.606
    factor1           0.515    0.119    4.313    0.000    0.526    0.526
    factor2           1.126    0.173    6.499    0.000    0.793    0.793

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              0.970    0.135    7.208    0.000    0.970    0.503
   .PBC2              0.939    0.119    7.873    0.000    0.939    0.918
   .PBC3              2.577    0.327    7.890    0.000    2.577    0.938
   .PBC4              0.351    0.083    4.225    0.000    0.351    0.190
   .PBC5              0.287    0.075    3.845    0.000    0.287    0.170
   .PBC6              0.491    0.078    6.311    0.000    0.491    0.196
   .PBC7              0.424    0.067    6.350    0.000    0.424    0.200
   .PBC8              3.463    0.437    7.925    0.000    3.463    0.968
   .PBC9              0.293    0.059    4.999    0.000    0.293    0.119
   .PBC10             0.464    0.076    6.151    0.000    0.464    0.182
    factor1           0.958    0.174    5.511    0.000    1.000    1.000
    factor2           2.016    0.283    7.129    0.000    1.000    1.000
anova(fit4,fit5)
Chi-Squared Difference Test

     Df    AIC   BIC  Chisq Chisq diff Df diff Pr(>Chisq)  
fit4 76 9902.2 10106 196.40                                
fit5 84 9902.1 10076 212.28     15.885       8    0.04405 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

後減前(△CFI>-.0.01、△TLI>-0.01、△△RMSEA<0.01SRMR<0.01) 必須全部都符合,

fit6<-cfa(PBC.model, 
         data=dta, 
         group="Gender",
         group.equal=c("loadings", "intercepts"),
         group.partial=c("factor2=~PBC7", "PBC2~1"))
#定義某些變項的item intercept自由估計,或者某些變項的factor loading自由估計
#factor2的PBC7 factor loading自由估計
#PBC的intercept自由估計
summary(fit6,fit.measures=T, standardized=T)
lavaan 0.6-9 ended normally after 77 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        64
  Number of equality constraints                    16
                                                      
  Number of observations per group:                   
    2                                              199
    1                                              126
                                                      
Model Test User Model:
                                                      
  Test statistic                               210.807
  Degrees of freedom                                82
  P-value (Chi-square)                           0.000
  Test statistic for each group:
    2                                          110.213
    1                                          100.594

Model Test Baseline Model:

  Test statistic                              2133.931
  Degrees of freedom                                90
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.937
  Tucker-Lewis Index (TLI)                       0.931

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4904.312
  Loglikelihood unrestricted model (H1)      -4798.908
                                                      
  Akaike (AIC)                                9904.623
  Bayesian (BIC)                             10086.247
  Sample-size adjusted Bayesian (BIC)         9933.995

Root Mean Square Error of Approximation:

  RMSEA                                          0.098
  90 Percent confidence interval - lower         0.082
  90 Percent confidence interval - upper         0.115
  P-value RMSEA <= 0.05                          0.000

Standardized Root Mean Square Residual:

  SRMR                                           0.066

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured


Group 1 [2]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 =~                                                            
    PBC1              1.000                               0.945    0.651
    PBC2    (.p2.)    0.276    0.065    4.227    0.000    0.261    0.231
    PBC3    (.p3.)   -0.423    0.090   -4.678    0.000   -0.400   -0.275
    PBC4    (.p4.)    1.251    0.087   14.372    0.000    1.183    0.893
    PBC5    (.p5.)    1.208    0.084   14.424    0.000    1.142    0.907
  factor2 =~                                                            
    PBC6              1.000                               1.542    0.908
    PBC7              0.911    0.049   18.774    0.000    1.405    0.852
    PBC8    (.p8.)   -0.239    0.056   -4.247    0.000   -0.368   -0.248
    PBC9    (.p9.)    1.035    0.034   30.289    0.000    1.597    0.935
    PBC10   (.10.)    1.017    0.037   27.774    0.000    1.568    0.907

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2           0.659    0.128    5.147    0.000    0.452    0.452

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1    (.24.)    4.661    0.091   51.107    0.000    4.661    3.209
   .PBC2              5.714    0.080   71.449    0.000    5.714    5.065
   .PBC3    (.26.)    4.003    0.088   45.673    0.000    4.003    2.749
   .PBC4    (.27.)    4.439    0.092   48.277    0.000    4.439    3.351
   .PBC5    (.28.)    4.696    0.088   53.453    0.000    4.696    3.729
   .PBC6    (.29.)    4.146    0.117   35.286    0.000    4.146    2.441
   .PBC7    (.30.)    4.248    0.112   37.962    0.000    4.248    2.575
   .PBC8    (.31.)    4.258    0.092   46.132    0.000    4.258    2.869
   .PBC9    (.32.)    3.939    0.119   33.062    0.000    3.939    2.307
   .PBC10   (.33.)    4.162    0.119   34.844    0.000    4.162    2.407
    factor1           0.000                               0.000    0.000
    factor2           0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              1.215    0.132    9.231    0.000    1.215    0.576
   .PBC2              1.205    0.121    9.919    0.000    1.205    0.947
   .PBC3              1.960    0.198    9.894    0.000    1.960    0.925
   .PBC4              0.356    0.071    5.039    0.000    0.356    0.203
   .PBC5              0.281    0.063    4.446    0.000    0.281    0.177
   .PBC6              0.505    0.068    7.453    0.000    0.505    0.175
   .PBC7              0.747    0.087    8.564    0.000    0.747    0.275
   .PBC8              2.066    0.208    9.942    0.000    2.066    0.939
   .PBC9              0.364    0.058    6.235    0.000    0.364    0.125
   .PBC10             0.530    0.071    7.496    0.000    0.530    0.177
    factor1           0.894    0.146    6.126    0.000    1.000    1.000
    factor2           2.379    0.273    8.712    0.000    1.000    1.000


Group 2 [1]:

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 =~                                                            
    PBC1              1.000                               0.980    0.705
    PBC2    (.p2.)    0.276    0.065    4.227    0.000    0.270    0.270
    PBC3    (.p3.)   -0.423    0.090   -4.678    0.000   -0.414   -0.250
    PBC4    (.p4.)    1.251    0.087   14.372    0.000    1.225    0.901
    PBC5    (.p5.)    1.208    0.084   14.424    0.000    1.183    0.911
  factor2 =~                                                            
    PBC6              1.000                               1.418    0.897
    PBC7              0.922    0.046   20.006    0.000    1.308    0.895
    PBC8    (.p8.)   -0.239    0.056   -4.247    0.000   -0.338   -0.179
    PBC9    (.p9.)    1.035    0.034   30.289    0.000    1.468    0.938
    PBC10   (.10.)    1.017    0.037   27.774    0.000    1.442    0.904

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  factor1 ~~                                                            
    factor2           0.665    0.152    4.391    0.000    0.479    0.479

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1    (.24.)    4.661    0.091   51.107    0.000    4.661    3.356
   .PBC2              5.859    0.094   62.185    0.000    5.859    5.844
   .PBC3    (.26.)    4.003    0.088   45.673    0.000    4.003    2.414
   .PBC4    (.27.)    4.439    0.092   48.277    0.000    4.439    3.262
   .PBC5    (.28.)    4.696    0.088   53.453    0.000    4.696    3.615
   .PBC6    (.29.)    4.146    0.117   35.286    0.000    4.146    2.621
   .PBC7    (.30.)    4.248    0.112   37.962    0.000    4.248    2.909
   .PBC8    (.31.)    4.258    0.092   46.132    0.000    4.258    2.251
   .PBC9    (.32.)    3.939    0.119   33.062    0.000    3.939    2.517
   .PBC10   (.33.)    4.162    0.119   34.844    0.000    4.162    2.609
    factor1           0.511    0.119    4.280    0.000    0.522    0.522
    factor2           1.124    0.173    6.489    0.000    0.793    0.793

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PBC1              0.969    0.134    7.207    0.000    0.969    0.502
   .PBC2              0.932    0.118    7.881    0.000    0.932    0.927
   .PBC3              2.577    0.327    7.890    0.000    2.577    0.938
   .PBC4              0.350    0.083    4.208    0.000    0.350    0.189
   .PBC5              0.288    0.075    3.845    0.000    0.288    0.170
   .PBC6              0.491    0.078    6.312    0.000    0.491    0.196
   .PBC7              0.423    0.067    6.299    0.000    0.423    0.198
   .PBC8              3.463    0.437    7.925    0.000    3.463    0.968
   .PBC9              0.293    0.059    5.006    0.000    0.293    0.120
   .PBC10             0.465    0.076    6.156    0.000    0.465    0.183
    factor1           0.960    0.174    5.512    0.000    1.000    1.000
    factor2           2.012    0.283    7.098    0.000    1.000    1.000

通常會Conbarch alpha→EFA→CFA的路線,老師比較不常用Racsh

Racsh

原始初衷是想要知道問卷的答案適不適合拿來加總運算? 現在而是來驗證題目是不是好的 把量詞用機率的概念做轉換,是Item response theory,IRT的P1,是連續的量詞是等距的 > Item response theory P1,P2,P3 (一參模型:難度,二參模型:難度+鑑別度,三參模型:難度+鑑別度+猜測度) > Partial credit model:問卷有10個題目,每個都用五點量表,但假設每一點的差距在每一題都不同,估每一題答1~5的機率都不同 > Rating scale model:限制五點量表每一題的差距都一致的 適配度PCM>RSM,Racsh<ITM P2)

Racsh infit/outfit:看有沒有outlier

MnSq:看題目跟概念是否一致0.5~1.5可留,值越小表示越多餘可刪除,超過1表示離概念越遠

person separation reliability/person separation index:考慮樣本的能力,以樣本分出來的一致性 item separation reliability/person separation index:考慮題目難易度 (跟Conbarch alpha概念類似) 通常person算出來都會比item差 index像是分布,index越大越好,可以測到的範圍更廣 reliability>0.7才可接受 separation>2才可接受

Differential item functioning,DIF:男生算出item 1的難度-女生算出item稱之DIF contrast 1的難度,期望兩個族群差異小,表示兩個族群想到的概念是一致的,通常希望<0.5

disordered category:針對likert scale做order的檢查(有人也沒做這個檢查) local dependence:題目沒有估計到的之間沒有關聯性

library(eRm)
#WBIS1-11(75~85),刪掉WBIS2, WBIS9當成全部都是同一個factor
a<-dta[75]
b<-dta[,77:82]
c<-dta[,84:85]
wbis<-cbind(a,b,c)
head(wbis)
  WBIS1 WBIS3 WBIS4 WBIS5 WBIS6 WBIS7 WBIS8 WBIS10 WBIS11
1     2     5     4     3     4     2     4      4      4
2     3     4     5     3     4     2     2      2      1
3     4     4     5     3     5     5     5      5      5
4     4     4     4     3     3     2     2      2      2
5     4     4     4     3     4     3     1      1      1
6     2     4     4     3     3     1     1      3      3
summary(wbis)
     WBIS1           WBIS3           WBIS4           WBIS5      
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:3.000   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
 Median :4.000   Median :3.000   Median :4.000   Median :3.000  
 Mean   :3.443   Mean   :3.163   Mean   :3.372   Mean   :2.858  
 3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
     WBIS6           WBIS7           WBIS8           WBIS10     
 Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
 1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
 Median :3.000   Median :2.000   Median :2.000   Median :2.000  
 Mean   :2.982   Mean   :1.895   Mean   :1.997   Mean   :2.182  
 3rd Qu.:4.000   3rd Qu.:3.000   3rd Qu.:3.000   3rd Qu.:3.000  
 Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
     WBIS11     
 Min.   :1.000  
 1st Qu.:1.000  
 Median :2.000  
 Mean   :2.169  
 3rd Qu.:3.000  
 Max.   :5.000  
pcm.wbis<-PCM(wbis)
pres.pcm.wbis<-person.parameter(pcm.wbis)
itemfit(pres.pcm.wbis)

Itemfit Statistics: 
          Chisq  df p-value Outfit MSQ Infit MSQ Outfit t Infit t Discrim
WBIS1  1127.804 320   0.000      3.513     2.826   19.926  16.822  -0.320
WBIS3   273.326 320   0.972      0.851     0.859   -1.898  -1.951   0.620
WBIS4   228.926 320   1.000      0.713     0.705   -3.772  -4.289   0.705
WBIS5   171.241 320   1.000      0.533     0.510   -7.227  -8.237   0.840
WBIS6   199.653 320   1.000      0.622     0.621   -5.600  -5.966   0.779
WBIS7   215.254 320   1.000      0.671     0.701   -3.569  -4.036   0.726
WBIS8   184.459 320   1.000      0.575     0.635   -5.305  -5.059   0.785
WBIS10  202.407 320   1.000      0.631     0.665   -4.940  -4.812   0.769
WBIS11  205.966 320   1.000      0.642     0.629   -4.519  -5.534   0.779

outfit MSQ應該要在0.5~1.5之間,結果看起來第一題最差 p<0.05表示題目比較不好 p>0.05表示題目跟概念比較吻合 Discrim鑑別度,僅供參考,因為在計算infit/outfit時,Discrim是假設一致的 可以把第一題刪掉,再跑一次看看

#算person separation reliability
SepRel(pres.pcm.wbis)
Separation Reliability: 0.8364
#0.8364結果很不錯
thresholds(pcm.wbis)

Design Matrix Block 1:
       Location Threshold 1 Threshold 2 Threshold 3 Threshold 4
WBIS1  -0.61786    -2.23572    -0.62043    -0.42743     0.81213
WBIS3  -0.11431    -1.15059    -0.28797    -0.71633     1.69766
WBIS4  -0.37478    -0.89075    -0.80611    -0.51965     0.71739
WBIS5   0.16603    -0.75301    -0.31379     0.07349     1.65742
WBIS6   0.03918    -0.69366    -0.63544     0.04527     1.44056
WBIS7   1.38962     0.39989     0.68063     1.36941     3.10853
WBIS8   1.15655    -0.02419     0.97955     1.04547     2.62536
WBIS10  0.89827    -0.30046     0.58485     1.11650     2.19219
WBIS11  0.99848    -0.09129     0.59349     0.71834     2.77340
#看題目的答案是否有ranking
#thresholds應該要有方向性,逐漸變大或逐漸變小
#如果忽大忽小,表示disordered category不好
#WBIS1就有逐漸變大的趨勢
#WBIS3在Threshold2、Threshold3 ranking比較不按照順序,建議合併後重新收案
pcm.wbis

Results of PCM estimation: 

Call:  PCM(X = wbis) 

Conditional log-likelihood: -2740.322 
Number of iterations: 37 
Number of parameters: 35 

Item (Category) Difficulty Parameters (eta):
           WBIS1.c2   WBIS1.c3   WBIS1.c4   WBIS3.c1   WBIS3.c2   WBIS3.c3
Estimate -2.8561570 -3.2835853 -2.4714581 -1.1505871 -1.4385564 -2.1548849
Std.Err   0.2798626  0.2753554  0.2865144  0.2017425  0.2160686  0.2067263
           WBIS3.c4   WBIS4.c1   WBIS4.c2   WBIS4.c3   WBIS4.c4   WBIS5.c1
Estimate -0.4572243 -0.8907466 -1.6968558 -2.2165080 -1.4991150 -0.7530095
Std.Err   0.2576536  0.2182097  0.2152803  0.2145778  0.2346465  0.1777323
           WBIS5.c2   WBIS5.c3  WBIS5.c4   WBIS6.c1   WBIS6.c2   WBIS6.c3
Estimate -1.0668017 -0.9933123 0.6641069 -0.6936586 -1.3290943 -1.2838253
Std.Err   0.1870984  0.1984225 0.2618894  0.1895772  0.1889014  0.2005348
          WBIS6.c4  WBIS7.c1 WBIS7.c2  WBIS7.c3  WBIS7.c4    WBIS8.c1  WBIS8.c2
Estimate 0.1567338 0.3998899 1.080520 2.4499304 5.5584610 -0.02419198 0.9553570
Std.Err  0.2509717 0.1410898 0.179407 0.2499671 0.5445029  0.13579334 0.1875039
          WBIS8.c3  WBIS8.c4  WBIS10.c1 WBIS10.c2 WBIS10.c3 WBIS10.c4
Estimate 2.0008257 4.6261885 -0.3004601 0.2843908 1.4008904 3.5930769
Std.Err  0.2387218 0.4387293  0.1413998 0.1755700 0.2285092 0.3690647
           WBIS11.c1 WBIS11.c2 WBIS11.c3 WBIS11.c4
Estimate -0.09128808 0.5021998  1.220536 3.9939358
Std.Err   0.14294025 0.1795317  0.212816 0.4068658