Read dataset

t = "C:\\Users\\Thuan Nguyen\\Documents\\myData.csv"
data = read.csv(t)
myData = data[,2:21]

Attaching data and fix it

attach(myData)
fix(myData)

Load the requirement libraries

library(devtools)
## Loading required package: usethis
library(psych)
library(GPArotation)
library(corpcor)
library(corrplot)
## corrplot 0.84 loaded
library(factoextra)
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(likert)
## Loading required package: xtable
#library(jbryer)
library(ggplot2)
library(grid)

Correlation Analysis

corMatrix=cor(myData)
round(corMatrix,5)
##           V1       V2       V4       V5       V7       V8       V9      V10
## V1   1.00000  0.44146  0.40224  0.40576 -0.05227 -0.05321 -0.02591  0.00489
## V2   0.44146  1.00000  0.32520  0.34585 -0.11228 -0.06484 -0.05851 -0.01247
## V4   0.40224  0.32520  1.00000  0.57540  0.01186  0.03317  0.05933  0.05464
## V5   0.40576  0.34585  0.57540  1.00000  0.06406  0.05556  0.06737  0.06994
## V7  -0.05227 -0.11228  0.01186  0.06406  1.00000  0.61864  0.27116  0.29047
## V8  -0.05321 -0.06484  0.03317  0.05556  0.61864  1.00000  0.31220  0.27300
## V9  -0.02591 -0.05851  0.05933  0.06737  0.27116  0.31220  1.00000  0.38393
## V10  0.00489 -0.01247  0.05464  0.06994  0.29047  0.27300  0.38393  1.00000
## V11 -0.00911 -0.01060  0.08077  0.07293  0.33682  0.35439  0.31957  0.63952
## V13 -0.04210 -0.05011 -0.13486 -0.17060 -0.02406 -0.02393  0.04622 -0.01932
## V14 -0.08278 -0.07092 -0.16808 -0.16568 -0.11871 -0.08121  0.02069 -0.06217
## V15 -0.09367 -0.12194 -0.24665 -0.24976 -0.29354 -0.29061 -0.21291 -0.21784
## V16 -0.04828 -0.03497 -0.11099 -0.12293 -0.06115 -0.09219 -0.06125 -0.06853
## V17 -0.06189 -0.05366 -0.14644 -0.17484 -0.18992 -0.18399 -0.13648 -0.17652
## V18 -0.01436 -0.06824 -0.05312 -0.15556 -0.21949 -0.21548 -0.11141 -0.13411
## V23 -0.06328 -0.09279  0.00097 -0.09355 -0.07683 -0.08496 -0.09861 -0.14821
## V24 -0.03076 -0.07402  0.02159 -0.05177 -0.10446 -0.12009 -0.12763 -0.18196
## V25 -0.04725 -0.08300 -0.05650 -0.08654 -0.08681 -0.07528 -0.05148 -0.13702
## V26 -0.07307 -0.08400 -0.10178 -0.15538 -0.12702 -0.08521 -0.08705 -0.14524
## V27  0.03268  0.01428 -0.02613 -0.03676 -0.11739 -0.10740 -0.10421 -0.14805
##          V11      V13      V14      V15      V16      V17      V18      V23
## V1  -0.00911 -0.04210 -0.08278 -0.09367 -0.04828 -0.06189 -0.01436 -0.06328
## V2  -0.01060 -0.05011 -0.07092 -0.12194 -0.03497 -0.05366 -0.06824 -0.09279
## V4   0.08077 -0.13486 -0.16808 -0.24665 -0.11099 -0.14644 -0.05312  0.00097
## V5   0.07293 -0.17060 -0.16568 -0.24976 -0.12293 -0.17484 -0.15556 -0.09355
## V7   0.33682 -0.02406 -0.11871 -0.29354 -0.06115 -0.18992 -0.21949 -0.07683
## V8   0.35439 -0.02393 -0.08121 -0.29061 -0.09219 -0.18399 -0.21548 -0.08496
## V9   0.31957  0.04622  0.02069 -0.21291 -0.06125 -0.13648 -0.11141 -0.09861
## V10  0.63952 -0.01932 -0.06217 -0.21784 -0.06853 -0.17652 -0.13411 -0.14821
## V11  1.00000 -0.06672 -0.09397 -0.31675 -0.16541 -0.25912 -0.26523 -0.14392
## V13 -0.06672  1.00000  0.52034  0.27850  0.25149  0.13116  0.24729  0.03158
## V14 -0.09397  0.52034  1.00000  0.32058  0.27422  0.16124  0.27786  0.05906
## V15 -0.31675  0.27850  0.32058  1.00000  0.31078  0.47950  0.44699  0.22403
## V16 -0.16541  0.25149  0.27422  0.31078  1.00000  0.28520  0.26146  0.14622
## V17 -0.25912  0.13116  0.16124  0.47950  0.28520  1.00000  0.26382  0.18278
## V18 -0.26523  0.24729  0.27786  0.44699  0.26146  0.26382  1.00000  0.30498
## V23 -0.14392  0.03158  0.05906  0.22403  0.14622  0.18278  0.30498  1.00000
## V24 -0.16592  0.05850  0.07149  0.18794  0.09710  0.13701  0.20667  0.59482
## V25 -0.17817  0.07389  0.09565  0.28002  0.13652  0.23200  0.31874  0.50802
## V26 -0.15583  0.09786  0.11314  0.29704  0.12636  0.25062  0.29856  0.50287
## V27 -0.17980  0.11873  0.11307  0.25548  0.09982  0.17250  0.25912  0.33535
##          V24      V25      V26      V27
## V1  -0.03076 -0.04725 -0.07307  0.03268
## V2  -0.07402 -0.08300 -0.08400  0.01428
## V4   0.02159 -0.05650 -0.10178 -0.02613
## V5  -0.05177 -0.08654 -0.15538 -0.03676
## V7  -0.10446 -0.08681 -0.12702 -0.11739
## V8  -0.12009 -0.07528 -0.08521 -0.10740
## V9  -0.12763 -0.05148 -0.08705 -0.10421
## V10 -0.18196 -0.13702 -0.14524 -0.14805
## V11 -0.16592 -0.17817 -0.15583 -0.17980
## V13  0.05850  0.07389  0.09786  0.11873
## V14  0.07149  0.09565  0.11314  0.11307
## V15  0.18794  0.28002  0.29704  0.25548
## V16  0.09710  0.13652  0.12636  0.09982
## V17  0.13701  0.23200  0.25062  0.17250
## V18  0.20667  0.31874  0.29856  0.25912
## V23  0.59482  0.50802  0.50287  0.33535
## V24  1.00000  0.53704  0.42091  0.33701
## V25  0.53704  1.00000  0.56590  0.36322
## V26  0.42091  0.56590  1.00000  0.46981
## V27  0.33701  0.36322  0.46981  1.00000
corrplot(corMatrix, method = "color")

