7  Factor Analysis and Structural Equation Modeling (SEM)

7.1 Analisis Faktor

harga <- read.csv("Data/harga.csv")
head(harga)
         City Bread Burger Milk Oranges Tomatoes
1    Atlanta   24.5   94.5 73.9    80.1     41.6
2  Baltimore   26.5   91.0 67.5    74.6     33.3
3     Boston   29.7  100.8 61.4   104.0     59.6
4    Buffalo   22.8   86.6 65.3   118.4     61.2
5    Chicago   26.7   86.7 62.7   105.9     60.2
6 Cincinnati   25.3  102.5 63.3    99.3     45.6
str(harga)
'data.frame':   23 obs. of  6 variables:
 $ City    : chr  "Atlanta " "Baltimore " "Boston " "Buffalo " ...
 $ Bread   : num  24.5 26.5 29.7 22.8 26.7 25.3 22.8 23.3 24.1 29.3 ...
 $ Burger  : num  94.5 91 100.8 86.6 86.7 ...
 $ Milk    : num  73.9 67.5 61.4 65.3 62.7 63.3 52.4 62.5 51.5 80.2 ...
 $ Oranges : num  80.1 74.6 104 118.4 105.9 ...
 $ Tomatoes: num  41.6 33.3 59.6 61.2 60.2 45.6 60.1 60.8 60.5 71.7 ...

7.1.1 EFA

library(corrplot)
corrplot(cor(harga[,2:6]), method="number")

library(psych)
KMO(harga[,2:6])
Kaiser-Meyer-Olkin factor adequacy
Call: KMO(r = harga[, 2:6])
Overall MSA =  0.52
MSA for each item = 
   Bread   Burger     Milk  Oranges Tomatoes 
    0.52     0.58     0.59     0.49     0.48 
# Bartlett's Test of Sphericity
cortest.bartlett(harga[,2:6])
$chisq
[1] 36.46285

$p.value
[1] 7.006877e-05

$df
[1] 10
# Anti image correlation (AIC)
corrplot(KMO(harga[,2:6])$ImCo, method="number") 

# Determinan positif
det(cor(harga[,2:6]))
[1] 0.1541406
# Principal component analysis (PCA)
pca1 = princomp(harga[,2:6], scores=TRUE, cor=TRUE)
summary(pca1)
Importance of components:
                          Comp.1    Comp.2    Comp.3     Comp.4     Comp.5
Standard deviation     1.4841538 1.2325047 0.8824610 0.55357732 0.43935672
Proportion of Variance 0.4405425 0.3038136 0.1557475 0.06128957 0.03860687
Cumulative Proportion  0.4405425 0.7443561 0.9001036 0.96139313 1.00000000
scree(harga[,2:6])

# Menentukan faktor loading Analisis faktor loading
loadings(pca1)

Loadings:
         Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Bread     0.436  0.484  0.354  0.597  0.306
Burger    0.542  0.292  0.307 -0.657 -0.309
Milk      0.346  0.308 -0.866        -0.163
Oranges   0.410 -0.579  0.108  0.399 -0.571
Tomatoes  0.478 -0.500 -0.137 -0.211  0.677

               Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
SS loadings       1.0    1.0    1.0    1.0    1.0
Proportion Var    0.2    0.2    0.2    0.2    0.2
Cumulative Var    0.2    0.4    0.6    0.8    1.0
# Rotasi untuk mengkonfirmasi hasil analisis loading
fa1 = factanal(harga[,2:6], factor=2, rotation="varimax")
fa1

Call:
factanal(x = harga[, 2:6], factors = 2, rotation = "varimax")

Uniquenesses:
   Bread   Burger     Milk  Oranges Tomatoes 
   0.239    0.318    0.830    0.420    0.005 

Loadings:
         Factor1 Factor2
Bread             0.868 
Burger    0.195   0.803 
Milk      0.135   0.390 
Oranges   0.756         
Tomatoes  0.985   0.157 

               Factor1 Factor2
SS loadings      1.605   1.583
Proportion Var   0.321   0.317
Cumulative Var   0.321   0.638

Test of the hypothesis that 2 factors are sufficient.
The chi square statistic is 1.16 on 1 degree of freedom.
The p-value is 0.282 
# Diagram jalur hasil analisis EFA dan menampilkan faktor loading-nya
fa.diagram(fa1$loadings, digits = 3)

7.1.2 CFA

# Spesifikasi model
attach(harga)
model1 <- "
F1 =~ Tomatoes + Oranges
F2 =~ Bread + Burger + Milk
F1 ~~ F2 "
library(lavaan)
fitmod = cfa(model1, data = harga)
summary(fitmod, fit.measures = TRUE, standardized = TRUE)
lavaan 0.6-19 ended normally after 85 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        11

  Number of observations                            23

Model Test User Model:
                                                      
  Test statistic                                 3.642
  Degrees of freedom                                 4
  P-value (Chi-square)                           0.457

Model Test Baseline Model:

  Test statistic                                43.007
  Degrees of freedom                                10
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    1.000
  Tucker-Lewis Index (TLI)                       1.027

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)               -367.812
  Loglikelihood unrestricted model (H1)       -365.991
                                                      
  Akaike (AIC)                                 757.623
  Bayesian (BIC)                               770.114
  Sample-size adjusted Bayesian (SABIC)        736.072

