Bayesian SEM

Author

Ty Partridge

setwd("C:/Work Files/Teaching/PSY 8170/Winter 2026/Class Exercises/Bayesian SEM")
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.0     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   4.0.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidybayes)
Warning: package 'tidybayes' was built under R version 4.5.3
library(psych)

Attaching package: 'psych'

The following objects are masked from 'package:ggplot2':

    %+%, alpha
library(knitr)
library(kableExtra)

Attaching package: 'kableExtra'

The following object is masked from 'package:dplyr':

    group_rows
library(blavaan)
Loading required package: Rcpp
This is blavaan 0.5-8
On multicore systems, we suggest use of future::plan("multicore") or
  future::plan("multisession") for faster post-MCMC computations.
library(loo)
Warning: package 'loo' was built under R version 4.5.3
This is loo version 2.9.0
- Online documentation and vignettes at mc-stan.org/loo
- As of v2.0.0 loo defaults to 1 core but we recommend using as many as possible. Use the 'cores' argument or set options(mc.cores = NUM_CORES) for an entire session. 
- Windows 10 users: loo may be very slow if 'mc.cores' is set in your .Rprofile file (see https://github.com/stan-dev/loo/issues/94).
library(corrplot)
corrplot 0.95 loaded
library(performance)
library(lavaan)
Warning: package 'lavaan' was built under R version 4.5.3
This is lavaan 0.6-21
lavaan is FREE software! Please report any bugs.

Attaching package: 'lavaan'

The following object is masked from 'package:psych':

    cor2cov
SEM_Data <- read.csv("HBAT example.csv") 

names(SEM_Data)
 [1] "id"  "JS1" "OC1" "OC2" "EP1" "OC3" "OC4" "EP2" "EP3" "AC1" "EP4" "JS2"
[13] "JS3" "AC2" "SI1" "JS4" "SI2" "JS5" "AC3" "SI3" "AC4" "SI4" "C1"  "C2" 
[25] "C3"  "AGE" "EXP" "JP"  "JS"  "OC"  "SI"  "EP"  "AC" 
colnames(SEM_Data)[1]<-"ID"
colnames(SEM_Data)[23]<-"Gender"
colnames(SEM_Data)[24]<-"Employee Type"
colnames(SEM_Data)[25]<-"Geographic Location"

str(SEM_Data)
'data.frame':   400 obs. of  33 variables:
 $ ID                 : int  1 2 3 4 5 6 7 8 9 10 ...
 $ JS1                : int  5 3 4 4 5 6 2 2 4 5 ...
 $ OC1                : int  3 0 6 7 2 5 6 4 9 5 ...
 $ OC2                : int  5 5 10 7 10 8 10 9 10 9 ...
 $ EP1                : int  10 10 10 10 10 8 9 10 8 10 ...
 $ OC3                : int  10 3 10 10 9 7 10 9 10 9 ...
 $ OC4                : int  10 7 10 7 9 7 9 7 10 10 ...
 $ EP2                : int  10 10 10 10 9 10 9 10 6 10 ...
 $ EP3                : int  5 10 10 9 10 7 9 10 8 8 ...
 $ AC1                : int  1 2 1 2 1 1 2 1 3 2 ...
 $ EP4                : int  NA 7 7 7 6 7 6 7 3 7 ...
 $ JS2                : int  4 4 2 5 4 6 3 2 5 3 ...
 $ JS3                : int  3 3 2 4 3 5 6 1 1 2 ...
 $ AC2                : int  2 1 4 1 1 2 4 1 4 4 ...
 $ SI1                : int  4 5 5 5 5 5 5 3 3 4 ...
 $ JS4                : int  3 2 3 2 2 3 4 1 1 2 ...
 $ SI2                : int  4 4 5 4 5 4 5 4 3 4 ...
 $ JS5                : int  23 43 60 33 58 62 11 21 80 33 ...
 $ AC3                : int  1 1 1 1 2 1 3 1 3 1 ...
 $ SI3                : int  3 4 5 3 3 3 5 4 2 3 ...
 $ AC4                : int  1 1 2 1 2 1 3 3 1 4 ...
 $ SI4                : int  3 4 5 4 4 3 4 2 2 3 ...
 $ Gender             : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Employee Type      : int  0 1 1 0 1 0 1 1 0 0 ...
 $ Geographic Location: int  1 1 1 1 1 1 1 1 1 1 ...
 $ AGE                : int  42 32 43 26 37 35 44 50 27 47 ...
 $ EXP                : num  6 5.8 1 3 14 8 12.5 0.2 0.3 5.3 ...
 $ JP                 : int  5 4 5 5 5 4 5 5 4 5 ...
 $ JS                 : num  -0.22499 -0.55478 -0.51594 -0.13101 0.00117 ...
 $ OC                 : num  -0.364 -1.661 0.781 -0.33 0.321 ...
 $ SI                 : num  -0.37 0.388 1.281 0.222 0.641 ...
 $ EP                 : num  NA 0.868 0.868 0.659 0.435 ...
 $ AC                 : num  -1.295 -1.257 -0.827 -1.257 -1.086 ...
SEM_Data = SEM_Data %>% mutate(across(.cols=2:22, .fns=as.numeric))

SEM_Data$Gender<-factor(SEM_Data$Gender,
                        levels = c(0,1),
                        labels = c("Male", "Female"))

SEM_Data$`Employee Type`<-factor(SEM_Data$`Employee Type`,
                        levels = c(0,1),
                        labels = c("Part-Time", "Full-Time"))

SEM_Data$`Geographic Location`<-factor(SEM_Data$`Geographic Location`,
                                 levels = c(0,1),
                                 labels = c("Non-USA", "USA"))

describe(SEM_Data[,-1])
                     vars   n  mean    sd median trimmed   mad   min    max
JS1                     1 400  4.20  1.34   4.00    4.22  1.48  1.00   7.00
OC1                     2 400  4.89  2.53   5.00    4.92  2.97  0.00  10.00
OC2                     3 400  8.42  2.19   9.00    8.89  1.48  0.00  10.00
EP1                     4 400  8.53  1.83   9.00    8.85  1.48  0.00  10.00
OC3                     5 400  8.65  1.75   9.00    8.99  1.48  0.00  10.00
OC4                     6 400  8.40  2.05   9.00    8.83  1.48  0.00  10.00
EP2                     7 400  8.85  1.63   9.00    9.17  1.48  0.00  10.00
EP3                     8 400  8.93  1.33   9.00    9.16  1.48  0.00  10.00
AC1                     9 400  2.76  1.39   3.00    2.70  1.48  1.00   5.00
EP4                    10 399  5.83  1.39   6.00    6.06  1.48  1.00   7.00
JS2                    11 400  4.20  1.37   4.00    4.22  1.48  1.00   7.00
JS3                    12 400  3.21  1.32   3.00    3.22  1.48  1.00   6.00
AC2                    13 400  3.55  1.73   4.00    3.57  1.48  1.00   6.00
SI1                    14 400  4.20  0.87   4.00    4.33  1.48  1.00   5.00
JS4                    15 400  2.67  1.28   3.00    2.58  1.48  1.00   5.00
SI2                    16 400  4.20  0.88   4.00    4.33  1.48  1.00   5.00
JS5                    17 400 54.82 20.59  55.50   54.83 22.98  0.00 100.00
AC3                    18 400  2.78  1.42   3.00    2.72  1.48  1.00   5.00
SI3                    19 400  3.47  1.02   3.00    3.50  1.48  1.00   5.00
AC4                    20 399  3.21  1.61   3.00    3.14  1.48  1.00   6.00
SI4                    21 400  3.48  0.97   4.00    3.52  1.48  1.00   5.00
Gender*                22 400  1.50  0.50   1.50    1.50  0.74  1.00   2.00
Employee Type*         23 400  1.52  0.50   2.00    1.53  0.00  1.00   2.00
Geographic Location*   24 400  1.50  0.50   1.50    1.50  0.74  1.00   2.00
AGE                    25 399 43.38  7.14  43.00   43.36  7.41 24.00  62.00
EXP                    26 399  8.64  3.62   8.60    8.68  3.56  0.10  25.00
JP                     27 399  4.36  0.97   5.00    4.54  0.00  1.00   5.00
JS                     28 400  0.00  0.92  -0.03   -0.01  0.96 -2.36   2.40
OC                     29 400  0.00  0.93   0.27    0.16  0.76 -4.22   0.97
SI                     30 400  0.00  0.95   0.10    0.10  0.83 -3.43   1.28
EP                     31 399  0.00  0.93   0.13    0.15  1.09 -4.29   0.87
AC                     32 399  0.00  0.95  -0.06   -0.02  1.27 -1.45   1.71
                      range  skew kurtosis   se
JS1                    6.00 -0.09    -0.21 0.07
OC1                   10.00 -0.13    -0.72 0.13
OC2                   10.00 -2.07     4.52 0.11
EP1                   10.00 -1.98     5.35 0.09
OC3                   10.00 -2.03     5.24 0.09
OC4                   10.00 -1.97     4.29 0.10
EP2                   10.00 -2.11     5.71 0.08
EP3                   10.00 -1.81     5.39 0.07
AC1                    4.00  0.22    -1.22 0.07
EP4                    6.00 -1.28     1.30 0.07
JS2                    6.00 -0.03    -0.19 0.07
JS3                    5.00  0.11    -0.69 0.07
AC2                    5.00 -0.07    -1.32 0.09
SI1                    4.00 -1.31     2.10 0.04
JS4                    4.00  0.30    -0.97 0.06
SI2                    4.00 -1.25     1.84 0.04
JS5                  100.00 -0.02    -0.66 1.03
AC3                    4.00  0.21    -1.25 0.07
SI3                    4.00  0.00    -0.55 0.05
AC4                    5.00  0.17    -1.11 0.08
SI4                    4.00 -0.48     0.00 0.05
Gender*                1.00  0.00    -2.00 0.03
Employee Type*         1.00 -0.09    -2.00 0.03
Geographic Location*   1.00  0.00    -2.00 0.03
AGE                   38.00  0.02    -0.26 0.36
EXP                   24.90  0.10     0.86 0.18
JP                     4.00 -1.33     0.69 0.05
JS                     4.76  0.09    -0.39 0.05
OC                     5.19 -1.73     3.53 0.05
SI                     4.71 -1.06     1.41 0.05
EP                     5.15 -1.39     2.09 0.05
AC                     3.16  0.13    -1.25 0.05
describe(SEM_Data[,-1])%>%
  knitr::kable(digits = 3, format="html", booktabs=TRUE, caption="Table 1. Example Descriptives")%>%
  kable_classic(full_width = F, html_font = "Cambria")
Table 1. Example Descriptives
vars n mean sd median trimmed mad min max range skew kurtosis se
JS1 1 400 4.197 1.339 4.000 4.216 1.483 1.000 7.000 6.000 -0.087 -0.215 0.067
OC1 2 400 4.888 2.525 5.000 4.922 2.965 0.000 10.000 10.000 -0.130 -0.723 0.126
OC2 3 400 8.418 2.186 9.000 8.887 1.483 0.000 10.000 10.000 -2.067 4.519 0.109
EP1 4 400 8.528 1.831 9.000 8.853 1.483 0.000 10.000 10.000 -1.983 5.354 0.092
OC3 5 400 8.655 1.755 9.000 8.991 1.483 0.000 10.000 10.000 -2.031 5.239 0.088
OC4 6 400 8.405 2.053 9.000 8.828 1.483 0.000 10.000 10.000 -1.973 4.294 0.103
EP2 7 400 8.848 1.628 9.000 9.169 1.483 0.000 10.000 10.000 -2.111 5.706 0.081
EP3 8 400 8.928 1.335 9.000 9.159 1.483 0.000 10.000 10.000 -1.810 5.391 0.067
AC1 9 400 2.760 1.394 3.000 2.700 1.483 1.000 5.000 4.000 0.216 -1.221 0.070
EP4 10 399 5.830 1.395 6.000 6.056 1.483 1.000 7.000 6.000 -1.280 1.301 0.070
JS2 11 400 4.202 1.370 4.000 4.219 1.483 1.000 7.000 6.000 -0.034 -0.190 0.068
JS3 12 400 3.215 1.316 3.000 3.216 1.483 1.000 6.000 5.000 0.107 -0.692 0.066
AC2 13 400 3.553 1.726 4.000 3.566 1.483 1.000 6.000 5.000 -0.070 -1.324 0.086
SI1 14 400 4.202 0.871 4.000 4.334 1.483 1.000 5.000 4.000 -1.310 2.095 0.044
JS4 15 400 2.668 1.281 3.000 2.584 1.483 1.000 5.000 4.000 0.301 -0.965 0.064
SI2 16 400 4.205 0.877 4.000 4.331 1.483 1.000 5.000 4.000 -1.252 1.839 0.044
JS5 17 400 54.818 20.594 55.500 54.834 22.980 0.000 100.000 100.000 -0.023 -0.658 1.030
AC3 18 400 2.775 1.419 3.000 2.719 1.483 1.000 5.000 4.000 0.206 -1.249 0.071
SI3 19 400 3.473 1.016 3.000 3.497 1.483 1.000 5.000 4.000 0.003 -0.550 0.051
AC4 20 399 3.211 1.612 3.000 3.140 1.483 1.000 6.000 5.000 0.171 -1.113 0.081
SI4 21 400 3.480 0.968 4.000 3.522 1.483 1.000 5.000 4.000 -0.481 0.005 0.048
Gender* 22 400 1.500 0.501 1.500 1.500 0.741 1.000 2.000 1.000 0.000 -2.005 0.025
Employee Type* 23 400 1.522 0.500 2.000 1.528 0.000 1.000 2.000 1.000 -0.090 -1.997 0.025
Geographic Location* 24 400 1.500 0.501 1.500 1.500 0.741 1.000 2.000 1.000 0.000 -2.005 0.025
AGE 25 399 43.383 7.138 43.000 43.364 7.413 24.000 62.000 38.000 0.019 -0.256 0.357
EXP 26 399 8.639 3.620 8.600 8.683 3.558 0.100 25.000 24.900 0.097 0.856 0.181
JP 27 399 4.358 0.974 5.000 4.536 0.000 1.000 5.000 4.000 -1.332 0.695 0.049
JS 28 400 0.000 0.920 -0.026 -0.010 0.964 -2.358 2.402 4.759 0.093 -0.393 0.046
OC 29 400 0.000 0.934 0.268 0.160 0.760 -4.218 0.969 5.187 -1.729 3.528 0.047
SI 30 400 0.000 0.947 0.104 0.096 0.831 -3.426 1.281 4.708 -1.055 1.410 0.047
EP 31 399 0.000 0.932 0.130 0.148 1.094 -4.286 0.868 5.154 -1.392 2.091 0.047
AC 32 399 0.000 0.946 -0.062 -0.019 1.267 -1.450 1.712 3.162 0.130 -1.253 0.047
#JS = Job Satisfaction
#OC = Organizational Commitment
#EP = Environmental Support
#AC = Attitude Toward Co-Workers
#SI = Stay Intention 

#All variables coded with higher scores indicating higher levels of the construct

SEM_Data_NM <- na.omit(SEM_Data)
dpriors()
               nu             alpha            lambda              beta 
   "normal(0,32)"    "normal(0,10)"    "normal(0,10)"    "normal(0,10)" 
            theta               psi               rho             ibpsi 
"gamma(1,.5)[sd]" "gamma(1,.5)[sd]"       "beta(1,1)" "wishart(3,iden)" 
              tau 
  "normal(0,1.5)" 
Parameter Meaning Default Prior
nu Observed intercepts Normal(0, 32)
alpha Latent intercepts Normal(0, 10)
lambda Factor loadings Normal(0, 10)
beta Regression paths Normal(0, 10)
theta Residual variances (observed) Gamma(1, 0.5)
psi Residual variances (latent) Gamma(1, 0.5)
rho Correlations Beta(1, 1)
ibpsi Latent covariance matrix Wishart
tau Thresholds (ordinal only) Normal(0, 1.5)
BayesM1 <- '
  Env_Supp =~ EP1 + EP2 + EP3 + EP4
  Att_Cowrk =~ AC1 + AC2 + AC3 + AC4
  Org_Comm =~ OC1 + OC2 + OC3 + OC4
  Job_Sat =~ JS1 + JS2 + JS3 + JS4 
  Stay_Int =~ SI1 + SI2 + SI3 + SI4
  
  Job_Sat ~ Env_Supp + Att_Cowrk + Org_Comm
  Stay_Int ~ Env_Supp + Att_Cowrk + Org_Comm + Job_Sat
  
  Env_Supp ~~ Att_Cowrk
  Env_Supp ~~ Org_Comm
  Att_Cowrk ~~ Org_Comm
'

B_fit1 <- bsem(BayesM1, data = SEM_Data_NM)

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.00371 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 37.1 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 1: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 1: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 1: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 1: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 1: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 1: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 1: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 1: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 1: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 1: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 1: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 18.521 seconds (Warm-up)
Chain 1:                10.625 seconds (Sampling)
Chain 1:                29.146 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 0.000927 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 9.27 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 2: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 2: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 2: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 2: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 2: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 2: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 2: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 2: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 2: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 2: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 2: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 6.171 seconds (Warm-up)
Chain 2:                10.202 seconds (Sampling)
Chain 2:                16.373 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 0.000617 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 6.17 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 3: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 3: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 3: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 3: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 3: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 3: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 3: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 3: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 3: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 3: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 3: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 5.738 seconds (Warm-up)
Chain 3:                10.654 seconds (Sampling)
Chain 3:                16.392 seconds (Total)
Chain 3: 
Computing post-estimation metrics (including lvs if requested)...
summary(B_fit1, standardized = TRUE, fit.measures = TRUE, rsquare = TRUE)
blavaan 0.5.8 ended normally after 1000 iterations

  Estimator                                      BAYES
  Optimization method                             MCMC
  Number of model parameters                        50

  Number of observations                           398

  Statistic                                 MargLogLik         PPP
  Value                                     -12377.126       0.021

Parameter Estimates:


Latent Variables:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Env_Supp =~                                                           
    EP1               1.000                               1.261    0.690
    EP2               1.059    0.076    0.920    1.216    1.335    0.814
    EP3               0.823    0.062    0.710    0.952    1.038    0.780
    EP4               0.918    0.066    0.797    1.055    1.157    0.823
  Att_Cowrk =~                                                          
    AC1               1.000                               1.141    0.819
    AC2               1.248    0.070    1.119    1.388    1.424    0.821
    AC3               1.046    0.057    0.939    1.160    1.194    0.837
    AC4               1.155    0.065    1.032    1.287    1.318    0.815
  Org_Comm =~                                                           
    OC1               1.000                               1.432    0.570
    OC2               1.370    0.121    1.167    1.636    1.963    0.889
    OC3               0.816    0.084    0.666    0.999    1.169    0.661
    OC4               1.218    0.109    1.027    1.462    1.745    0.841
  Job_Sat =~                                                            
    JS1               1.000                               0.987    0.735
    JS2               1.036    0.084    0.886    1.213    1.022    0.741
    JS3               0.936    0.081    0.791    1.107    0.924    0.697
    JS4               0.927    0.080    0.778    1.094    0.915    0.709
  Stay_Int =~                                                           
    SI1               1.000                               0.713    0.812
    SI2               1.074    0.055    0.971    1.186    0.765    0.865
    SI3               1.065    0.067    0.935    1.203    0.759    0.742
    SI4               1.169    0.063    1.054    1.304    0.833    0.853
     Rhat    Prior       
                         
                         
    1.000    normal(0,10)
    1.000    normal(0,10)
    0.999    normal(0,10)
                         
                         
    1.001    normal(0,10)
    0.999    normal(0,10)
    1.001    normal(0,10)
                         
                         
    1.000    normal(0,10)
    1.000    normal(0,10)
    1.000    normal(0,10)
                         
                         
    1.000    normal(0,10)
    1.000    normal(0,10)
    1.000    normal(0,10)
                         
                         
    1.000    normal(0,10)
    1.000    normal(0,10)
    1.000    normal(0,10)

Regressions:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Job_Sat ~                                                             
    Env_Supp          0.147    0.056    0.036    0.257    0.187    0.187
    Att_Cowrk        -0.048    0.053   -0.148    0.055   -0.055   -0.055
    Org_Comm          0.078    0.050   -0.019    0.177    0.114    0.114
  Stay_Int ~                                                            
    Env_Supp          0.199    0.036    0.132    0.271    0.353    0.353
    Att_Cowrk         0.073    0.031    0.012    0.135    0.117    0.117
    Org_Comm          0.164    0.032    0.104    0.230    0.330    0.330
    Job_Sat           0.049    0.036   -0.021    0.118    0.067    0.067
     Rhat    Prior       
                         
    1.000    normal(0,10)
    0.999    normal(0,10)
    0.999    normal(0,10)
                         
    1.000    normal(0,10)
    0.999    normal(0,10)
    1.000    normal(0,10)
    0.999    normal(0,10)

Covariances:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Env_Supp ~~                                                           
    Att_Cowrk         0.358    0.088    0.193    0.540    0.249    0.249
    Org_Comm          0.884    0.143    0.629    1.187    0.490    0.490
  Att_Cowrk ~~                                                          
    Org_Comm          0.491    0.105    0.299    0.708    0.300    0.300
     Rhat    Prior       
                         
    1.000     lkj_corr(1)
    0.999     lkj_corr(1)
                         
    1.000     lkj_corr(1)

Variances:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
   .EP1               1.747    0.150    1.476    2.049    1.747    0.524
   .EP2               0.910    0.095    0.738    1.103    0.910    0.338
   .EP3               0.693    0.065    0.576    0.824    0.693    0.391
   .EP4               0.636    0.067    0.511    0.778    0.636    0.322
   .AC1               0.640    0.061    0.525    0.766    0.640    0.330
   .AC2               0.985    0.092    0.814    1.177    0.985    0.327
   .AC3               0.609    0.063    0.493    0.740    0.609    0.299
   .AC4               0.881    0.083    0.726    1.059    0.881    0.336
   .OC1               4.263    0.323    3.667    4.939    4.263    0.675
   .OC2               1.017    0.157    0.728    1.317    1.017    0.209
   .OC3               1.763    0.143    1.507    2.061    1.763    0.563
   .OC4               1.258    0.141    0.991    1.543    1.258    0.292
   .JS1               0.828    0.082    0.681    0.996    0.828    0.460
   .JS2               0.861    0.087    0.700    1.049    0.861    0.452
   .JS3               0.901    0.081    0.755    1.069    0.901    0.514
   .JS4               0.829    0.078    0.684    0.993    0.829    0.498
   .SI1               0.263    0.024    0.217    0.312    0.263    0.341
   .SI2               0.198    0.021    0.158    0.240    0.198    0.252
   .SI3               0.471    0.039    0.398    0.553    0.471    0.450
   .SI4               0.260    0.027    0.210    0.319    0.260    0.272
    Env_Supp          1.589    0.217    1.187    2.038    1.000    1.000
    Att_Cowrk         1.302    0.136    1.053    1.584    1.000    1.000
    Org_Comm          2.051    0.358    1.386    2.794    1.000    1.000
   .Job_Sat           0.913    0.124    0.681    1.173    0.937    0.937
   .Stay_Int          0.290    0.033    0.229    0.359    0.571    0.571
     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]
    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]
    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]
    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]
    1.000 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]