KMO and Bartlett Test

#KMO Test
KMO(myData)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = myData)
## Overall MSA =  0.8
## MSA for each item = 
##   V1   V2   V4   V5   V7   V8   V9  V10  V11  V13  V14  V15  V16  V17  V18  V23 
## 0.77 0.77 0.73 0.76 0.74 0.74 0.84 0.71 0.76 0.71 0.74 0.87 0.87 0.86 0.88 0.83 
##  V24  V25  V26  V27 
## 0.80 0.85 0.85 0.88
#Bartlett Test
cortest.bartlett(myData)
## R was not square, finding R from data
## $chisq
## [1] 3408.639
## 
## $p.value
## [1] 0
## 
## $df
## [1] 190

EFA analysis

pca1 <- prcomp(myData, scale = TRUE)
get_eig(pca1)
##        eigenvalue variance.percent cumulative.variance.percent
## Dim.1   4.4154995        22.077498                    22.07750
## Dim.2   2.3719553        11.859777                    33.93727
## Dim.3   2.1020392        10.510196                    44.44747
## Dim.4   1.6417939         8.208969                    52.65644
## Dim.5   1.0206835         5.103418                    57.75986
## Dim.6   0.9635107         4.817553                    62.57741
## Dim.7   0.8373678         4.186839                    66.76425
## Dim.8   0.7646453         3.823226                    70.58748
## Dim.9   0.7001072         3.500536                    74.08801
## Dim.10  0.6697637         3.348818                    77.43683
## Dim.11  0.6535989         3.267994                    80.70482
## Dim.12  0.5497797         2.748898                    83.45372
## Dim.13  0.5193246         2.596623                    86.05035
## Dim.14  0.4833616         2.416808                    88.46715
## Dim.15  0.4718451         2.359225                    90.82638
## Dim.16  0.4276291         2.138145                    92.96452
## Dim.17  0.3986494         1.993247                    94.95777
## Dim.18  0.3554408         1.777204                    96.73497
## Dim.19  0.3325270         1.662635                    98.39761
## Dim.20  0.3204780         1.602390                   100.00000
fviz_screeplot(pca1, addlabels = TRUE, n = 12)