Root Mean Square Error of Approximation:

  RMSEA                                          0.000
  90 Percent confidence interval - lower         0.000
  90 Percent confidence interval - upper         0.302
  P-value H_0: RMSEA <= 0.050                    0.487
  P-value H_0: RMSEA >= 0.080                    0.469

Standardized Root Mean Square Residual:

  SRMR                                           0.065

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
  F1 =~                                                                 
    Tomatoes          1.000                              10.659    1.062
    Oranges           0.934    0.580    1.611    0.107    9.952    0.715
  F2 =~                                                                 
    Bread             1.000                               1.622    0.662
    Burger            4.700    2.464    1.907    0.056    7.623    1.032
    Milk              1.307    0.858    1.523    0.128    2.119    0.312

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  F1 ~~                                                                 
    F2                5.161    4.482    1.151    0.250    0.299    0.299

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .Tomatoes        -12.966   66.742   -0.194    0.846  -12.966   -0.129
   .Oranges          94.906   64.476    1.472    0.141   94.906    0.489
   .Bread             3.381    1.581    2.138    0.033    3.381    0.562
   .Burger           -3.518   27.199   -0.129    0.897   -3.518   -0.064
   .Milk             41.714   12.439    3.354    0.001   41.714    0.903
    F1              113.605   72.842    1.560    0.119    1.000    1.000
    F2                2.631    1.912    1.376    0.169    1.000    1.000
fitmeasures(fitmod)
                 npar                  fmin                 chisq 
               11.000                 0.079                 3.642 
                   df                pvalue        baseline.chisq 
                4.000                 0.457                43.007 
          baseline.df       baseline.pvalue                   cfi 
               10.000                 0.000                 1.000 
                  tli                  nnfi                   rfi 
                1.027                 1.027                 0.788 
                  nfi                  pnfi                   ifi 
                0.915                 0.366                 1.009 
                  rni                  logl     unrestricted.logl 
                1.011              -367.812              -365.991 
                  aic                   bic                ntotal 
              757.623               770.114                23.000 
                 bic2                 rmsea        rmsea.ci.lower 
              736.072                 0.000                 0.000 
       rmsea.ci.upper        rmsea.ci.level          rmsea.pvalue 
                0.302                 0.900                 0.487 
       rmsea.close.h0 rmsea.notclose.pvalue     rmsea.notclose.h0 
                0.050                 0.469                 0.080 
                  rmr            rmr_nomean                  srmr 
                2.823                 2.823                 0.065 
         srmr_bentler   srmr_bentler_nomean                  crmr 
                0.065                 0.065                 0.080 
          crmr_nomean            srmr_mplus     srmr_mplus_nomean 
                0.080                 0.065                 0.065 
                cn_05                 cn_01                   gfi 
               60.915                84.843                 0.947 
                 agfi                  pgfi                   mfi 
                0.803                 0.253                 1.008 
                 ecvi 
                1.115 
library(semPlot)
semPaths(fitmod, what='std', layout='tree', title = TRUE, 
         posCol = 1, nDigits = 3, 
         edge.label.cex=0.7, 
         exoVar = FALSE, 
         sizeMan = 5, 
         sizeLat = 5)

# Estimasi Reliabilitas alpha cronbach
psych::alpha(harga[,2:6])

Reliability analysis   
Call: psych::alpha(x = harga[, 2:6])

  raw_alpha std.alpha G6(smc) average_r S/N ase mean  sd median_r
      0.63      0.67    0.77      0.29 2.1 0.1   67 5.8     0.26

    95% confidence boundaries 
         lower alpha upper
Feldt     0.32  0.63  0.82
Duhachek  0.42  0.63  0.83

 Reliability if an item is dropped:
         raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
Bread         0.64      0.63    0.68      0.30 1.7    0.110 0.065  0.26
Burger        0.56      0.54    0.63      0.23 1.2    0.107 0.083  0.13
Milk          0.64      0.68    0.78      0.34 2.1    0.091 0.096  0.26
Oranges       0.55      0.65    0.66      0.32 1.9    0.140 0.043  0.32
Tomatoes      0.37      0.59    0.61      0.26 1.4    0.197 0.062  0.27

 Item statistics 
          n raw.r std.r r.cor r.drop mean   sd
Bread    23  0.38  0.64  0.56   0.30   25  2.5
Burger   23  0.62  0.77  0.72   0.41   92  7.6
Milk     23  0.42  0.56  0.36   0.20   62  7.0
Oranges  23  0.82  0.61  0.56   0.49  103 14.2
Tomatoes 23  0.86  0.71  0.68   0.71   52 10.3

7.2 Model Persamaan Struktural (SEM)

library(lavaan)  
library(semPlot)
library(readxl)
datasem <- read_excel("Data/Datalikert.xlsx")
head(datasem[,1:5])
# A tibble: 6 × 5
  Perusahaan Provinsi   Pulau    A1    A2
       <dbl> <chr>      <chr> <dbl> <dbl>
