# Bayesian CFA of the RIASEC42            #

library(foreign)
library(plyr)
library(blavaan)
## Loading required package: Rcpp
## This is blavaan 0.5-3
## On multicore systems, we suggest use of future::plan("multicore") or
##   future::plan("multisession") for faster post-MCMC computations.
library(semTools)
## Loading required package: lavaan
## This is lavaan 0.6-17
## lavaan is FREE software! Please report any bugs.
## 
## ###############################################################################
## This is semTools 0.5-6
## All users of R (or SEM) are invited to submit functions or ideas for functions.
## ###############################################################################
library(rstan)
## Loading required package: StanHeaders
## 
## rstan version 2.32.6 (Stan version 2.32.2)
## For execution on a local, multicore CPU with excess RAM we recommend calling
## options(mc.cores = parallel::detectCores()).
## To avoid recompilation of unchanged Stan programs, we recommend calling
## rstan_options(auto_write = TRUE)
## For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
## change `threads_per_chain` option:
## rstan_options(threads_per_chain = 1)
## Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
library(ggplot2)
library(HDInterval)
library(mcmcse)
library(Rmpfr)
## Loading required package: gmp
## 
## Attaching package: 'gmp'
## The following objects are masked from 'package:base':
## 
##     %*%, apply, crossprod, matrix, tcrossprod
## C code of R package 'Rmpfr': GMP using 64 bits per limb
## 
## Attaching package: 'Rmpfr'
## The following object is masked from 'package:gmp':
## 
##     outer
## The following objects are masked from 'package:stats':
## 
##     dbinom, dgamma, dnbinom, dnorm, dpois, dt, pnorm
## The following objects are masked from 'package:base':
## 
##     cbind, pmax, pmin, rbind
library(scales)
library(gridExtra)
library(epiDisplay)
## Loading required package: survival
## Loading required package: MASS
## Loading required package: nnet
## 
## Attaching package: 'epiDisplay'
## The following object is masked from 'package:scales':
## 
##     alpha
## The following object is masked from 'package:ggplot2':
## 
##     alpha
## The following object is masked from 'package:rstan':
## 
##     lookup
library(bayesplot)
## This is bayesplot version 1.11.1
## - Online documentation and vignettes at mc-stan.org/bayesplot
## - bayesplot theme set to bayesplot::theme_default()
##    * Does _not_ affect other ggplot2 plots
##    * See ?bayesplot_theme_set for details on theme setting
library(Bayesrel)
RIASEC42 = read.csv2("D:\\OneDrive - UMP\\R - lenh 2016\\RIASEC1308.csv", comment.char="#", stringsAsFactors=T)
names(RIASEC42)
##  [1] "id"   "gioi" "lop"  "R1"   "R2"   "R3"   "R4"   "R5"   "R6"   "R7"  
## [11] "I1"   "I2"   "I3"   "I4"   "I5"   "I6"   "I7"   "A1"   "A2"   "A3"  
## [21] "A4"   "A5"   "A6"   "A7"   "S1"   "S2"   "S3"   "S4"   "S5"   "S6"  
## [31] "S7"   "E1"   "E2"   "E3"   "E4"   "E5"   "E6"   "E7"   "C1"   "C2"  
## [41] "C3"   "C4"   "C5"   "C6"   "C7"
# Định nghĩa mô hình SEM
mohinh.1 <- '
    R =~ R1 + R2 + R3 + R4 + R5 + R6 + R7
    I =~ I1 + I2 + I3 + I4 + I5 + I6 + I7
    A =~ A1 + A2 + A3 + A4 + A5 + S6 + A7
    S =~ S1 + S2 + S3 + S4 + S5 + S6 + S7
    E =~ E1 + E2 + E3 + E4 + E5 + E6 + E7
    C =~ C1 + C2 + C3 + C4 + C5 + C6 + C7 '
library(blcfa)
## Loading required package: stringr
## Loading required package: MCMCpack
## Loading required package: coda
## 
## Attaching package: 'coda'
## The following object is masked from 'package:rstan':
## 
##     traceplot
## ##
## ## Markov Chain Monte Carlo Package (MCMCpack)
## ## Copyright (C) 2003-2024 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park
## ##
## ## Support provided by the U.S. National Science Foundation
## ## (Grants SES-0350646 and SES-0350613)
## ##
## Loading required package: msm
## Loading required package: statmod
## Loading required package: psychometric
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
## 
##     select
## The following object is masked from 'package:gridExtra':
## 
##     combine
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: multilevel
## Loading required package: nlme
## 
## Attaching package: 'nlme'
## The following object is masked from 'package:dplyr':
## 
##     collapse
## Loading required package: purrr
## 
## Attaching package: 'purrr'
## The following object is masked from 'package:scales':
## 
##     discard
## The following object is masked from 'package:plyr':
## 
##     compact
## 
## Attaching package: 'psychometric'
## The following object is masked from 'package:epiDisplay':
## 
##     alpha
## The following object is masked from 'package:scales':
## 
##     alpha
## The following object is masked from 'package:ggplot2':
## 
##     alpha
## Loading required package: MplusAutomation
## Version:  1.1.1
## We work hard to write this free software. Please help us get credit by citing: 
## 
## Hallquist, M. N. & Wiley, J. F. (2018). MplusAutomation: An R Package for Facilitating Large-Scale Latent Variable Analyses in Mplus. Structural Equation Modeling, 25, 621-638. doi: 10.1080/10705511.2017.1402334.
## 
## -- see citation("MplusAutomation").
## Loading required package: sna
## Loading required package: statnet.common
## 
## Attaching package: 'statnet.common'
## The following objects are masked from 'package:base':
## 
##     attr, order
## Loading required package: network
## 
## 'network' 1.18.2 (2023-12-04), part of the Statnet Project
## * 'news(package="network")' for changes since last version
## * 'citation("network")' for citation information
## * 'https://statnet.org' for help, support, and other information
## 
## Attaching package: 'network'
## The following object is masked from 'package:plyr':
## 
##     is.discrete
## sna: Tools for Social Network Analysis
## Version 2.7-2 created on 2023-12-05.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
##  For citation information, type citation("sna").
##  Type help(package="sna") to get started.
## 
## Attaching package: 'sna'
## The following object is masked from 'package:nlme':
## 
##     gapply
## Loading required package: doParallel
## Loading required package: foreach
## 
## Attaching package: 'foreach'
## The following objects are masked from 'package:purrr':
## 
##     accumulate, when
## Loading required package: iterators
## Loading required package: parallel
## Loading required package: rstudioapi
fit.1 <- bcfa(
  model = mohinh.1,        # Mô hình SEM được định nghĩa trước
  data = RIASEC42,         # Dữ liệu đầu vào
  cp = "srs",               # Phương pháp chọn mẫu ("srs": Simple Random Sampling)
  n.chains = 1,             # Số lượng chuỗi lấy mẫu
  burnin = 100,              # Số lần lấy mẫu ban đầu bị bỏ qua
  sample = 1000,              # Số lượng lần lấy mẫu
  mcmcfile = TRUE,          # Lưu trữ kết quả MCMC vào tệp tin
  mcmcextra = list(),       # Thông số bổ sung cho MCMC
  inits = "simple",         # Cách khởi tạo (ở đây sử dụng cách khởi tạo đơn giản)
  convergence = "flexible", # Tiêu chí hội tụ (ở đây sử dụng cách kiểm tra hội tụ thủ công)
  seed = 12345,             # Seed cho quá trình ngẫu nhiên
  target = "stan",          # Phương pháp lấy mẫu từ Stan
  wiggle.sd = 0.1,          # Độ biến động cho phép
  prisamp = TRUE,           # Lấy mẫu đều từ các nhóm phụ
  jags.ic = TRUE,           # Sử dụng thông số tương quan từ JAGS
  test = "bootstrap"        # Phương pháp kiểm định (ở đây sử dụng kiểm định bootstrap)
)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0.007457 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 74.57 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1: 
## Chain 1: 
## Chain 1: WARNING: There aren't enough warmup iterations to fit the
## Chain 1:          three stages of adaptation as currently configured.
## Chain 1:          Reducing each adaptation stage to 15%/75%/10% of
## Chain 1:          the given number of warmup iterations:
## Chain 1:            init_buffer = 15
## Chain 1:            adapt_window = 75
## Chain 1:            term_buffer = 10
## Chain 1: 
## Chain 1: Iteration:    1 / 1100 [  0%]  (Warmup)
## Chain 1: Iteration:  101 / 1100 [  9%]  (Sampling)
## Chain 1: Iteration:  210 / 1100 [ 19%]  (Sampling)
## Chain 1: Iteration:  320 / 1100 [ 29%]  (Sampling)
## Chain 1: Iteration:  430 / 1100 [ 39%]  (Sampling)
## Chain 1: Iteration:  540 / 1100 [ 49%]  (Sampling)
## Chain 1: Iteration:  650 / 1100 [ 59%]  (Sampling)
## Chain 1: Iteration:  760 / 1100 [ 69%]  (Sampling)
## Chain 1: Iteration:  870 / 1100 [ 79%]  (Sampling)
## Chain 1: Iteration:  980 / 1100 [ 89%]  (Sampling)
## Chain 1: Iteration: 1090 / 1100 [ 99%]  (Sampling)
## Chain 1: Iteration: 1100 / 1100 [100%]  (Sampling)
## Chain 1: 
## Chain 1:  Elapsed Time: 122.876 seconds (Warm-up)
## Chain 1:                761.694 seconds (Sampling)
## Chain 1:                884.57 seconds (Total)
## Chain 1: 
## Computing post-estimation metrics (including lvs if requested)...