pc2 <- principal(myData, nfactors = 4, rotate = "varimax") #Choice n = 4 factors
print.psych(pc2, cut = 0.4, sort = TRUE)
## Principal Components Analysis
## Call: principal(r = myData, nfactors = 4, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     item   RC3   RC1   RC4   RC2   h2   u2 com
## V23   16  0.79                   0.63 0.37 1.0
## V25   18  0.79                   0.64 0.36 1.1
## V24   17  0.76                   0.59 0.41 1.0
## V26   19  0.75                   0.61 0.39 1.1
## V27   20  0.59                   0.40 0.60 1.3
## V11    9        0.72             0.56 0.44 1.1
## V8     6        0.71             0.53 0.47 1.1
## V10    8        0.70             0.52 0.48 1.1
## V7     5        0.69             0.51 0.49 1.1
## V9     7        0.64             0.42 0.58 1.1
## V14   11              0.76       0.58 0.42 1.0
## V13   10              0.75       0.57 0.43 1.0
## V16   13              0.57       0.34 0.66 1.1
## V15   12              0.57       0.57 0.43 2.5
## V18   15              0.52       0.44 0.56 2.2
## V17   14              0.40       0.32 0.68 2.7
## V4     3                    0.76 0.61 0.39 1.1
## V1     1                    0.76 0.58 0.42 1.0
## V5     4                    0.75 0.62 0.38 1.2
## V2     2                    0.69 0.50 0.50 1.1
## 
##                        RC3  RC1  RC4  RC2
## SS loadings           3.05 2.77 2.40 2.30
## Proportion Var        0.15 0.14 0.12 0.12
## Cumulative Var        0.15 0.29 0.41 0.53
## Proportion Explained  0.29 0.26 0.23 0.22
## Cumulative Proportion 0.29 0.55 0.78 1.00
## 
## Mean item complexity =  1.3
## Test of the hypothesis that 4 components are sufficient.
## 
## The root mean square of the residuals (RMSR) is  0.07 
##  with the empirical chi square  992.62  with prob <  3.6e-139 
## 
## Fit based upon off diagonal values = 0.91

Cronback’s alpha

#psych::alpha(myData[, c(06, 18, 13, 07, 14, 10, 15)])

Structural Equation Modelling

library(lavaan)
## This is lavaan 0.6-5
## lavaan is BETA software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## The following object is masked from 'package:psych':
## 
##     cor2cov
model <- '
   # measurement model
     n1 =~ V1 + V2 + V4 +V5
     n2 =~ V7 + V8 + V9 + V10 + V11
     n3 =~ V13 + V14 + V15 + V16 + V17 + V18
     n4 =~ V23 + V24 + V25 +V26 + V27
   # regressions
     n4 ~ n1
     n4 ~ n2
     n4 ~ n3
     n1 ~ n2
     n1 ~ n3
     n2 ~ n3