1          1 Jawa Barat Jawa      4     5
2          2 Jawa Timur Jawa      5     5
3          3 Jawa Timur Jawa      4     4
4          4 Jawa Barat Jawa      4     4
5          5 Jawa Timur Jawa      4     4
6          6 Jawa Timur Jawa      4     4
str(datasem)
tibble [300 × 45] (S3: tbl_df/tbl/data.frame)
 $ Perusahaan: num [1:300] 1 2 3 4 5 6 7 8 9 10 ...
 $ Provinsi  : chr [1:300] "Jawa Barat" "Jawa Timur" "Jawa Timur" "Jawa Barat" ...
 $ Pulau     : chr [1:300] "Jawa" "Jawa" "Jawa" "Jawa" ...
 $ A1        : num [1:300] 4 5 4 4 4 4 4 5 4 5 ...
 $ A2        : num [1:300] 5 5 4 4 4 4 4 5 4 5 ...
 $ A3        : num [1:300] 5 5 4 3 4 5 4 5 3 5 ...
 $ A4        : num [1:300] 4 5 4 4 3 4 4 5 3 5 ...
 $ A5        : num [1:300] 4 4 4 4 4 4 4 5 3 5 ...
 $ A6        : num [1:300] 4 5 4 4 4 4 4 5 3 4 ...
 $ A7        : num [1:300] 5 5 5 4 4 4 4 5 3 5 ...
 $ A8        : num [1:300] 5 5 5 4 4 4 4 5 3 4 ...
 $ Atotal    : num [1:300] 36 39 34 31 31 33 32 40 26 38 ...
 $ B1        : num [1:300] 4 4 4 4 3 5 3 3 3 4 ...
 $ B2        : num [1:300] 4 4 4 3 4 4 3 3 2 4 ...
 $ Btotal    : num [1:300] 8 8 8 7 7 9 6 6 5 8 ...
 $ C1        : num [1:300] 4 4 4 4 4 4 4 5 3 4 ...
 $ C2        : num [1:300] 4 4 4 4 4 4 4 4 3 4 ...
 $ Ctotal    : num [1:300] 8 8 8 8 8 8 8 9 6 8 ...
 $ D1        : num [1:300] 4 5 4 4 4 4 4 4 3 4 ...
 $ D2        : num [1:300] 4 5 4 3 4 5 4 4 2 4 ...
 $ D3        : num [1:300] 4 5 4 4 4 4 4 4 3 4 ...
 $ D4        : num [1:300] 4 5 4 5 4 4 4 4 3 4 ...
 $ Dtotal    : num [1:300] 16 20 16 16 16 17 16 16 11 16 ...
 $ E1        : num [1:300] 5 5 4 4 4 4 4 4 3 5 ...
 $ E2        : num [1:300] 5 5 4 4 4 5 4 4 3 5 ...
 $ E3        : num [1:300] 5 5 4 4 4 5 4 5 4 5 ...
 $ E4        : num [1:300] 4 5 4 3 4 5 4 4 3 4 ...
 $ E5        : num [1:300] 4 5 4 4 3 5 4 4 3 4 ...
 $ E6        : num [1:300] 4 5 4 4 4 4 4 4 3 4 ...
 $ E7        : num [1:300] 4 5 4 4 4 5 4 4 3 4 ...
 $ E8        : num [1:300] 4 5 4 4 3 5 4 4 3 4 ...
 $ E9        : num [1:300] 4 5 4 4 4 4 4 4 3 4 ...
 $ E10       : num [1:300] 4 5 4 4 4 5 4 5 3 4 ...
 $ E11       : num [1:300] 4 5 4 3 3 5 4 5 3 4 ...
 $ E12       : num [1:300] 5 5 4 4 4 5 4 5 3 5 ...
 $ Etotal    : num [1:300] 52 60 48 46 45 57 48 52 37 52 ...
 $ F1        : num [1:300] 5 5 4 4 4 5 4 4 2 4 ...
 $ F2        : num [1:300] 4 5 4 4 4 5 4 4 3 3 ...
 $ F3        : num [1:300] 4 5 4 4 4 4 4 4 2 3 ...
 $ F4        : num [1:300] 4 5 4 4 4 5 4 5 3 4 ...
 $ F5        : num [1:300] 4 5 4 4 3 5 4 4 3 3 ...
 $ F6        : num [1:300] 4 5 4 4 3 4 4 5 3 4 ...
 $ F7        : num [1:300] 4 5 4 4 3 4 4 4 3 4 ...
 $ F8        : num [1:300] 4 5 4 4 4 5 4 4 3 4 ...
 $ Ftotal    : num [1:300] 33 40 32 32 29 37 32 34 22 29 ...
attach(datasem)
table(A1)
A1
  1   2   3   4   5 
  3   4  37 121 135 
barplot(table(A1))

# Spesifikasi Model
sem.model = "
faktor =~ A1 + A2 + A3 + A4
permintaan =~ B1 + B2  
industri =~ C1 + C2  
strategi =~ D1 + D2 + D3 + D4
regulasi =~ E1 + E2 + E3 + E4 + E5 + E6
kesempatan =~ F1 + F2 + F3 + F4
kesempatan ~ faktor + permintaan + industri + strategi + regulasi"
sem.fit = sem(sem.model, data = datasem)
summary(sem.fit, fit.measures=TRUE)
lavaan 0.6-19 ended normally after 90 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        59

  Number of observations                           300