R-Square:
                   Estimate
    EP1               0.476
    EP2               0.662
    EP3               0.609
    EP4               0.678
    AC1               0.670
    AC2               0.673
    AC3               0.701
    AC4               0.664
    OC1               0.325
    OC2               0.791
    OC3               0.437
    OC4               0.708
    JS1               0.540
    JS2               0.548
    JS3               0.486
    JS4               0.502
    SI1               0.659
    SI2               0.748
    SI3               0.550
    SI4               0.728
    Job_Sat           0.063
    Stay_Int          0.429
plot(B_fit1, pars = 16:22, plot.type = "trace")

plot(B_fit1, pars = 16:22, plot.type = "intervals")

BayesM2 <- '
  Env_Supp =~ EP1 + prior("normal(0,1)")*EP2 + EP3 + EP4
  Att_Cowrk =~ AC1 + AC2 + AC3 + AC4
  Org_Comm =~ OC1 + OC2 + OC3 + OC4
  Job_Sat =~ JS1 + JS2 + JS3 + JS4 
  Stay_Int =~ SI1 + SI2 + SI3 + SI4
  
  Job_Sat ~ Env_Supp + prior("normal(0.3,0.1)")*Att_Cowrk + Org_Comm
  Stay_Int ~ Env_Supp + Att_Cowrk + Org_Comm + prior("normal(0.5,0.1)")*Job_Sat
  
  Env_Supp ~~ Att_Cowrk
  Env_Supp ~~ Org_Comm
  Att_Cowrk ~~ Org_Comm