'
fit <- sem(model, data=myData)
summary(fit, standardized=TRUE)
## lavaan 0.6-5 ended normally after 67 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         46
##                                                       
##   Number of observations                           593
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                               674.762
##   Degrees of freedom                               164
##   P-value (Chi-square)                           0.000
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard errors                             Standard
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   n1 =~                                                                 
##     V1                1.000                               0.637    0.573
##     V2                0.832    0.090    9.235    0.000    0.530    0.501
##     V4                1.265    0.110   11.520    0.000    0.806    0.731
##     V5                1.463    0.126   11.587    0.000    0.932    0.758
##   n2 =~                                                                 
##     V7                1.000                               0.553    0.543
##     V8                1.032    0.106    9.738    0.000    0.571    0.551
##     V9                1.025    0.116    8.867    0.000    0.567    0.481
##     V10               1.454    0.129   11.233    0.000    0.804    0.710
##     V11               1.560    0.135   11.529    0.000    0.863    0.768
##   n3 =~                                                                 
##     V13               1.000                               0.248    0.405
##     V14               1.048    0.147    7.152    0.000    0.260    0.456
##     V15               2.311    0.266    8.680    0.000    0.573    0.779
##     V16               1.149    0.163    7.040    0.000    0.285    0.443
##     V17               1.742    0.222    7.834    0.000    0.432    0.553
##     V18               1.714    0.214    7.997    0.000    0.425    0.582
##   n4 =~                                                                 
##     V23               1.000                               1.095    0.721
##     V24               0.983    0.066   14.914    0.000    1.077    0.695
##     V25               1.083    0.068   15.825    0.000    1.186    0.747
##     V26               1.100    0.072   15.358    0.000    1.204    0.719
##     V27               0.946    0.082   11.598    0.000    1.036    0.531
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   n4 ~                                                                  
##     n1                0.057    0.093    0.620    0.536    0.033    0.033
##     n2               -0.161    0.116   -1.381    0.167   -0.081   -0.081
##     n3                1.968    0.360    5.466    0.000    0.445    0.445
##   n1 ~                                                                  
##     n2               -0.136    0.073   -1.864    0.062   -0.118   -0.118
##     n3               -1.054    0.207   -5.096    0.000   -0.410   -0.410
##   n2 ~                                                                  
##     n3               -1.051    0.172   -6.119    0.000   -0.471   -0.471
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .V1                0.830    0.057   14.658    0.000    0.830    0.672
##    .V2                0.840    0.054   15.492    0.000    0.840    0.749
##    .V4                0.568    0.052   10.823    0.000    0.568    0.466
##    .V5                0.643    0.066    9.805    0.000    0.643    0.425
##    .V7                0.730    0.048   15.289    0.000    0.730    0.705
##    .V8                0.747    0.049   15.209    0.000    0.747    0.697
##    .V9                1.070    0.068   15.846    0.000    1.070    0.769
##    .V10               0.636    0.052   12.342    0.000    0.636    0.496
##    .V11               0.518    0.050   10.454    0.000    0.518    0.411
##    .V13               0.313    0.019   16.306    0.000    0.313    0.836
##    .V14               0.257    0.016   15.992    0.000    0.257    0.792
##    .V15               0.212    0.021    9.921    0.000    0.212    0.393
##    .V16               0.333    0.021   16.082    0.000    0.333    0.804
##    .V17               0.422    0.028   15.128    0.000    0.422    0.694
##    .V18               0.352    0.024   14.777    0.000    0.352    0.661
##    .V23               1.107    0.083   13.349    0.000    1.107    0.480
##    .V24               1.240    0.089   13.889    0.000    1.240    0.517
##    .V25               1.115    0.088   12.705    0.000    1.115    0.442
##    .V26               1.351    0.101   13.387    0.000    1.351    0.482
##    .V27               2.740    0.173   15.846    0.000    2.740    0.718
##    .n1                0.351    0.054    6.517    0.000    0.864    0.864
##    .n2                0.238    0.038    6.182    0.000    0.778    0.778
##     n3                0.061    0.013    4.574    0.000    1.000    1.000
##    .n4                0.925    0.105    8.835    0.000    0.771    0.771

Bootstraping

model <- '
    # measurement model
      n1 =~ V1 + V2 + V4 +V5
      n2 =~ V7 + V8 + V9 + V10 + V11
      n3 =~ V13 + V14 + V15 + V16 + V17 + V18
      n4 =~ V23 + V24 + V25 +V26 + V27
    # regressions
      n4 ~ n1
      n4 ~ n2
      n4 ~ n3
      n1 ~ n2
      n1 ~ n3
      n2 ~ n3