Model Test User Model:
                                                      
  Test statistic                               555.757
  Degrees of freedom                               194
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              7355.210
  Degrees of freedom                               231
  P-value                                        0.000

User Model versus Baseline Model:

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

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4608.159
  Loglikelihood unrestricted model (H1)      -4330.280
                                                      
  Akaike (AIC)                                9334.318
  Bayesian (BIC)                              9552.841
  Sample-size adjusted Bayesian (SABIC)       9365.728

Root Mean Square Error of Approximation:

  RMSEA                                          0.079
  90 Percent confidence interval - lower         0.071
  90 Percent confidence interval - upper         0.087
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.410

Standardized Root Mean Square Residual:

  SRMR                                           0.035

Parameter Estimates:

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

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  faktor =~                                           
    A1                1.000                           
    A2                1.266    0.089   14.271    0.000
    A3                1.312    0.094   13.991    0.000
    A4                1.261    0.091   13.913    0.000
  permintaan =~                                       
    B1                1.000                           
    B2                1.020    0.063   16.072    0.000
  industri =~                                         
    C1                1.000                           
    C2                1.035    0.044   23.446    0.000
  strategi =~                                         
    D1                1.000                           
    D2                0.973    0.033   29.472    0.000
    D3                0.972    0.043   22.590    0.000
    D4                0.817    0.042   19.325    0.000
  regulasi =~                                         
    E1                1.000                           
    E2                0.929    0.039   23.666    0.000
    E3                0.950    0.043   22.088    0.000
    E4                1.015    0.039   25.697    0.000
    E5                0.985    0.042   23.464    0.000
    E6                0.913    0.045   20.186    0.000
  kesempatan =~                                       
    F1                1.000                           
    F2                1.006    0.038   26.712    0.000
    F3                1.033    0.042   24.672    0.000
    F4                0.943    0.046   20.414    0.000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  kesempatan ~                                        
    faktor            0.016    0.111    0.146    0.884
    permintaan        0.042    0.059    0.705    0.481
    industri          0.129    0.133    0.976    0.329
    strategi          0.131    0.091    1.449    0.147
    regulasi          0.685    0.077    8.860    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  faktor ~~                                           
    permintaan        0.233    0.034    6.785    0.000
    industri          0.327    0.037    8.729    0.000
    strategi          0.292    0.035    8.242    0.000
    regulasi          0.343    0.039    8.730    0.000
  permintaan ~~                                       
    industri          0.366    0.043    8.447    0.000
    strategi          0.391    0.045    8.713    0.000
    regulasi          0.332    0.043    7.797    0.000
  industri ~~                                         
    strategi          0.437    0.043   10.274    0.000
    regulasi          0.416    0.043    9.764    0.000
  strategi ~~                                         
    regulasi          0.405    0.042    9.580    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .A1                0.323    0.029   11.229    0.000
   .A2                0.161    0.018    8.902    0.000
   .A3                0.205    0.022    9.430    0.000
   .A4                0.198    0.021    9.552    0.000
   .B1                0.269    0.032    8.457    0.000
   .B2                0.078    0.025    3.161    0.002
   .C1                0.122    0.014    8.515    0.000
   .C2                0.106    0.014    7.549    0.000
   .D1                0.093    0.011    8.749    0.000
   .D2                0.063    0.008    7.476    0.000
   .D3                0.182    0.017   10.625    0.000
   .D4                0.200    0.018   11.219    0.000
   .E1                0.145    0.014   10.563    0.000
   .E2                0.114    0.011   10.395    0.000
   .E3                0.156    0.014   10.845    0.000
   .E4                0.091    0.010    9.488    0.000
   .E5                0.133    0.013   10.462    0.000
   .E6                0.198    0.018   11.224    0.000
   .F1                0.139    0.014    9.697    0.000
   .F2                0.090    0.011    8.221    0.000
   .F3                0.140    0.015    9.540    0.000
   .F4                0.233    0.021   10.912    0.000
    faktor            0.321    0.047    6.841    0.000
    permintaan        0.525    0.065    8.048    0.000
    industri          0.480    0.049    9.751    0.000
    strategi          0.522    0.050   10.406    0.000
    regulasi          0.542    0.055    9.811    0.000
   .kesempatan        0.122    0.015    8.068    0.000
sem.fit = sem(sem.model, data = datasem, std.lv=TRUE)
summary(sem.fit, fit.measures=TRUE, standardized=TRUE)
lavaan 0.6-19 ended normally after 90 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        59

  Number of observations                           300

Model Test User Model:
                                                      
  Test statistic                               555.757
  Degrees of freedom                               194
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              7355.210
  Degrees of freedom                               231
  P-value                                        0.000

User Model versus Baseline Model:

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

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4608.159
  Loglikelihood unrestricted model (H1)      -4330.280
                                                      
  Akaike (AIC)                                9334.318
  Bayesian (BIC)                              9552.841
  Sample-size adjusted Bayesian (SABIC)       9365.728