'

B_fit2 <- bsem(BayesM2, data = SEM_Data_NM)

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000613 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 6.13 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 1: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 1: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 1: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 1: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 1: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 1: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 1: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 1: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 1: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 1: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 1: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 6.251 seconds (Warm-up)
Chain 1:                10.36 seconds (Sampling)
Chain 1:                16.611 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 0.000526 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 5.26 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 2: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 2: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 2: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 2: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 2: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 2: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 2: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 2: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 2: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 2: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 2: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 5.941 seconds (Warm-up)
Chain 2:                10.244 seconds (Sampling)
Chain 2:                16.185 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 0.000521 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 5.21 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 3: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 3: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 3: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 3: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 3: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 3: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 3: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 3: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 3: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 3: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 3: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 6.039 seconds (Warm-up)
Chain 3:                9.921 seconds (Sampling)
Chain 3:                15.96 seconds (Total)
Chain 3: 
Computing post-estimation metrics (including lvs if requested)...
summary(B_fit2, standardized = TRUE, fit.measures = TRUE, rsquare = TRUE)
blavaan 0.5.8 ended normally after 1000 iterations

  Estimator                                      BAYES
  Optimization method                             MCMC
  Number of model parameters                        50

  Number of observations                           398

  Statistic                                 MargLogLik         PPP
  Value                                     -12380.061       0.012