Hiển thị kết quả mô hình

summary(fit.1)                   # Hiển thị tổng quan về kết quả mô hình
## blavaan 0.5.3 ended normally after 1000 iterations
## 
##   Estimator                                      BAYES
##   Optimization method                             MCMC
##   Number of model parameters                        98
## 
##   Number of observations                          1308
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                     -112000.180       0.000
## 
## Parameter Estimates:
## 
## 
## Latent Variables:
##                    Estimate   Pri.SD pi.lower pi.upper     Rhat    Prior       
##   R =~                                                                         
##     R1                1.000    0.000                                           
##     R2                0.238    9.823  -19.806   18.812    1.000    normal(0,10)
##     R3               -0.193    9.644  -19.539   19.716    0.999    normal(0,10)
##     R4               -0.157    9.643  -18.468   19.228    0.999    normal(0,10)
##     R5                0.376   10.164  -19.807   20.579    0.999    normal(0,10)
##     R6                0.346    9.719  -18.632   18.094    0.999    normal(0,10)
##     R7               -0.087   10.203  -18.904   19.779    0.999    normal(0,10)
##   I =~                                                                         
##     I1                1.000    0.000                                           
##     I2                0.069    9.698  -19.300   19.184    0.999    normal(0,10)
##     I3               -0.314    9.541  -18.501   18.523    0.999    normal(0,10)
##     I4               -0.254   10.146  -19.743   19.282    0.999    normal(0,10)
##     I5                0.155    9.633  -17.967   19.415    1.001    normal(0,10)
##     I6                0.057   10.051  -20.546   18.788    0.999    normal(0,10)
##     I7               -0.187   10.422  -20.279   19.664    0.999    normal(0,10)
##   A =~                                                                         
##     A1                1.000    0.000                                           
##     A2               -0.065    9.860  -19.289   18.893    0.999    normal(0,10)
##     A3                0.100   10.074  -18.928   19.687    0.999    normal(0,10)
##     A4               -0.413   10.286  -21.059   19.543    0.999    normal(0,10)
##     A5                0.374    9.658  -19.217   19.712    0.999    normal(0,10)
##     S6               -0.505    9.519  -19.731   18.531    0.999    normal(0,10)
##     A7               -0.295   10.692  -22.597   20.582    0.999    normal(0,10)
##   S =~                                                                         
##     S1                1.000    0.000                                           
##     S2               -0.076    9.654  -18.766   19.516    1.000    normal(0,10)
##     S3                0.412    9.475  -19.302   19.038    0.999    normal(0,10)
##     S4               -0.414    9.466  -18.212   17.475    0.999    normal(0,10)
##     S5               -0.321   10.180  -20.108   20.925    1.000    normal(0,10)
##     S6                0.191   10.008  -20.324   20.277    1.001    normal(0,10)
##     S7                0.357    9.985  -18.815   20.474    0.999    normal(0,10)
##   E =~                                                                         
##     E1                1.000    0.000                                           
##     E2               -0.393   10.313  -19.958   20.268    0.999    normal(0,10)
##     E3               -0.424   10.570  -23.032   20.044    0.999    normal(0,10)
##     E4               -0.207    9.420  -19.284   18.471    0.999    normal(0,10)
##     E5               -0.657   10.150  -19.787   19.622    0.999    normal(0,10)
##     E6                0.058   10.592  -19.967   20.452    0.999    normal(0,10)
##     E7                0.147    9.225  -18.709   18.334    1.000    normal(0,10)
##   C =~                                                                         
##     C1                1.000    0.000                                           
##     C2               -0.128    9.906  -18.820   19.796    0.999    normal(0,10)
##     C3                0.071   10.200  -19.842   19.292    0.999    normal(0,10)
##     C4                0.356    9.684  -18.580   18.611    0.999    normal(0,10)
##     C5               -0.189    9.633  -20.128   18.707    0.999    normal(0,10)
##     C6                0.040    9.570  -18.754   19.166    0.999    normal(0,10)
##     C7                0.253    9.824  -19.870   19.938    0.999    normal(0,10)
## 
## Covariances:
##                    Estimate   Pri.SD pi.lower pi.upper     Rhat    Prior       
##   R ~~                                                                         
##     I                 0.055    2.581   -6.227    5.287    0.999     lkj_corr(1)
##     A                -0.051    3.425   -5.610    5.655    0.999     lkj_corr(1)
##     S                 0.051    3.124   -5.995    6.049    0.999     lkj_corr(1)
##     E                -0.116    3.060   -7.291    6.474    1.000     lkj_corr(1)
##     C                 0.076    3.818   -5.156    5.443    0.999     lkj_corr(1)
##   I ~~                                                                         
##     A                 0.074    3.116   -4.973    6.094    1.001     lkj_corr(1)
##     S                 0.030    2.595   -4.341    4.823    1.000     lkj_corr(1)
##     E                -0.143    3.054   -6.283    5.250    1.000     lkj_corr(1)
##     C                -0.063    2.668   -5.407    4.216    0.999     lkj_corr(1)
##   A ~~                                                                         
##     S                 0.040    2.933   -6.093    6.492    1.001     lkj_corr(1)
##     E                -0.100    3.335   -6.126    5.243    1.002     lkj_corr(1)
##     C                -0.004    3.025   -5.615    5.385    1.001     lkj_corr(1)
##   S ~~                                                                         
##     E                -0.009    3.095   -5.813    5.382    0.999     lkj_corr(1)
##     C                 0.057    3.100   -4.820    5.491    1.001     lkj_corr(1)
##   E ~~                                                                         
##     C                -0.047    3.114   -5.744    5.093    0.999     lkj_corr(1)
## 
## Variances:
##                    Estimate   Pri.SD pi.lower pi.upper     Rhat    Prior       
##    .R1                7.916   16.572    0.007   52.541    0.999 gamma(1,.5)[sd]
##    .R2                8.117   18.570    0.003   55.390    1.000 gamma(1,.5)[sd]
##    .R3                8.174   19.768    0.002   56.848    0.999 gamma(1,.5)[sd]
##    .R4                7.155   16.653    0.001   42.677    1.004 gamma(1,.5)[sd]
##    .R5                7.670   15.221    0.004   50.447    0.999 gamma(1,.5)[sd]
##    .R6                8.154   16.962    0.003   52.365    1.001 gamma(1,.5)[sd]
##    .R7                7.718   15.363    0.007   48.840    0.999 gamma(1,.5)[sd]
##    .I1                8.612   19.322    0.004   57.814    1.000 gamma(1,.5)[sd]
##    .I2                7.287   17.424    0.001   47.445    0.999 gamma(1,.5)[sd]
##    .I3                8.697   19.447    0.001   62.136    1.003 gamma(1,.5)[sd]
##    .I4                8.704   20.135    0.002   65.780    1.005 gamma(1,.5)[sd]
##    .I5                6.357   11.922    0.003   38.933    1.000 gamma(1,.5)[sd]
##    .I6                8.170   23.102    0.003   49.787    1.000 gamma(1,.5)[sd]
##    .I7                8.986   30.889    0.001   66.143    1.000 gamma(1,.5)[sd]
##    .A1                8.021   17.231    0.005   54.712    0.999 gamma(1,.5)[sd]
##    .A2                8.134   20.271    0.002   58.003    1.002 gamma(1,.5)[sd]
##    .A3                8.769   22.493    0.006   54.394    0.999 gamma(1,.5)[sd]
##    .A4                8.034   18.143    0.006   58.459    0.999 gamma(1,.5)[sd]
##    .A5                9.019   20.305    0.003   64.088    0.999 gamma(1,.5)[sd]
##    .S6                7.830   16.556    0.005   51.864    0.999 gamma(1,.5)[sd]
##    .A7                8.104   17.726    0.001   52.462    1.000 gamma(1,.5)[sd]
##    .S1                9.322   23.031    0.002   64.356    1.001 gamma(1,.5)[sd]
##    .S2                7.437   15.640    0.005   49.060    1.000 gamma(1,.5)[sd]
##    .S3                7.264   14.312    0.003   48.928    1.000 gamma(1,.5)[sd]
##    .S4                7.916   18.349    0.002   46.108    0.999 gamma(1,.5)[sd]
##    .S5                7.482   14.760    0.007   47.402    1.000 gamma(1,.5)[sd]
##    .S7                7.691   18.844    0.002   50.723    0.999 gamma(1,.5)[sd]
##    .E1                7.642   15.154    0.003   49.147    1.001 gamma(1,.5)[sd]
##    .E2                7.622   14.298    0.003   49.552    0.999 gamma(1,.5)[sd]
##    .E3                8.202   18.094    0.002   52.753    0.999 gamma(1,.5)[sd]
##    .E4                7.966   16.162    0.004   49.126    0.999 gamma(1,.5)[sd]
##    .E5                8.150   16.261    0.001   56.676    1.001 gamma(1,.5)[sd]
##    .E6                7.802   15.758    0.003   50.992    0.999 gamma(1,.5)[sd]
##    .E7                7.914   19.212    0.002   64.554    0.999 gamma(1,.5)[sd]
##    .C1                8.244   19.316    0.004   52.512    1.001 gamma(1,.5)[sd]
##    .C2                7.473   16.614    0.003   47.650    0.999 gamma(1,.5)[sd]
##    .C3                8.143   16.744    0.007   53.399    1.000 gamma(1,.5)[sd]
##    .C4                7.462   14.567    0.002   53.533    0.999 gamma(1,.5)[sd]
##    .C5                9.021   19.379    0.002   62.055    1.000 gamma(1,.5)[sd]
##    .C6                9.122   26.157    0.002   59.966    1.000 gamma(1,.5)[sd]
##    .C7                7.588   16.244    0.002   45.813    0.999 gamma(1,.5)[sd]
##     R                 9.318   22.174    0.002   58.778    0.999 gamma(1,.5)[sd]
##     I                 7.335   14.076    0.005   43.178    0.999 gamma(1,.5)[sd]
##     A                 8.199   17.759    0.004   58.152    1.001 gamma(1,.5)[sd]
##     S                 8.076   17.721    0.002   59.394    1.000 gamma(1,.5)[sd]
##     E                 8.128   15.767    0.005   51.536    0.999 gamma(1,.5)[sd]
##     C                 7.450   18.886    0.002   47.380    0.999 gamma(1,.5)[sd]
summary(fit.1, standardized = T)  # Hiển thị kết quả standardized (chuẩn hóa)
## blavaan 0.5.3 ended normally after 1000 iterations
## 
##   Estimator                                      BAYES
##   Optimization method                             MCMC
##   Number of model parameters                        98
## 
##   Number of observations                          1308
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                     -112000.180       0.000
## 
## Parameter Estimates:
## 
## 
## Latent Variables:
##                    Estimate   Pri.SD pi.lower pi.upper   Std.lv  Std.all
##   R =~                                                                  
##     R1                1.000    0.000                      3.053    0.735
##     R2                0.238    9.823  -19.806   18.812    0.726    0.247
##     R3               -0.193    9.644  -19.539   19.716   -0.588   -0.202
##     R4               -0.157    9.643  -18.468   19.228   -0.478   -0.176
##     R5                0.376   10.164  -19.807   20.579    1.148    0.383
##     R6                0.346    9.719  -18.632   18.094    1.057    0.347
##     R7               -0.087   10.203  -18.904   19.779   -0.265   -0.095
##   I =~                                                                  
##     I1                1.000    0.000                      2.708    0.678
##     I2                0.069    9.698  -19.300   19.184    0.186    0.069
##     I3               -0.314    9.541  -18.501   18.523   -0.849   -0.277
##     I4               -0.254   10.146  -19.743   19.282   -0.689   -0.227
##     I5                0.155    9.633  -17.967   19.415    0.421    0.165
##     I6                0.057   10.051  -20.546   18.788    0.155    0.054
##     I7               -0.187   10.422  -20.279   19.664   -0.507   -0.167
##   A =~                                                                  
##     A1                1.000    0.000                      2.863    0.711
##     A2               -0.065    9.860  -19.289   18.893   -0.185   -0.065
##     A3                0.100   10.074  -18.928   19.687    0.286    0.096
##     A4               -0.413   10.286  -21.059   19.543   -1.182   -0.385
##     A5                0.374    9.658  -19.217   19.712    1.070    0.335
##     S6               -0.505    9.519  -19.731   18.531   -1.445   -0.452
##     A7               -0.295   10.692  -22.597   20.582   -0.843   -0.284
##   S =~                                                                  
##     S1                1.000    0.000                      2.842    0.681
##     S2               -0.076    9.654  -18.766   19.516   -0.216   -0.079
##     S3                0.412    9.475  -19.302   19.038    1.171    0.398
##     S4               -0.414    9.466  -18.212   17.475   -1.177   -0.386
##     S5               -0.321   10.180  -20.108   20.925   -0.914   -0.317
##     S6                0.191   10.008  -20.324   20.277    0.542    0.170
##     S7                0.357    9.985  -18.815   20.474    1.014    0.344
##   E =~                                                                  
##     E1                1.000    0.000                      2.851    0.718
##     E2               -0.393   10.313  -19.958   20.268   -1.120   -0.376
##     E3               -0.424   10.570  -23.032   20.044   -1.210   -0.389
##     E4               -0.207    9.420  -19.284   18.471   -0.591   -0.205
##     E5               -0.657   10.150  -19.787   19.622   -1.872   -0.548
##     E6                0.058   10.592  -19.967   20.452    0.164    0.059
##     E7                0.147    9.225  -18.709   18.334    0.418    0.147
##   C =~                                                                  
##     C1                1.000    0.000                      2.729    0.689
##     C2               -0.128    9.906  -18.820   19.796   -0.348   -0.126
##     C3                0.071   10.200  -19.842   19.292    0.193    0.068
##     C4                0.356    9.684  -18.580   18.611    0.972    0.335
##     C5               -0.189    9.633  -20.128   18.707   -0.517   -0.170
##     C6                0.040    9.570  -18.754   19.166    0.108    0.036
##     C7                0.253    9.824  -19.870   19.938    0.691    0.243
##      Rhat    Prior       
##                          
##                          
##     1.000    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##                          
##                          
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     1.001    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##                          
##                          
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##                          
##                          
##     1.000    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     1.000    normal(0,10)
##     1.001    normal(0,10)
##     0.999    normal(0,10)
##                          
##                          
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     1.000    normal(0,10)
##                          
##                          
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
##     0.999    normal(0,10)
## 
## Covariances:
##                    Estimate   Pri.SD pi.lower pi.upper   Std.lv  Std.all
##   R ~~                                                                  
##     I                 0.055    2.581   -6.227    5.287    0.007    0.007
##     A                -0.051    3.425   -5.610    5.655   -0.006   -0.006
##     S                 0.051    3.124   -5.995    6.049    0.006    0.006
##     E                -0.116    3.060   -7.291    6.474   -0.013   -0.013
##     C                 0.076    3.818   -5.156    5.443    0.009    0.009
##   I ~~                                                                  
##     A                 0.074    3.116   -4.973    6.094    0.010    0.010
##     S                 0.030    2.595   -4.341    4.823    0.004    0.004
##     E                -0.143    3.054   -6.283    5.250   -0.018   -0.018
##     C                -0.063    2.668   -5.407    4.216   -0.009   -0.009
##   A ~~                                                                  
##     S                 0.040    2.933   -6.093    6.492    0.005    0.005
##     E                -0.100    3.335   -6.126    5.243   -0.012   -0.012
##     C                -0.004    3.025   -5.615    5.385   -0.001   -0.001
##   S ~~                                                                  
##     E                -0.009    3.095   -5.813    5.382   -0.001   -0.001
##     C                 0.057    3.100   -4.820    5.491    0.007    0.007
##   E ~~                                                                  
##     C                -0.047    3.114   -5.744    5.093   -0.006   -0.006
##      Rhat    Prior       
##                          
##     0.999     lkj_corr(1)
##     0.999     lkj_corr(1)
##     0.999     lkj_corr(1)
##     1.000     lkj_corr(1)
##     0.999     lkj_corr(1)
##                          
##     1.001     lkj_corr(1)
##     1.000     lkj_corr(1)
##     1.000     lkj_corr(1)
##     0.999     lkj_corr(1)
##                          
##     1.001     lkj_corr(1)
##     1.002     lkj_corr(1)
##     1.001     lkj_corr(1)
##                          
##     0.999     lkj_corr(1)
##     1.001     lkj_corr(1)
##                          
##     0.999     lkj_corr(1)
## 
## Variances:
##                    Estimate   Pri.SD pi.lower pi.upper   Std.lv  Std.all
##    .R1                7.916   16.572    0.007   52.541    7.916    0.459
##    .R2                8.117   18.570    0.003   55.390    8.117    0.939
##    .R3                8.174   19.768    0.002   56.848    8.174    0.959
##    .R4                7.155   16.653    0.001   42.677    7.155    0.969
##    .R5                7.670   15.221    0.004   50.447    7.670    0.853
##    .R6                8.154   16.962    0.003   52.365    8.154    0.880
##    .R7                7.718   15.363    0.007   48.840    7.718    0.991
##    .I1                8.612   19.322    0.004   57.814    8.612    0.540
##    .I2                7.287   17.424    0.001   47.445    7.287    0.995
##    .I3                8.697   19.447    0.001   62.136    8.697    0.923
##    .I4                8.704   20.135    0.002   65.780    8.704    0.948
##    .I5                6.357   11.922    0.003   38.933    6.357    0.973
##    .I6                8.170   23.102    0.003   49.787    8.170    0.997
##    .I7                8.986   30.889    0.001   66.143    8.986    0.972
##    .A1                8.021   17.231    0.005   54.712    8.021    0.495
##    .A2                8.134   20.271    0.002   58.003    8.134    0.996
##    .A3                8.769   22.493    0.006   54.394    8.769    0.991
##    .A4                8.034   18.143    0.006   58.459    8.034    0.852
##    .A5                9.019   20.305    0.003   64.088    9.019    0.887
##    .S6                7.830   16.556    0.005   51.864    7.830    0.767
##    .A7                8.104   17.726    0.001   52.462    8.104    0.919
##    .S1                9.322   23.031    0.002   64.356    9.322    0.536
##    .S2                7.437   15.640    0.005   49.060    7.437    0.994
##    .S3                7.264   14.312    0.003   48.928    7.264    0.841
##    .S4                7.916   18.349    0.002   46.108    7.916    0.851
##    .S5                7.482   14.760    0.007   47.402    7.482    0.900
##    .S7                7.691   18.844    0.002   50.723    7.691    0.882
##    .E1                7.642   15.154    0.003   49.147    7.642    0.485
##    .E2                7.622   14.298    0.003   49.552    7.622    0.859
##    .E3                8.202   18.094    0.002   52.753    8.202    0.849
##    .E4                7.966   16.162    0.004   49.126    7.966    0.958
##    .E5                8.150   16.261    0.001   56.676    8.150    0.699
##    .E6                7.802   15.758    0.003   50.992    7.802    0.997
##    .E7                7.914   19.212    0.002   64.554    7.914    0.978
##    .C1                8.244   19.316    0.004   52.512    8.244    0.525
##    .C2                7.473   16.614    0.003   47.650    7.473    0.984
##    .C3                8.143   16.744    0.007   53.399    8.143    0.995
##    .C4                7.462   14.567    0.002   53.533    7.462    0.888
##    .C5                9.021   19.379    0.002   62.055    9.021    0.971
##    .C6                9.122   26.157    0.002   59.966    9.122    0.999
##    .C7                7.588   16.244    0.002   45.813    7.588    0.941
##     R                 9.318   22.174    0.002   58.778    1.000    1.000
##     I                 7.335   14.076    0.005   43.178    1.000    1.000
##     A                 8.199   17.759    0.004   58.152    1.000    1.000
##     S                 8.076   17.721    0.002   59.394    1.000    1.000
##     E                 8.128   15.767    0.005   51.536    1.000    1.000
##     C                 7.450   18.886    0.002   47.380    1.000    1.000
##      Rhat    Prior       
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.005 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
library(semPlot)