Root Mean Square Error of Approximation:

  RMSEA                                          0.079
  90 Percent confidence interval - lower         0.071
  90 Percent confidence interval - upper         0.087
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.410

Standardized Root Mean Square Residual:

  SRMR                                           0.035

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
  faktor =~                                                             
    A1                0.566    0.041   13.681    0.000    0.566    0.706
    A2                0.717    0.038   18.699    0.000    0.717    0.872
    A3                0.743    0.041   18.064    0.000    0.743    0.854
    A4                0.714    0.040   17.894    0.000    0.714    0.849
  permintaan =~                                                         
    B1                0.725    0.045   16.097    0.000    0.725    0.813
    B2                0.739    0.038   19.509    0.000    0.739    0.935
  industri =~                                                           
    C1                0.692    0.036   19.503    0.000    0.692    0.893
    C2                0.717    0.036   20.132    0.000    0.717    0.911
  strategi =~                                                           
    D1                0.723    0.035   20.812    0.000    0.723    0.922
    D2                0.703    0.033   21.615    0.000    0.703    0.941
    D3                0.702    0.038   18.344    0.000    0.702    0.855
    D4                0.590    0.036   16.459    0.000    0.590    0.797
  regulasi =~                                                           
    E1                0.736    0.038   19.623    0.000    0.736    0.888
    E2                0.684    0.034   19.941    0.000    0.684    0.897
    E3                0.699    0.037   18.967    0.000    0.699    0.870
    E4                0.747    0.035   21.120    0.000    0.747    0.927
    E5                0.725    0.037   19.819    0.000    0.725    0.894
    E6                0.673    0.038   17.720    0.000    0.673    0.834
  kesempatan =~                                                         
    F1                0.350    0.022   16.135    0.000    0.771    0.900
    F2                0.352    0.021   16.722    0.000    0.776    0.933
    F3                0.361    0.022   16.227    0.000    0.796    0.905
    F4                0.330    0.022   14.833    0.000    0.727    0.833

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  kesempatan ~                                                          
    faktor            0.026    0.180    0.146    0.884    0.012    0.012
    permintaan        0.086    0.123    0.705    0.481    0.039    0.039
    industri          0.256    0.263    0.973    0.331    0.116    0.116
    strategi          0.272    0.188    1.447    0.148    0.123    0.123
    regulasi          1.443    0.190    7.608    0.000    0.654    0.654

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  faktor ~~                                                             
    permintaan        0.568    0.046   12.297    0.000    0.568    0.568
    industri          0.833    0.025   33.258    0.000    0.833    0.833
    strategi          0.715    0.033   21.548    0.000    0.715    0.715
    regulasi          0.822    0.023   35.175    0.000    0.822    0.822
  permintaan ~~                                                         
    industri          0.729    0.035   20.610    0.000    0.729    0.729
    strategi          0.746    0.032   23.194    0.000    0.746    0.746
    regulasi          0.623    0.041   15.291    0.000    0.623    0.623
  industri ~~                                                           
    strategi          0.874    0.020   44.744    0.000    0.874    0.874
    regulasi          0.816    0.024   33.446    0.000    0.816    0.816
  strategi ~~                                                           
    regulasi          0.762    0.027   27.976    0.000    0.762    0.762

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .A1                0.323    0.029   11.229    0.000    0.323    0.502
   .A2                0.161    0.018    8.902    0.000    0.161    0.239
   .A3                0.205    0.022    9.430    0.000    0.205    0.271
   .A4                0.198    0.021    9.552    0.000    0.198    0.280
   .B1                0.269    0.032    8.457    0.000    0.269    0.339
   .B2                0.078    0.025    3.161    0.002    0.078    0.126
   .C1                0.122    0.014    8.515    0.000    0.122    0.203
   .C2                0.106    0.014    7.549    0.000    0.106    0.171
   .D1                0.093    0.011    8.749    0.000    0.093    0.151
   .D2                0.063    0.008    7.476    0.000    0.063    0.114
   .D3                0.182    0.017   10.625    0.000    0.182    0.270
   .D4                0.200    0.018   11.219    0.000    0.200    0.365
   .E1                0.145    0.014   10.563    0.000    0.145    0.211
   .E2                0.114    0.011   10.395    0.000    0.114    0.195
   .E3                0.156    0.014   10.845    0.000    0.156    0.242
   .E4                0.091    0.010    9.488    0.000    0.091    0.141
   .E5                0.133    0.013   10.462    0.000    0.133    0.201
   .E6                0.198    0.018   11.224    0.000    0.198    0.304
   .F1                0.139    0.014    9.697    0.000    0.139    0.190
   .F2                0.090    0.011    8.221    0.000    0.090    0.130
   .F3                0.140    0.015    9.540    0.000    0.140    0.181
   .F4                0.233    0.021   10.912    0.000    0.233    0.306
    faktor            1.000                               1.000    1.000
    permintaan        1.000                               1.000    1.000
    industri          1.000                               1.000    1.000
    strategi          1.000                               1.000    1.000
    regulasi          1.000                               1.000    1.000
   .kesempatan        1.000                               0.206    0.206