Parameter Estimates:


Latent Variables:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Env_Supp =~                                                           
    EP1               1.000                               1.267    0.692
    EP2               1.052    0.072    0.921    1.201    1.333    0.813
    EP3               0.820    0.061    0.707    0.943    1.039    0.781
    EP4               0.914    0.063    0.799    1.044    1.158    0.824
  Att_Cowrk =~                                                          
    AC1               1.000                               1.139    0.818
    AC2               1.251    0.072    1.116    1.400    1.425    0.820
    AC3               1.048    0.058    0.936    1.165    1.193    0.837
    AC4               1.157    0.067    1.032    1.295    1.318    0.815
  Org_Comm =~                                                           
    OC1               1.000                               1.433    0.570
    OC2               1.370    0.120    1.165    1.634    1.963    0.889
    OC3               0.817    0.083    0.669    0.993    1.171    0.661
    OC4               1.218    0.108    1.021    1.453    1.746    0.842
  Job_Sat =~                                                            
    JS1               1.000                               0.978    0.730
    JS2               1.047    0.085    0.894    1.217    1.024    0.741
    JS3               0.949    0.082    0.795    1.114    0.928    0.700
    JS4               0.941    0.080    0.787    1.105    0.920    0.711
  Stay_Int =~                                                           
    SI1               1.000                               0.722    0.816
    SI2               1.067    0.053    0.969    1.172    0.770    0.865
    SI3               1.059    0.067    0.930    1.194    0.764    0.744
    SI4               1.162    0.061    1.045    1.287    0.839    0.855
     Rhat    Prior       
                         
                         
    1.000     normal(0,1)
    1.000    normal(0,10)
    1.000    normal(0,10)
                         
                         
    1.000    normal(0,10)
    0.999    normal(0,10)
    0.999    normal(0,10)
                         
                         
    1.000    normal(0,10)
    1.000    normal(0,10)
    1.000    normal(0,10)
                         
                         
    1.002    normal(0,10)
    1.001    normal(0,10)
    1.000    normal(0,10)
                         
                         
    1.000    normal(0,10)
    1.001    normal(0,10)
    1.001    normal(0,10)