semPaths(
  fit.1,                # Đối tượng mô hình SEM được sử dụng để vẽ đồ thị
  layout = "circle3",   # Bố cục của đồ thị ("tree2", "tree3", "circle2", "circle3", "user")
  whatLabels = "est",   # Loại nhãn được hiển thị trên đường dẫn ("est", "std", "none")
  intercepts = T,    # Cho phép hiển thị hệ số điều chỉnh
  residuals = T,     # Cho phép hiển thị các sai số
  intStyle = "rectangle", # Kiểu biểu tượng điều chỉnh ("ellipse", "triangle", "hexagon", "rectangle")
  exoCov = TRUE,        # Cho phép hiển thị hiệp phương sai của các biến endogenous
  rotation = 3,         # Góc quay của đồ thị
  edge.label.cex = 1, # Kích thước của nhãn trên các cạnh
  edge.label.color = "blue", # Màu của nhãn trên các cạnh
  edge.label.font =.3,  # Font của nhãn trên các cạnh
  curvePivot = T,    # Pivot curves around centroid
  curveAdjacent = T, # Góc cong của các đường dẫn kề nhau
)

mô hình 2 hiêp biến số

Fit mô hình

mohinh.2 <- c(paste0("R", 1:7, " ~~ R", 1:7), paste0("R", 1:7, " ~ 1"),
              paste0("I", 1:7, " ~~ I", 1:7), paste0("I", 1:7, " ~ 1"),
              paste0("A", 1:7, " ~~ A", 1:7), paste0("A", 1:7, " ~ 1"),
              paste0("S", 1:7, " ~~ S", 1:7), paste0("S", 1:7, " ~ 1"),
              paste0("E", 1:7, " ~~ E", 1:7), paste0("E", 1:7, " ~ 1"),
              paste0("C", 1:7, " ~~ C", 1:7), paste0("C", 1:7, " ~ 1"))