#sem.fit = sem(sem.model, data = datasem, std.lv=TRUE, orthogonal=TRUE)
#summary(sem.fit, fit.measures=TRUE, standardized=TRUE)
# Modification Indices
modificationIndices(sem.fit, minimum.value = 10)
           lhs op rhs     mi    epc sepc.lv sepc.all sepc.nox
72      faktor =~  D3 10.792  0.143   0.143    0.174    0.174
82      faktor =~  F3 14.022 -0.170  -0.170   -0.193   -0.193
99  permintaan =~  E6 13.919  0.142   0.142    0.176    0.176
112   industri =~  D3 19.393  0.315   0.315    0.383    0.383
134   strategi =~  E3 11.975 -0.144  -0.144   -0.179   -0.179
152   regulasi =~  D3 18.808  0.197   0.197    0.240    0.240
157   regulasi =~  F4 13.142  0.272   0.272    0.312    0.312
168 kesempatan =~  D3 22.896  0.100   0.220    0.268    0.268
175 kesempatan =~  E6 25.214  0.153   0.337    0.418    0.418
176         A1 ~~  A2 15.863  0.068   0.068    0.298    0.298
270         B1 ~~  F4 14.265  0.063   0.063    0.253    0.253
317         D1 ~~  D3 10.752 -0.035  -0.035   -0.272   -0.272
331         D2 ~~  E1 11.098  0.025   0.025    0.257    0.257
347         D3 ~~  E6 12.029  0.042   0.042    0.223    0.223
351         D3 ~~  F4 10.217 -0.043  -0.043   -0.208   -0.208
352         D4 ~~  E1 11.953 -0.038  -0.038   -0.223   -0.223
362         E1 ~~  E2 17.329  0.038   0.038    0.294    0.294
363         E1 ~~  E3 10.360  0.033   0.033    0.220    0.220
364         E1 ~~  E4 12.186 -0.031  -0.031   -0.266   -0.266
371         E2 ~~  E3 11.663  0.032   0.032    0.236    0.236
373         E2 ~~  E5 10.449 -0.028  -0.028   -0.231   -0.231
381         E3 ~~  E6 11.439 -0.039  -0.039   -0.221   -0.221
386         E4 ~~  E5 25.380  0.043   0.043    0.388    0.388
398         E6 ~~  F2 14.478 -0.037  -0.037   -0.275   -0.275
399         E6 ~~  F3 20.998  0.052   0.052    0.310    0.310
405         F2 ~~  F4 24.019 -0.058  -0.058   -0.404   -0.404
406         F3 ~~  F4 14.294  0.050   0.050    0.279    0.279
sem.model2 = "
faktor =~ A1 + A2 + A3 + A4
permintaan =~ B1 + B2  
industri =~ C1 + C2  
strategi =~ D1 + D2 + D3 + D4
regulasi =~ E1 + E2 + E3 + E4 + E5 + E6
kesempatan =~ F1 + F2 + F3 + F4
kesempatan ~ faktor + permintaan + industri + strategi + regulasi
A1  ~~  A2
"
sem.fit = sem(sem.model2, data = datasem, std.lv=TRUE)
summary(sem.fit, fit.measures=TRUE, standardized=TRUE)
lavaan 0.6-19 ended normally after 94 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        60

  Number of observations                           300

Model Test User Model:
                                                      
  Test statistic                               540.535
  Degrees of freedom                               193
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              7355.210
  Degrees of freedom                               231
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.951
  Tucker-Lewis Index (TLI)                       0.942

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -4600.548
  Loglikelihood unrestricted model (H1)      -4330.280
                                                      
  Akaike (AIC)                                9321.095
  Bayesian (BIC)                              9543.322
  Sample-size adjusted Bayesian (SABIC)       9353.038

Root Mean Square Error of Approximation:

  RMSEA                                          0.077
  90 Percent confidence interval - lower         0.070
  90 Percent confidence interval - upper         0.085
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.303