Regressions:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Job_Sat ~                                                             
    Env_Supp          0.132    0.056    0.024    0.241    0.172    0.172
    Att_Cowrk         0.030    0.048   -0.065    0.123    0.034    0.034
    Org_Comm          0.061    0.049   -0.034    0.160    0.089    0.089
  Stay_Int ~                                                            
    Env_Supp          0.192    0.034    0.125    0.262    0.336    0.336
    Att_Cowrk         0.075    0.031    0.015    0.135    0.118    0.118
    Org_Comm          0.161    0.032    0.102    0.229    0.320    0.320
    Job_Sat           0.102    0.035    0.034    0.173    0.139    0.139
     Rhat    Prior       
                         
    1.000    normal(0,10)
    0.999 normal(0.3,0.1)
    1.000    normal(0,10)
                         
    0.999    normal(0,10)
    0.999    normal(0,10)
    0.999    normal(0,10)
    0.999 normal(0.5,0.1)

Covariances:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Env_Supp ~~                                                           
    Att_Cowrk         0.356    0.089    0.187    0.539    0.246    0.246
    Org_Comm          0.888    0.138    0.633    1.170    0.489    0.489
  Att_Cowrk ~~                                                          
    Org_Comm          0.488    0.106    0.297    0.718    0.299    0.299
     Rhat    Prior       
                         
    0.999     lkj_corr(1)
    1.000     lkj_corr(1)
                         
    1.000     lkj_corr(1)

Variances:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
   .EP1               1.744    0.145    1.469    2.036    1.744    0.521
   .EP2               0.910    0.094    0.738    1.104    0.910    0.339
   .EP3               0.692    0.064    0.575    0.827    0.692    0.391
   .EP4               0.632    0.065    0.513    0.768    0.632    0.320
   .AC1               0.642    0.062    0.531    0.770    0.642    0.331
   .AC2               0.988    0.094    0.816    1.178    0.988    0.327
   .AC3               0.609    0.061    0.498    0.735    0.609    0.300
   .AC4               0.880    0.083    0.729    1.052    0.880    0.336
   .OC1               4.264    0.328    3.682    4.945    4.264    0.675
   .OC2               1.019    0.153    0.730    1.328    1.019    0.209
   .OC3               1.766    0.137    1.511    2.053    1.766    0.563
   .OC4               1.257    0.138    0.994    1.537    1.257    0.292
   .JS1               0.839    0.082    0.688    1.014    0.839    0.467
   .JS2               0.863    0.090    0.699    1.051    0.863    0.451
   .JS3               0.898    0.081    0.746    1.072    0.898    0.510
   .JS4               0.826    0.080    0.681    0.993    0.826    0.494
   .SI1               0.262    0.024    0.217    0.312    0.262    0.335
   .SI2               0.200    0.022    0.159    0.245    0.200    0.252
   .SI3               0.471    0.039    0.399    0.552    0.471    0.446
   .SI4               0.259    0.027    0.207    0.313    0.259    0.269
    Env_Supp          1.605    0.211    1.235    2.050    1.000    1.000
    Att_Cowrk         1.297    0.139    1.045    1.593    1.000    1.000
    Org_Comm          2.054    0.359    1.415    2.817    1.000    1.000
   .Job_Sat           0.901    0.121    0.680    1.150    0.942    0.942
   .Stay_Int          0.294    0.034    0.232    0.364    0.564    0.564
     Rhat    Prior       
    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]
    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]
    1.000 gamma(1,.5)[sd]
    1.001 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.000 gamma(1,.5)[sd]
    1.000 gamma(1,.5)[sd]
    1.000 gamma(1,.5)[sd]
    1.001 gamma(1,.5)[sd]
    1.001 gamma(1,.5)[sd]

R-Square:
                   Estimate
    EP1               0.479
    EP2               0.661
    EP3               0.609
    EP4               0.680
    AC1               0.669
    AC2               0.673
    AC3               0.700
    AC4               0.664
    OC1               0.325
    OC2               0.791
    OC3               0.437
    OC4               0.708
    JS1               0.533
    JS2               0.549
    JS3               0.490
    JS4               0.506
    SI1               0.665
    SI2               0.748
    SI3               0.554
    SI4               0.731
    Job_Sat           0.058
    Stay_Int          0.436
blavFitIndices(B_fit2)
Warning: 
50 (12.6%) p_waic estimates greater than 0.4. We recommend trying loo instead.
Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
Posterior mean (EAP) of devm-based fit indices:

      BRMSEA    BGammaHat adjBGammaHat          BMc 
       0.036        0.986        0.972        0.931 
coef(B_fit2) %>%
  kable(
    digits = 3,
    format = "html",
    booktabs = TRUE,
    caption = "Model 2: Posterior Estimates"
  ) %>%
  kable_classic(full_width = FALSE, html_font = "Cambria")