fit.2 <- bcfa(model = mohinh.2,        # Mô hình SEM được định nghĩa trước
  data = RIASEC42,         # Dữ liệu đầu vào
  cp = "srs",               # Phương pháp chọn mẫu ("srs": Simple Random Sampling)
  n.chains = 1,             # Số lượng chuỗi lấy mẫu
  burnin = 100,              # Số lần lấy mẫu ban đầu bị bỏ qua
  sample = 1000,              # Số lượng lần lấy mẫu
  mcmcfile = TRUE,          # Lưu trữ kết quả MCMC vào tệp tin
  mcmcextra = list(),       # Thông số bổ sung cho MCMC
  inits = "simple",         # Cách khởi tạo (ở đây sử dụng cách khởi tạo đơn giản)
  convergence="flexible",   # Tiêu chí hội tụ (ở đây sử dụng cách kiểm tra hội tụ thủ công)
  seed = 12345,             # Seed cho quá trình ngẫu nhiên
  target = "stan",          # Phương pháp lấy mẫu từ Stan
  wiggle.sd = 0.1,          # Độ biến động cho phép
  prisamp = TRUE,           # Lấy mẫu đều từ các nhóm phụ
  jags.ic = TRUE,           # Sử dụng thông số tương quan từ JAGS
  test = "bootstrap"        # Phương pháp kiểm định (ở đây sử dụng kiểm định bootstrap)
)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0.005344 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 53.44 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1: 
## Chain 1: 
## Chain 1: WARNING: There aren't enough warmup iterations to fit the
## Chain 1:          three stages of adaptation as currently configured.
## Chain 1:          Reducing each adaptation stage to 15%/75%/10% of
## Chain 1:          the given number of warmup iterations:
## Chain 1:            init_buffer = 15
## Chain 1:            adapt_window = 75
## Chain 1:            term_buffer = 10
## Chain 1: 
## Chain 1: Iteration:    1 / 1100 [  0%]  (Warmup)
## Chain 1: Iteration:  101 / 1100 [  9%]  (Sampling)
## Chain 1: Iteration:  210 / 1100 [ 19%]  (Sampling)
## Chain 1: Iteration:  320 / 1100 [ 29%]  (Sampling)
## Chain 1: Iteration:  430 / 1100 [ 39%]  (Sampling)
## Chain 1: Iteration:  540 / 1100 [ 49%]  (Sampling)
## Chain 1: Iteration:  650 / 1100 [ 59%]  (Sampling)
## Chain 1: Iteration:  760 / 1100 [ 69%]  (Sampling)
## Chain 1: Iteration:  870 / 1100 [ 79%]  (Sampling)
## Chain 1: Iteration:  980 / 1100 [ 89%]  (Sampling)
## Chain 1: Iteration: 1090 / 1100 [ 99%]  (Sampling)
## Chain 1: Iteration: 1100 / 1100 [100%]  (Sampling)
## Chain 1: 
## Chain 1:  Elapsed Time: 222.925 seconds (Warm-up)
## Chain 1:                2804.99 seconds (Sampling)
## Chain 1:                3027.92 seconds (Total)
## Chain 1:
## Warning in validityMethod(object): The following variables have undefined
## values: log_lik[1],The following variables have undefined values:
## log_lik[2],The following variables have undefined values: log_lik[3],The
## following variables have undefined values: log_lik[4],The following variables
## have undefined values: log_lik[5],The following variables have undefined
## values: log_lik[6],The following variables have undefined values:
## log_lik[7],The following variables have undefined values: log_lik[8],The
## following variables have undefined values: log_lik[9],The following variables
## have undefined values: log_lik[10],The following variables have undefined
## values: log_lik[11],The following variables have undefined values:
## log_lik[12],The following variables have undefined values: log_lik[13],The
## following variables have undefined values: log_lik[14],The following variables
## have undefined values: log_lik[15],The following variables have undefined
## values: log_lik[16],The following variables have undefined values:
## log_lik[17],The following variables have undefined values: log_lik[18],The
## following variables have undefined values: log_lik[19],The following variables
## have undefined values: log_lik[20],The following variables have undefined
## values: log_lik[21],The following variables have undefined values:
## log_lik[22],The following variables have undefined values: log_lik[23],The
## following variables have undefined values: log_lik[24],The following variables
## have undefined values: log_lik[25],The following variables have undefined
## values: log_lik[26],The following variables have undefined values:
## log_lik[27],The following variables have undefined values: log_lik[28],The
## following variables have undefined values: log_lik[29],The following variables
## have undefined values: log_lik[30],The following variables have undefined
## values: log_lik[31],The following variables have undefined values:
## log_lik[32],The following variables have undefined values: log_lik[33],The
## following variables have undefined values: log_lik[34],The following variables
## have undefined values: log_lik[35],The following variables have undefined
## values: log_lik[36],The following variables have undefined values:
## log_lik[37],The following variables have undefined values: log_lik[38],The
## following variables have undefined values: log_lik[39],The following variables
## have undefined values: log_lik[40],The following variables have undefined
## values: log_lik[41],The following variables have undefined values:
## log_lik[42],The following variables have undefined values: log_lik[43],The
## following variables have undefined values: log_lik[44],The following variables
## have undefined values: log_lik[45],The following variables have undefined
## values: log_lik[46],The following variables have undefined values:
## log_lik[47],The following variables have undefined values: log_lik[48],The
## following variables have undefined values: log_lik[49],The following variables
## have undefined values: log_lik[50],The following variables have undefined
## values: log_lik[51],The following variables have undefined values:
## log_lik[52],The following variables have undefined values: log_lik[53],The
## following variables have undefined values: log_lik[54],The following variables
## have undefined values: log_lik[55],The following variables have undefined
## values: log_lik[56],The following variables have undefined values:
## log_lik[57],The following variables have undefined values: log_lik[58],The
## following variables have undefined values: log_lik[59],The following variables
## have undefined values: log_lik[60],The following variables have undefined
## values: log_lik[61],The following variables have undefined values:
## log_lik[62],The following variables have undefined values: log_lik[63],The
## following variables have undefined values: log_lik[64],The following variables
## have undefined values: log_lik[65],The following variables have undefined
## values: log_lik[66],The following variables have undefined values:
## log_lik[67],The following variables have undefined values: log_lik[68],The
## following variables have undefined values: log_lik[69],The following variables
## have undefined values: log_lik[70],The following variables have undefined
## values: log_lik[71],The following variables have undefined values:
## log_lik[72],The following variables have undefined values: log_lik[73],The
## following variables have undefined values: log_lik[74],The following variables
## have undefined values: log_lik[75],The following variables have undefined
## values: log_lik[76],The following variables have undefined values:
## log_lik[77],The following variables have undefined values: log_lik[78],The
## following variables have undefined values: log_lik[79],The following variables
## have undefined values: log_lik[80],The following variables have undefined
## values: log_lik[81],The following variables have undefined values:
## log_lik[82],The following variables have undefined values: log_lik[83],The
## following variables have undefined values: log_lik[84],The following variables
## have undefined values: log_lik[85],The following variables have undefined
## values: log_lik[86],The following variables have undefined values:
## log_lik[87],The following variables have undefined values: log_lik[88],The
## following variables have undefined values: log_lik[89],The following variables
## have undefined values: log_lik[90],The following variables have undefined
## values: log_lik[91],The following variables have undefined values:
## log_lik[92],The following variables have undefined values: log_lik[93],The
## following variables have undefined values: log_lik[94],The following variables
## have undefined values: log_lik[95],The following variables have undefined
## values: log_lik[96],The following variables have undefined values:
## log_lik[97],The following variables have undefined values: log_lik[98],The
## following variables have undefined values: log_lik[99],The following variables
## have undefined values: log_lik[100],The following variables have undefined
## values: log_lik[101],The following variables have undefined values:
## log_lik[102],The following variables have undefined values: log_lik[103],The
## following variables have undefined values: log_lik[104],The following variables
## have undefined values: log_lik[105],The following variables have undefined
## values: log_lik[106],The following variables have undefined values:
## log_lik[107],The following variables have undefined values: log_lik[108],The
## following variables have undefined values: log_lik[109],The following variables
## have undefined values: log_lik[110],The following variables have undefined
## values: log_lik[111],The following variables have undefined values:
## log_lik[112],The following variables have undefined values: log_lik[113],The
## following variables have undefined values: log_lik[114],The following variables
## have undefined values: log_lik[115],The following variables have undefined
## values: log_lik[116],The following variables have undefined values:
## log_lik[117],The following variables have undefined values: log_lik[118],The
## following variables have undefined values: log_lik[119],The following variables
## have undefined values: log_lik[120],The following variables have undefined
## values: log_lik[121],The following variables have undefined values:
## log_lik[122],The following variables have undefined values: log_lik[123],The
## following variables have undefined values: log_lik[124],The following variables
## have undefined values: log_lik[125],The following variables have undefined
## values: log_lik[126],The following variables have undefined values:
## log_lik[127],The following variables have undefined values: log_lik[128],The
## following variables have undefined values: log_lik[129],The following variables
## have undefined values: log_lik[130],The following variables have undefined
## values: log_lik[131],The following variables have undefined values:
## log_lik[132],The following variables have undefined values: log_lik[133],The
## following variables have undefined values: log_lik[134],The following variables
## have undefined values: log_lik[135],The following variables have undefined
## values: log_lik[136],Th
## Computing post-estimation metrics (including lvs if requested)...