Standardized Root Mean Square Residual:

  SRMR                                           0.035

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
  faktor =~                                                             
    A1                0.539    0.043   12.660    0.000    0.539    0.672
    A2                0.702    0.039   18.009    0.000    0.702    0.854
    A3                0.752    0.041   18.363    0.000    0.752    0.864
    A4                0.720    0.040   18.060    0.000    0.720    0.855
  permintaan =~                                                         
    B1                0.724    0.045   16.093    0.000    0.724    0.813
    B2                0.739    0.038   19.507    0.000    0.739    0.935
  industri =~                                                           
    C1                0.692    0.036   19.469    0.000    0.692    0.892
    C2                0.717    0.036   20.171    0.000    0.717    0.912
  strategi =~                                                           
    D1                0.723    0.035   20.813    0.000    0.723    0.922
    D2                0.703    0.033   21.613    0.000    0.703    0.941
    D3                0.702    0.038   18.345    0.000    0.702    0.855
    D4                0.590    0.036   16.460    0.000    0.590    0.797
  regulasi =~                                                           
    E1                0.736    0.038   19.615    0.000    0.736    0.888
    E2                0.684    0.034   19.943    0.000    0.684    0.897
    E3                0.699    0.037   18.964    0.000    0.699    0.870
    E4                0.747    0.035   21.115    0.000    0.747    0.927
    E5                0.726    0.037   19.826    0.000    0.726    0.894
    E6                0.673    0.038   17.728    0.000    0.673    0.834
  kesempatan =~                                                         
    F1                0.350    0.022   16.137    0.000    0.771    0.900
    F2                0.352    0.021   16.726    0.000    0.776    0.933
    F3                0.361    0.022   16.232    0.000    0.796    0.905
    F4                0.330    0.022   14.836    0.000    0.727    0.833

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  kesempatan ~                                                          
    faktor            0.031    0.186    0.167    0.867    0.014    0.014
    permintaan        0.087    0.122    0.709    0.478    0.039    0.039
    industri          0.253    0.267    0.947    0.344    0.115    0.115
    strategi          0.272    0.189    1.442    0.149    0.123    0.123
    regulasi          1.441    0.190    7.578    0.000    0.654    0.654

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
 .A1 ~~                                                                 
   .A2                0.068    0.019    3.588    0.000    0.068    0.269
  faktor ~~                                                             
    permintaan        0.573    0.046   12.417    0.000    0.573    0.573
    industri          0.837    0.025   33.458    0.000    0.837    0.837
    strategi          0.716    0.033   21.421    0.000    0.716    0.716
    regulasi          0.824    0.024   34.919    0.000    0.824    0.824
  permintaan ~~                                                         
    industri          0.729    0.035   20.581    0.000    0.729    0.729
    strategi          0.746    0.032   23.189    0.000    0.746    0.746
    regulasi          0.623    0.041   15.292    0.000    0.623    0.623
  industri ~~                                                           
    strategi          0.874    0.020   44.757    0.000    0.874    0.874
    regulasi          0.816    0.024   33.429    0.000    0.816    0.816
  strategi ~~                                                           
    regulasi          0.762    0.027   27.982    0.000    0.762    0.762

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .A1                0.353    0.032   11.133    0.000    0.353    0.549
   .A2                0.182    0.020    9.132    0.000    0.182    0.270
   .A3                0.192    0.022    8.905    0.000    0.192    0.253
   .A4                0.190    0.021    9.171    0.000    0.190    0.268
   .B1                0.270    0.032    8.454    0.000    0.270    0.339
   .B2                0.078    0.025    3.155    0.002    0.078    0.125
   .C1                0.123    0.014    8.573    0.000    0.123    0.205
   .C2                0.104    0.014    7.494    0.000    0.104    0.169
   .D1                0.093    0.011    8.748    0.000    0.093    0.151
   .D2                0.063    0.008    7.481    0.000    0.063    0.114
   .D3                0.182    0.017   10.624    0.000    0.182    0.270
   .D4                0.200    0.018   11.218    0.000    0.200    0.365
   .E1                0.145    0.014   10.565    0.000    0.145    0.211
   .E2                0.114    0.011   10.392    0.000    0.114    0.195
   .E3                0.157    0.014   10.844    0.000    0.157    0.242
   .E4                0.092    0.010    9.490    0.000    0.092    0.141
   .E5                0.132    0.013   10.456    0.000    0.132    0.201
   .E6                0.197    0.018   11.222    0.000    0.197    0.304
   .F1                0.140    0.014    9.700    0.000    0.140    0.190
   .F2                0.090    0.011    8.219    0.000    0.090    0.130
   .F3                0.140    0.015    9.538    0.000    0.140    0.181
   .F4                0.233    0.021   10.912    0.000    0.233    0.306
    faktor            1.000                               1.000    1.000
    permintaan        1.000                               1.000    1.000
    industri          1.000                               1.000    1.000
    strategi          1.000                               1.000    1.000
    regulasi          1.000                               1.000    1.000
   .kesempatan        1.000                               0.206    0.206

7.2.1 Visualisasi SEM

semPaths(sem.fit)

semPaths(sem.fit, "std", 
         color = list(lat = "green", man = "yellow"), 
         edge.color="black")

semPaths(sem.fit, "std", 
         color = list(lat = "green", man = "yellow"), 
         edge.color="black", fade=FALSE)

semPaths(sem.fit, "std", 
         color = list(lat = "green", man = "yellow"), 
         edge.color="black", 
         fade=FALSE, residuals=FALSE, exoCov=FALSE)

7.3 PLS SEM

# source:https://rpubs.com/ifn1411/PLS
# install plspm
#install.packages("plspm")
# load plspm
library(plspm)
# load data spainmodel
data(spainfoot)
# first 5 row of spainmodel data
head(spainfoot)
           GSH GSA  SSH  SSA GCH GCA  CSH  CSA WMH WMA LWR LRWL  YC RC
Barcelona   61  44 0.95 0.95  14  21 0.47 0.32  14  13  10   22  76  6
RealMadrid  49  34 1.00 0.84  29  23 0.37 0.37  14  11  10   18 115  9
Sevilla     28  26 0.74 0.74  20  19 0.42 0.53  11  10   4    7 100  8
AtleMadrid  47  33 0.95 0.84  23  34 0.37 0.16  13   7   6    9 116  5
Villarreal  33  28 0.84 0.68  25  29 0.26 0.16  12   6   5   11 102  5
Valencia    47  21 1.00 0.68  26  28 0.26 0.26  12   6   5    8 120  6
Attack <-  c(0, 0, 0)
Defense <- c(1, 0, 0)
Success <- c(1, 0, 0)