Model 2: Posterior Estimates
x
Env_Supp=~EP2 1.05233595
Env_Supp=~EP3 0.82010711
Env_Supp=~EP4 0.91421937
Att_Cowrk=~AC2 1.25114540
Att_Cowrk=~AC3 1.04758351
Att_Cowrk=~AC4 1.15722824
Org_Comm=~OC2 1.36955130
Org_Comm=~OC3 0.81688520
Org_Comm=~OC4 1.21818121
Job_Sat=~JS2 1.04724357
Job_Sat=~JS3 0.94890311
Job_Sat=~JS4 0.94064472
Stay_Int=~SI2 1.06683519
Stay_Int=~SI3 1.05858992
Stay_Int=~SI4 1.16191087
Job_Sat~Env_Supp 0.13245396
Job_Sat~Att_Cowrk 0.02955331
Job_Sat~Org_Comm 0.06057994
Stay_Int~Env_Supp 0.19169864
Stay_Int~Att_Cowrk 0.07497001
Stay_Int~Org_Comm 0.16101549
Stay_Int~Job_Sat 0.10229977
Env_Supp~~Att_Cowrk 0.35558831
Env_Supp~~Org_Comm 0.88817317
Att_Cowrk~~Org_Comm 0.48830706
EP1~~EP1 1.74413939
EP2~~EP2 0.91030435
EP3~~EP3 0.69189179
EP4~~EP4 0.63204949
AC1~~AC1 0.64199507
AC2~~AC2 0.98840975
AC3~~AC3 0.60905525
AC4~~AC4 0.87989178
OC1~~OC1 4.26417874
OC2~~OC2 1.01933829
OC3~~OC3 1.76558950
OC4~~OC4 1.25657745
JS1~~JS1 0.83926723
JS2~~JS2 0.86262649
JS3~~JS3 0.89777894
JS4~~JS4 0.82582345
SI1~~SI1 0.26228228
SI2~~SI2 0.19953398
SI3~~SI3 0.47108229
SI4~~SI4 0.25876541
Env_Supp~~Env_Supp 1.60510164
Att_Cowrk~~Att_Cowrk 1.29664341
Org_Comm~~Org_Comm 2.05444113
Job_Sat~~Job_Sat 0.90051979
Stay_Int~~Stay_Int 0.29395682
# Convergence (Rhat should be ~1)
blavInspect(B_fit2, "rhat")
       Env_Supp=~EP2        Env_Supp=~EP3        Env_Supp=~EP4 
           0.9997795            0.9997582            0.9997945 
      Att_Cowrk=~AC2       Att_Cowrk=~AC3       Att_Cowrk=~AC4 
           0.9998579            0.9994991            0.9993860 
       Org_Comm=~OC2        Org_Comm=~OC3        Org_Comm=~OC4 
           1.0001280            0.9998580            0.9997512 
        Job_Sat=~JS2         Job_Sat=~JS3         Job_Sat=~JS4 
           1.0020571            1.0008162            0.9999660 
       Stay_Int=~SI2        Stay_Int=~SI3        Stay_Int=~SI4 
           1.0001916            1.0010021            1.0007905 
    Job_Sat~Env_Supp    Job_Sat~Att_Cowrk     Job_Sat~Org_Comm 
           0.9998379            0.9994700            0.9995112 
   Stay_Int~Env_Supp   Stay_Int~Att_Cowrk    Stay_Int~Org_Comm 
           0.9993286            0.9992264            0.9994762 
    Stay_Int~Job_Sat  Env_Supp~~Att_Cowrk   Env_Supp~~Org_Comm 
           0.9992499            0.9994078            1.0000468 
 Att_Cowrk~~Org_Comm             EP1~~EP1             EP2~~EP2 
           0.9997015            0.9993212            0.9998598 
            EP3~~EP3             EP4~~EP4             AC1~~AC1 
           0.9993281            0.9998082            0.9997120 
            AC2~~AC2             AC3~~AC3             AC4~~AC4 
           0.9996619            0.9992538            0.9991569 
            OC1~~OC1             OC2~~OC2             OC3~~OC3 
           0.9991976            0.9994420            0.9991603 
            OC4~~OC4             JS1~~JS1             JS2~~JS2 
           0.9993225            1.0002440            1.0005617 
            JS3~~JS3             JS4~~JS4             SI1~~SI1 
           0.9994241            0.9992051            0.9995742 
            SI2~~SI2             SI3~~SI3             SI4~~SI4 
           0.9996769            0.9994502            0.9994870 
  Env_Supp~~Env_Supp Att_Cowrk~~Att_Cowrk   Org_Comm~~Org_Comm 
           0.9998454            1.0003942            1.0001945 
    Job_Sat~~Job_Sat   Stay_Int~~Stay_Int 
           1.0010082            1.0005460 
# Trace plots
plot(B_fit2, pars = 16:22, plot.type = "trace")

# Credible intervals
plot(B_fit2, pars = 16:22, plot.type = "intervals")

B_fit3 <- bsem(
  BayesM2,
  data = SEM_Data_NM,
  dp = dpriors(lambda = "normal(1,5)")
)

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000589 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 5.89 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 1: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 1: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 1: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 1: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 1: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 1: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 1: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 1: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 1: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 1: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 1: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 5.783 seconds (Warm-up)
Chain 1:                10.343 seconds (Sampling)
Chain 1:                16.126 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 0.000529 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 5.29 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 2: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 2: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 2: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 2: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 2: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 2: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 2: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 2: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 2: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 2: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 2: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 5.566 seconds (Warm-up)
Chain 2:                9.886 seconds (Sampling)
Chain 2:                15.452 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 0.000607 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 6.07 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 1500 [  0%]  (Warmup)
Chain 3: Iteration:  150 / 1500 [ 10%]  (Warmup)
Chain 3: Iteration:  300 / 1500 [ 20%]  (Warmup)
Chain 3: Iteration:  450 / 1500 [ 30%]  (Warmup)
Chain 3: Iteration:  501 / 1500 [ 33%]  (Sampling)
Chain 3: Iteration:  650 / 1500 [ 43%]  (Sampling)
Chain 3: Iteration:  800 / 1500 [ 53%]  (Sampling)
Chain 3: Iteration:  950 / 1500 [ 63%]  (Sampling)
Chain 3: Iteration: 1100 / 1500 [ 73%]  (Sampling)
Chain 3: Iteration: 1250 / 1500 [ 83%]  (Sampling)
Chain 3: Iteration: 1400 / 1500 [ 93%]  (Sampling)
Chain 3: Iteration: 1500 / 1500 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 5.676 seconds (Warm-up)
Chain 3:                9.81 seconds (Sampling)
Chain 3:                15.486 seconds (Total)
Chain 3: 
Computing post-estimation metrics (including lvs if requested)...
summary(B_fit3, standardized = TRUE, fit.measures = TRUE, rsquare = TRUE)
blavaan 0.5.8 ended normally after 1000 iterations

  Estimator                                      BAYES
  Optimization method                             MCMC
  Number of model parameters                        50

  Number of observations                           398

  Statistic                                 MargLogLik         PPP
  Value                                     -12370.436       0.016