Hiển thị kết quả mô hình

summary(fit.2)   # Hiển thị tổng quan về kết quả mô hình
## blavaan 0.5.3 ended normally after 1000 iterations
## 
##   Estimator                                      BAYES
##   Optimization method                             MCMC
##   Number of model parameters                        84
## 
##   Number of observations                          1308
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                     -132232.297       1.000
## 
## Parameter Estimates:
## 
## 
## Intercepts:
##                    Estimate   Pri.SD pi.lower pi.upper     Rhat    Prior       
##     R1               -1.063   32.628  -61.995   63.410    0.999    normal(0,32)
##     R2               -0.657   32.964  -67.529   65.255    0.999    normal(0,32)
##     R3               -0.424   31.757  -57.857   63.731    1.000    normal(0,32)
##     R4                0.261   31.829  -62.359   61.608    1.000    normal(0,32)
##     R5               -0.862   33.151  -67.521   63.950    1.000    normal(0,32)
##     R6               -1.795   33.591  -70.305   62.876    0.999    normal(0,32)
##     R7                3.514   31.499  -59.742   64.656    0.999    normal(0,32)
##     I1                0.617   32.611  -62.326   65.504    1.001    normal(0,32)
##     I2                0.851   33.138  -63.501   64.477    1.000    normal(0,32)
##     I3                0.862   32.486  -60.564   66.650    1.000    normal(0,32)
##     I4                0.462   32.095  -61.927   67.962    1.000    normal(0,32)
##     I5                1.042   31.082  -59.461   61.317    0.999    normal(0,32)
##     I6                1.869   31.807  -61.999   64.056    1.000    normal(0,32)
##     I7                0.583   31.328  -63.555   59.255    1.001    normal(0,32)
##     A1               -0.561   31.282  -63.546   60.552    1.003    normal(0,32)
##     A2                1.474   31.074  -59.263   61.042    1.000    normal(0,32)
##     A3               -0.938   31.887  -62.854   58.912    1.000    normal(0,32)
##     A4               -0.591   33.214  -66.325   61.916    1.000    normal(0,32)
##     A5                0.176   33.469  -62.520   63.915    1.004    normal(0,32)
##     A6               -0.283   30.365  -59.096   59.322    1.004    normal(0,32)
##     A7               -1.285   32.003  -65.366   62.010    1.000    normal(0,32)
##     S1                0.621   33.110  -65.669   64.110    0.999    normal(0,32)
##     S2               -0.196   32.211  -61.040   64.220    0.999    normal(0,32)
##     S3               -1.554   30.332  -60.309   60.543    1.001    normal(0,32)
##     S4               -0.145   30.706  -60.627   59.787    0.999    normal(0,32)
##     S5                1.146   32.718  -62.937   67.499    0.999    normal(0,32)
##     S6                0.077   31.651  -67.503   62.157    1.001    normal(0,32)
##     S7                1.126   32.331  -64.840   65.354    0.999    normal(0,32)
##     E1               -0.265   32.176  -63.177   63.260    0.999    normal(0,32)
##     E2                0.659   32.802  -61.124   63.116    0.999    normal(0,32)
##     E3               -1.358   32.115  -64.996   60.666    1.000    normal(0,32)
##     E4                0.419   32.395  -61.457   67.093    1.000    normal(0,32)
##     E5                1.937   31.448  -59.076   65.302    1.000    normal(0,32)
##     E6               -0.608   31.568  -61.931   62.379    0.999    normal(0,32)
##     E7               -0.586   32.731  -65.141   61.871    0.999    normal(0,32)
##     C1               -0.062   33.289  -64.676   70.423    0.999    normal(0,32)
##     C2                0.750   32.485  -62.085   60.908    0.999    normal(0,32)
##     C3                0.356   30.944  -58.157   67.297    0.999    normal(0,32)
##     C4                1.074   32.009  -62.279   61.186    1.000    normal(0,32)
##     C5               -0.676   32.216  -64.071   65.797    0.999    normal(0,32)
##     C6                0.479   32.658  -65.222   61.289    0.999    normal(0,32)
##     C7                0.366   32.475  -59.641   66.944    1.000    normal(0,32)
## 
## Variances:
##                    Estimate   Pri.SD pi.lower pi.upper     Rhat    Prior       
##     R1                8.535   17.649    0.003   55.898    1.000 gamma(1,.5)[sd]
##     R2                8.026   20.280    0.001   54.374    0.999 gamma(1,.5)[sd]
##     R3                8.612   17.897    0.003   61.040    0.999 gamma(1,.5)[sd]
##     R4                8.124   17.739    0.001   60.906    0.999 gamma(1,.5)[sd]
##     R5                8.139   15.714    0.004   51.213    0.999 gamma(1,.5)[sd]
##     R6                8.947   22.519    0.003   56.093    0.999 gamma(1,.5)[sd]
##     R7                7.520   17.669    0.002   54.187    0.999 gamma(1,.5)[sd]
##     I1                8.190   18.881    0.002   57.174    0.999 gamma(1,.5)[sd]
##     I2                8.159   18.177    0.000   55.028    0.999 gamma(1,.5)[sd]
##     I3                8.704   18.567    0.003   59.654    1.001 gamma(1,.5)[sd]
##     I4                7.774   18.312    0.002   51.355    1.002 gamma(1,.5)[sd]
##     I5                7.522   18.542    0.003   45.879    1.002 gamma(1,.5)[sd]
##     I6                7.164   13.477    0.005   45.915    1.002 gamma(1,.5)[sd]
##     I7                7.078   14.527    0.004   47.641    1.000 gamma(1,.5)[sd]
##     A1                7.188   13.600    0.008   46.291    1.001 gamma(1,.5)[sd]
##     A2                7.755   16.147    0.001   55.504    1.001 gamma(1,.5)[sd]
##     A3                8.363   18.676    0.003   54.900    0.999 gamma(1,.5)[sd]
##     A4                7.823   19.737    0.006   45.249    1.004 gamma(1,.5)[sd]
##     A5                7.786   17.474    0.003   55.168    0.999 gamma(1,.5)[sd]
##     A6                8.741   18.941    0.001   64.071    1.000 gamma(1,.5)[sd]
##     A7                8.200   16.246    0.002   54.536    0.999 gamma(1,.5)[sd]
##     S1                8.257   19.561    0.004   51.439    1.000 gamma(1,.5)[sd]
##     S2                7.954   17.083    0.003   55.716    0.999 gamma(1,.5)[sd]
##     S3                8.398   21.490    0.003   57.394    1.000 gamma(1,.5)[sd]
##     S4                8.334   18.600    0.003   60.066    0.999 gamma(1,.5)[sd]
##     S5                7.714   15.856    0.005   51.891    1.000 gamma(1,.5)[sd]
##     S6                7.968   15.380    0.005   52.879    0.999 gamma(1,.5)[sd]
##     S7                7.198   14.575    0.001   50.974    0.999 gamma(1,.5)[sd]
##     E1                8.505   17.390    0.002   62.816    1.000 gamma(1,.5)[sd]
##     E2                7.973   19.187    0.003   55.760    1.000 gamma(1,.5)[sd]
##     E3                8.882   22.676    0.004   60.104    0.999 gamma(1,.5)[sd]
##     E4                8.801   19.789    0.003   60.890    0.999 gamma(1,.5)[sd]
##     E5                8.251   20.723    0.006   47.443    1.005 gamma(1,.5)[sd]
##     E6                7.027   14.215    0.004   48.989    1.002 gamma(1,.5)[sd]
##     E7                8.395   20.776    0.001   53.668    0.999 gamma(1,.5)[sd]
##     C1                8.183   16.779    0.003   57.600    1.000 gamma(1,.5)[sd]
##     C2                7.392   14.839    0.007   45.609    0.999 gamma(1,.5)[sd]
##     C3                7.499   15.759    0.005   42.769    0.999 gamma(1,.5)[sd]
##     C4                8.388   17.352    0.005   53.300    1.000 gamma(1,.5)[sd]
##     C5                6.859   16.281    0.002   46.117    0.999 gamma(1,.5)[sd]
##     C6                8.131   17.076    0.002   50.283    0.999 gamma(1,.5)[sd]
##     C7                9.000   19.880    0.001   62.447    0.999 gamma(1,.5)[sd]
summary(fit.2, standardized = TRUE)  # Hiển thị kết quả standardized (chuẩn hóa)
## blavaan 0.5.3 ended normally after 1000 iterations
## 
##   Estimator                                      BAYES
##   Optimization method                             MCMC
##   Number of model parameters                        84
## 
##   Number of observations                          1308
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                     -132232.297       1.000
## 
## Parameter Estimates:
## 
## 
## Intercepts:
##                    Estimate   Pri.SD pi.lower pi.upper   Std.lv  Std.all
##     R1               -1.063   32.628  -61.995   63.410   -1.063   -0.364
##     R2               -0.657   32.964  -67.529   65.255   -0.657   -0.232
##     R3               -0.424   31.757  -57.857   63.731   -0.424   -0.145
##     R4                0.261   31.829  -62.359   61.608    0.261    0.092
##     R5               -0.862   33.151  -67.521   63.950   -0.862   -0.302
##     R6               -1.795   33.591  -70.305   62.876   -1.795   -0.600
##     R7                3.514   31.499  -59.742   64.656    3.514    1.281
##     I1                0.617   32.611  -62.326   65.504    0.617    0.216
##     I2                0.851   33.138  -63.501   64.477    0.851    0.298
##     I3                0.862   32.486  -60.564   66.650    0.862    0.292
##     I4                0.462   32.095  -61.927   67.962    0.462    0.166
##     I5                1.042   31.082  -59.461   61.317    1.042    0.380
##     I6                1.869   31.807  -61.999   64.056    1.869    0.698
##     I7                0.583   31.328  -63.555   59.255    0.583    0.219
##     A1               -0.561   31.282  -63.546   60.552   -0.561   -0.209
##     A2                1.474   31.074  -59.263   61.042    1.474    0.529
##     A3               -0.938   31.887  -62.854   58.912   -0.938   -0.324
##     A4               -0.591   33.214  -66.325   61.916   -0.591   -0.211
##     A5                0.176   33.469  -62.520   63.915    0.176    0.063
##     A6               -0.283   30.365  -59.096   59.322   -0.283   -0.096
##     A7               -1.285   32.003  -65.366   62.010   -1.285   -0.449
##     S1                0.621   33.110  -65.669   64.110    0.621    0.216
##     S2               -0.196   32.211  -61.040   64.220   -0.196   -0.070
##     S3               -1.554   30.332  -60.309   60.543   -1.554   -0.536
##     S4               -0.145   30.706  -60.627   59.787   -0.145   -0.050
##     S5                1.146   32.718  -62.937   67.499    1.146    0.413
##     S6                0.077   31.651  -67.503   62.157    0.077    0.027
##     S7                1.126   32.331  -64.840   65.354    1.126    0.420
##     E1               -0.265   32.176  -63.177   63.260   -0.265   -0.091
##     E2                0.659   32.802  -61.124   63.116    0.659    0.233
##     E3               -1.358   32.115  -64.996   60.666   -1.358   -0.456
##     E4                0.419   32.395  -61.457   67.093    0.419    0.141
##     E5                1.937   31.448  -59.076   65.302    1.937    0.674
##     E6               -0.608   31.568  -61.931   62.379   -0.608   -0.229
##     E7               -0.586   32.731  -65.141   61.871   -0.586   -0.202
##     C1               -0.062   33.289  -64.676   70.423   -0.062   -0.022
##     C2                0.750   32.485  -62.085   60.908    0.750    0.276
##     C3                0.356   30.944  -58.157   67.297    0.356    0.130
##     C4                1.074   32.009  -62.279   61.186    1.074    0.371
##     C5               -0.676   32.216  -64.071   65.797   -0.676   -0.258
##     C6                0.479   32.658  -65.222   61.289    0.479    0.168
##     C7                0.366   32.475  -59.641   66.944    0.366    0.122
##      Rhat    Prior       
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     1.001    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     1.001    normal(0,32)
##     1.003    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.004    normal(0,32)
##     1.004    normal(0,32)
##     1.000    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     1.001    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     1.001    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     0.999    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
## 
## Variances:
##                    Estimate   Pri.SD pi.lower pi.upper   Std.lv  Std.all
##     R1                8.535   17.649    0.003   55.898    8.535    1.000
##     R2                8.026   20.280    0.001   54.374    8.026    1.000
##     R3                8.612   17.897    0.003   61.040    8.612    1.000
##     R4                8.124   17.739    0.001   60.906    8.124    1.000
##     R5                8.139   15.714    0.004   51.213    8.139    1.000
##     R6                8.947   22.519    0.003   56.093    8.947    1.000
##     R7                7.520   17.669    0.002   54.187    7.520    1.000
##     I1                8.190   18.881    0.002   57.174    8.190    1.000
##     I2                8.159   18.177    0.000   55.028    8.159    1.000
##     I3                8.704   18.567    0.003   59.654    8.704    1.000
##     I4                7.774   18.312    0.002   51.355    7.774    1.000
##     I5                7.522   18.542    0.003   45.879    7.522    1.000
##     I6                7.164   13.477    0.005   45.915    7.164    1.000
##     I7                7.078   14.527    0.004   47.641    7.078    1.000
##     A1                7.188   13.600    0.008   46.291    7.188    1.000
##     A2                7.755   16.147    0.001   55.504    7.755    1.000
##     A3                8.363   18.676    0.003   54.900    8.363    1.000
##     A4                7.823   19.737    0.006   45.249    7.823    1.000
##     A5                7.786   17.474    0.003   55.168    7.786    1.000
##     A6                8.741   18.941    0.001   64.071    8.741    1.000
##     A7                8.200   16.246    0.002   54.536    8.200    1.000
##     S1                8.257   19.561    0.004   51.439    8.257    1.000
##     S2                7.954   17.083    0.003   55.716    7.954    1.000
##     S3                8.398   21.490    0.003   57.394    8.398    1.000
##     S4                8.334   18.600    0.003   60.066    8.334    1.000
##     S5                7.714   15.856    0.005   51.891    7.714    1.000
##     S6                7.968   15.380    0.005   52.879    7.968    1.000
##     S7                7.198   14.575    0.001   50.974    7.198    1.000
##     E1                8.505   17.390    0.002   62.816    8.505    1.000
##     E2                7.973   19.187    0.003   55.760    7.973    1.000
##     E3                8.882   22.676    0.004   60.104    8.882    1.000
##     E4                8.801   19.789    0.003   60.890    8.801    1.000
##     E5                8.251   20.723    0.006   47.443    8.251    1.000
##     E6                7.027   14.215    0.004   48.989    7.027    1.000
##     E7                8.395   20.776    0.001   53.668    8.395    1.000
##     C1                8.183   16.779    0.003   57.600    8.183    1.000
##     C2                7.392   14.839    0.007   45.609    7.392    1.000
##     C3                7.499   15.759    0.005   42.769    7.499    1.000
##     C4                8.388   17.352    0.005   53.300    8.388    1.000
##     C5                6.859   16.281    0.002   46.117    6.859    1.000
##     C6                8.131   17.076    0.002   50.283    8.131    1.000
##     C7                9.000   19.880    0.001   62.447    9.000    1.000
##      Rhat    Prior       
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.005 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
library(semPlot)

semPaths(fit.2,
         whatLabels="est",
         layout = "tree",
          rotation = 3)

hết