'
fit2 <- sem(model, data=myData, se="bootstrap")
summary(fit2, standardized=TRUE)
## lavaan 0.6-5 ended normally after 67 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         46
##                                                       
##   Number of observations                           593
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                               674.762
##   Degrees of freedom                               164
##   P-value (Chi-square)                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                            Bootstrap
##   Number of requested bootstrap draws             1000
##   Number of successful bootstrap draws            1000
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   n1 =~                                                                 
##     V1                1.000                               0.637    0.573
##     V2                0.832    0.074   11.316    0.000    0.530    0.501
##     V4                1.265    0.123   10.264    0.000    0.806    0.731
##     V5                1.463    0.163    8.990    0.000    0.932    0.758
##   n2 =~                                                                 
##     V7                1.000                               0.553    0.543
##     V8                1.032    0.070   14.662    0.000    0.571    0.551
##     V9                1.025    0.185    5.534    0.000    0.567    0.481
##     V10               1.454    0.361    4.024    0.000    0.804    0.710
##     V11               1.560    0.364    4.287    0.000    0.863    0.768
##   n3 =~                                                                 
##     V13               1.000                               0.248    0.405
##     V14               1.048    0.112    9.343    0.000    0.260    0.456
##     V15               2.311    0.402    5.755    0.000    0.573    0.779
##     V16               1.149    0.193    5.965    0.000    0.285    0.443
##     V17               1.742    0.347    5.019    0.000    0.432    0.553
##     V18               1.714    0.268    6.391    0.000    0.425    0.582
##   n4 =~                                                                 
##     V23               1.000                               1.095    0.721
##     V24               0.983    0.055   17.735    0.000    1.077    0.695
##     V25               1.083    0.070   15.366    0.000    1.186    0.747
##     V26               1.100    0.079   14.006    0.000    1.204    0.719
##     V27               0.946    0.087   10.841    0.000    1.036    0.531
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   n4 ~                                                                  
##     n1                0.057    0.100    0.575    0.565    0.033    0.033
##     n2               -0.161    0.152   -1.059    0.290   -0.081   -0.081
##     n3                1.968    0.517    3.807    0.000    0.445    0.445
##   n1 ~                                                                  
##     n2               -0.136    0.077   -1.763    0.078   -0.118   -0.118
##     n3               -1.054    0.267   -3.951    0.000   -0.410   -0.410
##   n2 ~                                                                  
##     n3               -1.051    0.350   -3.008    0.003   -0.471   -0.471
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .V1                0.830    0.064   12.942    0.000    0.830    0.672
##    .V2                0.840    0.057   14.777    0.000    0.840    0.749
##    .V4                0.568    0.054   10.454    0.000    0.568    0.466
##    .V5                0.643    0.085    7.603    0.000    0.643    0.425
##    .V7                0.730    0.104    7.016    0.000    0.730    0.705
##    .V8                0.747    0.118    6.319    0.000    0.747    0.697
##    .V9                1.070    0.062   17.375    0.000    1.070    0.769
##    .V10               0.636    0.124    5.146    0.000    0.636    0.496
##    .V11               0.518    0.127    4.069    0.000    0.518    0.411
##    .V13               0.313    0.024   12.900    0.000    0.313    0.836
##    .V14               0.257    0.020   12.589    0.000    0.257    0.792
##    .V15               0.212    0.026    8.057    0.000    0.212    0.393
##    .V16               0.333    0.025   13.479    0.000    0.333    0.804
##    .V17               0.422    0.038   11.219    0.000    0.422    0.694
##    .V18               0.352    0.029   12.238    0.000    0.352    0.661
##    .V23               1.107    0.100   11.067    0.000    1.107    0.480
##    .V24               1.240    0.112   11.066    0.000    1.240    0.517
##    .V25               1.115    0.110   10.159    0.000    1.115    0.442
##    .V26               1.351    0.123   10.975    0.000    1.351    0.482
##    .V27               2.740    0.168   16.273    0.000    2.740    0.718
##    .n1                0.351    0.064    5.497    0.000    0.864    0.864
##    .n2                0.238    0.087    2.747    0.006    0.778    0.778
##     n3                0.061    0.018    3.356    0.001    1.000    1.000
##    .n4                0.925    0.108    8.533    0.000    0.771    0.771