Parameter Estimates:


Latent Variables:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Env_Supp =~                                                           
    EP1               1.000                               1.268    0.693
    EP2               1.051    0.073    0.919    1.207    1.333    0.813
    EP3               0.819    0.061    0.707    0.947    1.038    0.780
    EP4               0.914    0.065    0.794    1.055    1.158    0.824
  Att_Cowrk =~                                                          
    AC1               1.000                               1.141    0.818
    AC2               1.250    0.070    1.120    1.397    1.426    0.821
    AC3               1.046    0.058    0.938    1.167    1.194    0.837
    AC4               1.158    0.066    1.037    1.297    1.321    0.816
  Org_Comm =~                                                           
    OC1               1.000                               1.426    0.568
    OC2               1.374    0.120    1.163    1.637    1.960    0.889
    OC3               0.819    0.081    0.677    1.001    1.168    0.660
    OC4               1.222    0.107    1.031    1.460    1.743    0.841
  Job_Sat =~                                                            
    JS1               1.000                               0.975    0.728
    JS2               1.048    0.083    0.895    1.226    1.022    0.740
    JS3               0.950    0.079    0.804    1.108    0.927    0.700
    JS4               0.942    0.081    0.792    1.112    0.919    0.712
  Stay_Int =~                                                           
    SI1               1.000                               0.722    0.816
    SI2               1.066    0.055    0.962    1.175    0.770    0.865
    SI3               1.060    0.068    0.933    1.201    0.765    0.745
    SI4               1.162    0.063    1.043    1.292    0.839    0.855
     Rhat    Prior       
                         
                         
    1.003     normal(0,1)
    1.002     normal(1,5)
    1.003     normal(1,5)
                         
                         
    0.999     normal(1,5)
    0.999     normal(1,5)
    1.000     normal(1,5)
                         
                         
    1.001     normal(1,5)
    1.000     normal(1,5)
    1.002     normal(1,5)
                         
                         
    1.000     normal(1,5)
    1.000     normal(1,5)
    1.000     normal(1,5)
                         
                         
    1.001     normal(1,5)
    1.000     normal(1,5)
    1.000     normal(1,5)

Regressions:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Job_Sat ~                                                             
    Env_Supp          0.131    0.056    0.022    0.242    0.171    0.171
    Att_Cowrk         0.029    0.047   -0.061    0.121    0.033    0.033
    Org_Comm          0.060    0.050   -0.037    0.162    0.088    0.088
  Stay_Int ~                                                            
    Env_Supp          0.192    0.034    0.127    0.259    0.337    0.337
    Att_Cowrk         0.075    0.031    0.015    0.135    0.118    0.118
    Org_Comm          0.162    0.032    0.101    0.228    0.319    0.319
    Job_Sat           0.103    0.036    0.033    0.174    0.139    0.139
     Rhat    Prior       
                         
    0.999    normal(0,10)
    1.000 normal(0.3,0.1)
    1.000    normal(0,10)
                         
    1.000    normal(0,10)
    1.000    normal(0,10)
    1.000    normal(0,10)
    0.999 normal(0.5,0.1)

Covariances:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
  Env_Supp ~~                                                           
    Att_Cowrk         0.357    0.088    0.194    0.534    0.247    0.247
    Org_Comm          0.882    0.137    0.632    1.168    0.488    0.488
  Att_Cowrk ~~                                                          
    Org_Comm          0.488    0.105    0.297    0.701    0.300    0.300
     Rhat    Prior       
                         
    0.999     lkj_corr(1)
    1.000     lkj_corr(1)
                         
    1.000     lkj_corr(1)

Variances:
                   Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
   .EP1               1.739    0.151    1.468    2.057    1.739    0.520
   .EP2               0.911    0.091    0.747    1.107    0.911    0.339
   .EP3               0.693    0.065    0.578    0.829    0.693    0.392
   .EP4               0.634    0.066    0.510    0.767    0.634    0.321
   .AC1               0.642    0.063    0.530    0.774    0.642    0.330
   .AC2               0.985    0.093    0.813    1.174    0.985    0.326
   .AC3               0.610    0.058    0.504    0.732    0.610    0.300
   .AC4               0.879    0.081    0.731    1.049    0.879    0.335
   .OC1               4.266    0.326    3.660    4.947    4.266    0.677
   .OC2               1.016    0.157    0.721    1.339    1.016    0.209
   .OC3               1.766    0.144    1.504    2.064    1.766    0.564
   .OC4               1.258    0.142    0.989    1.548    1.258    0.293
   .JS1               0.842    0.084    0.692    1.014    0.842    0.469
   .JS2               0.863    0.084    0.707    1.029    0.863    0.452
   .JS3               0.896    0.084    0.738    1.070    0.896    0.511
   .JS4               0.823    0.077    0.681    0.981    0.823    0.494
   .SI1               0.262    0.025    0.217    0.313    0.262    0.335
   .SI2               0.199    0.021    0.158    0.242    0.199    0.251
   .SI3               0.470    0.039    0.399    0.549    0.470    0.445
   .SI4               0.259    0.027    0.210    0.316    0.259    0.269
    Env_Supp          1.607    0.216    1.222    2.070    1.000    1.000
    Att_Cowrk         1.302    0.139    1.043    1.592    1.000    1.000
    Org_Comm          2.035    0.337    1.405    2.731    1.000    1.000
   .Job_Sat           0.897    0.120    0.678    1.150    0.943    0.943
   .Stay_Int          0.294    0.034    0.233    0.366    0.563    0.563
     Rhat    Prior       
    1.000 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]
    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.000 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]
    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]
    1.001 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]

R-Square:
                   Estimate
    EP1               0.480
    EP2               0.661
    EP3               0.608
    EP4               0.679
    AC1               0.670
    AC2               0.674
    AC3               0.700
    AC4               0.665
    OC1               0.323
    OC2               0.791
    OC3               0.436
    OC4               0.707
    JS1               0.531
    JS2               0.548
    JS3               0.489
    JS4               0.506
    SI1               0.665
    SI2               0.749
    SI3               0.555
    SI4               0.731
    Job_Sat           0.057
    Stay_Int          0.437