model_path <- rbind(Attack, Defense, Success)
colnames(model_path) <- rownames(model_path)

model_path
        Attack Defense Success
Attack       0       0       0
Defense      1       0       0
Success      1       0       0
# graph structural model
innerplot(model_path)

Attack <-  c(0, 1, 0)
Defense <- c(0, 0, 0)
Success <- c(1, 1, 0)

model_path2 <- rbind(Attack, Defense, Success)
colnames(model_path2) <- rownames(model_path2)

model_path2
        Attack Defense Success
Attack       0       1       0
Defense      0       0       0
Success      1       1       0
# graph structural model
innerplot(model_path2, txt.col = "black")

# define latent variable associated with
model_blocks <- list(1:4, 5:8, 9:12)

# vector of modes (reflective)
model_modes <- c("A", "A", "A")

# run plspm analysis
model_pls <- plspm(Data = spainfoot, path_matrix = model_path, blocks = model_blocks, modes = model_modes)

model_pls
Partial Least Squares Path Modeling (PLS-PM) 
---------------------------------------------
   NAME             DESCRIPTION
1  $outer_model     outer model
2  $inner_model     inner model
3  $path_coefs      path coefficients matrix
4  $scores          latent variable scores
5  $crossloadings   cross-loadings
6  $inner_summary   summary inner model
7  $effects         total effects
8  $unidim          unidimensionality
9  $gof             goodness-of-fit
10 $boot            bootstrap results
11 $data            data matrix
---------------------------------------------
You can also use the function 'summary' 
# Unidimensionality
model_pls$unidim
        Mode MVs   C.alpha     DG.rho  eig.1st   eig.2nd
Attack     A   4 0.8905919 0.92456079 3.017160 0.7923055
Defense    A   4 0.0000000 0.02601677 2.393442 1.1752781
Success    A   4 0.9165491 0.94232868 3.217294 0.5370492
plot(model_pls, what = "loadings")

# Loadings and Communilaties
model_pls$outer_model
   name   block     weight    loading communality redundancy
1   GSH  Attack  0.3474771  0.9412506   0.8859527 0.00000000
2   GSA  Attack  0.2671782  0.8562398   0.7331465 0.00000000
3   SSH  Attack  0.2922077  0.8466039   0.7167381 0.00000000
4   SSA  Attack  0.2396012  0.8212987   0.6745316 0.00000000
5   GCH Defense -0.1198790  0.4762965   0.2268583 0.05071506
6   GCA Defense -0.4264164  0.8885714   0.7895590 0.17650898
7   CSH Defense  0.2949470 -0.7297095   0.5324759 0.11903706
8   CSA Defense  0.3898039 -0.8947452   0.8005689 0.17897028
9   WMH Success  0.2484276  0.7884562   0.6216632 0.49452090
10  WMA Success  0.2691511  0.8747163   0.7651285 0.60864477
11  LWR Success  0.2947322  0.9703409   0.9415614 0.74899365
12 LRWL Success  0.2998524  0.9428112   0.8888929 0.70709694
# Crossloadings
model_pls$crossloadings
   name   block     Attack    Defense    Success
1   GSH  Attack  0.9412506 -0.5139001  0.9019257
2   GSA  Attack  0.8562398 -0.3403294  0.7483558
3   SSH  Attack  0.8466039 -0.4124617  0.7781795
4   SSA  Attack  0.8212987 -0.3455460  0.6308989
5   GCH Defense -0.1302683  0.4762965 -0.1620567
6   GCA Defense -0.4633220  0.8885714 -0.5640722
7   CSH Defense  0.3204993 -0.7297095  0.4850456
8   CSA Defense  0.4235465 -0.8947452  0.5811253
9   WMH Success  0.7126127 -0.4120502  0.7884562
10  WMA Success  0.7720228 -0.7147787  0.8747163
11  LWR Success  0.8454164 -0.5345709  0.9703409
12 LRWL Success  0.8600973 -0.5910943  0.9428112
# Coefficient of Determination
model_pls$inner_model
$Defense
               Estimate Std. Error       t value   Pr(>|t|)
Intercept  5.504973e-17  0.2076918  2.650549e-16 1.00000000
Attack    -4.728148e-01  0.2076918 -2.276521e+00 0.03526176

$Success
              Estimate Std. Error      t value     Pr(>|t|)
Intercept 7.783183e-17  0.1065936 7.301735e-16 1.000000e+00
Attack    8.918971e-01  0.1065936 8.367266e+00 1.285711e-07
# Redundancy
model_pls$inner_summary
              Type        R2 Block_Communality Mean_Redundancy       AVE
Attack   Exogenous 0.0000000         0.7525922       0.0000000 0.7525922
Defense Endogenous 0.2235539         0.5873656       0.1313078 0.5873656
Success Endogenous 0.7954804         0.8043115       0.6398141 0.8043115
# Goodness-of-fit
model_pls$gof
[1] 0.6034738
plot(model_pls, what = "inner", colpos = "#6890c4BB", colneg = "#f9675dBB", txt.col = "black", arr.tcol="black")