coef(B_fit3) %>%
    kable(
    digits = 3,
    format = "html",
    booktabs = TRUE,
    caption = "Model 3: Posterior Estimates (Weak Priors)"
  ) %>%
  kable_classic(full_width = FALSE, html_font = "Cambria")
Model 3: Posterior Estimates (Weak Priors)
x
Env_Supp=~EP2 1.05103875
Env_Supp=~EP3 0.81855025
Env_Supp=~EP4 0.91353201
Att_Cowrk=~AC2 1.24989473
Att_Cowrk=~AC3 1.04636762
Att_Cowrk=~AC4 1.15797210
Org_Comm=~OC2 1.37412178
Org_Comm=~OC3 0.81854151
Org_Comm=~OC4 1.22210175
Job_Sat=~JS2 1.04763953
Job_Sat=~JS3 0.95031831
Job_Sat=~JS4 0.94221068
Stay_Int=~SI2 1.06640464
Stay_Int=~SI3 1.06003615
Stay_Int=~SI4 1.16165132
Job_Sat~Env_Supp 0.13145365
Job_Sat~Att_Cowrk 0.02863180
Job_Sat~Org_Comm 0.06025761
Stay_Int~Env_Supp 0.19213552
Stay_Int~Att_Cowrk 0.07475601
Stay_Int~Org_Comm 0.16160594
Stay_Int~Job_Sat 0.10287073
Env_Supp~~Att_Cowrk 0.35747782
Env_Supp~~Org_Comm 0.88226780
Att_Cowrk~~Org_Comm 0.48822021
EP1~~EP1 1.73913610
EP2~~EP2 0.91119635
EP3~~EP3 0.69313202
EP4~~EP4 0.63424619
AC1~~AC1 0.64178274
AC2~~AC2 0.98523863
AC3~~AC3 0.61001729
AC4~~AC4 0.87889912
OC1~~OC1 4.26625460
OC2~~OC2 1.01624000
OC3~~OC3 1.76648259
OC4~~OC4 1.25755173
JS1~~JS1 0.84206019
JS2~~JS2 0.86305014
JS3~~JS3 0.89643282
JS4~~JS4 0.82335190
SI1~~SI1 0.26239286
SI2~~SI2 0.19901222
SI3~~SI3 0.46998620
SI4~~SI4 0.25903218
Env_Supp~~Env_Supp 1.60735527
Att_Cowrk~~Att_Cowrk 1.30166097
Org_Comm~~Org_Comm 2.03472117
Job_Sat~~Job_Sat 0.89701453
Stay_Int~~Stay_Int 0.29371767
blavInspect(B_fit3, "rhat")
       Env_Supp=~EP2        Env_Supp=~EP3        Env_Supp=~EP4 
           1.0030587            1.0021384            1.0029584 
      Att_Cowrk=~AC2       Att_Cowrk=~AC3       Att_Cowrk=~AC4 
           0.9993566            0.9992504            0.9995370 
       Org_Comm=~OC2        Org_Comm=~OC3        Org_Comm=~OC4 
           1.0010065            1.0000329            1.0016103 
        Job_Sat=~JS2         Job_Sat=~JS3         Job_Sat=~JS4 
           1.0003696            1.0001723            1.0001136 
       Stay_Int=~SI2        Stay_Int=~SI3        Stay_Int=~SI4 
           1.0006708            1.0002865            1.0002660 
    Job_Sat~Env_Supp    Job_Sat~Att_Cowrk     Job_Sat~Org_Comm 
           0.9994825            0.9995212            0.9995135 
   Stay_Int~Env_Supp   Stay_Int~Att_Cowrk    Stay_Int~Org_Comm 
           0.9999417            0.9996804            1.0001914 
    Stay_Int~Job_Sat  Env_Supp~~Att_Cowrk   Env_Supp~~Org_Comm 
           0.9991264            0.9993867            0.9999587 
 Att_Cowrk~~Org_Comm             EP1~~EP1             EP2~~EP2 
           1.0001407            0.9999626            0.9995925 
            EP3~~EP3             EP4~~EP4             AC1~~AC1 
           0.9992713            0.9996599            0.9998458 
            AC2~~AC2             AC3~~AC3             AC4~~AC4 
           1.0004493            0.9995111            0.9991987 
            OC1~~OC1             OC2~~OC2             OC3~~OC3 
           0.9992383            1.0000208            0.9991289 
            OC4~~OC4             JS1~~JS1             JS2~~JS2 
           0.9991520            0.9994850            1.0000345 
            JS3~~JS3             JS4~~JS4             SI1~~SI1 
           0.9993771            0.9996318            0.9994349 
            SI2~~SI2             SI3~~SI3             SI4~~SI4 
           1.0000492            0.9993937            0.9996801 
  Env_Supp~~Env_Supp Att_Cowrk~~Att_Cowrk   Org_Comm~~Org_Comm 
           1.0014152            0.9992559            1.0005315 
    Job_Sat~~Job_Sat   Stay_Int~~Stay_Int 
           0.9994102            0.9999358 
plot(B_fit3, pars = 16:22, plot.type = "trace")

plot(B_fit3, pars = 16:22, plot.type = "intervals")

blavCompare(B_fit1, B_fit2)
Replacing NAs in `r_eff` with 1s
Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
Replacing NAs in `r_eff` with 1s
Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
Warning: 
49 (12.3%) p_waic estimates greater than 0.4. We recommend trying loo instead.
Warning: 
50 (12.6%) p_waic estimates greater than 0.4. We recommend trying loo instead.

WAIC estimates: 
 object1:  24528.125 
 object2:  24532.055 

 ELPD difference & SE: 
   -1.965    2.051 

LOO estimates: 
 object1:  24526.464 
 object2:  24530.093 

 ELPD difference & SE: 
   -1.814    1.864 

Laplace approximation to the log-Bayes factor
(experimental; positive values favor object1):    2.935 

Sample Write Up

A Bayesian structural equation model was estimated to examine relationships among latent constructs. Model estimation showed excellent convergence, with all R-hat values close to 1.00 and well-mixed trace plots, indicating stable posterior sampling. Overall model fit was strong according to posterior predictive fit indices, including BRMSEA = 0.036, BGammaHat = 0.986, adjusted BGammaHat = 0.973, and BMc = 0.931, all indicating good to excellent global fit. Predictive model comparison using LOO and WAIC indicated no meaningful differences in out-of-sample predictive performance across alternative prior specifications, suggesting robust predictive equivalence. However, posterior predictive checks indicated potential localized misfit (PPP = 0.015), suggesting that while the model captures the overall covariance structure well, it may not fully reproduce certain finer-grained aspects of the observed data. Taken together, results suggest a well-identified and stable model with strong global fit and predictive robustness, alongside minor localized discrepancies in model-data reproduction.