Paquetes requeridos

library(future)
future::plan("multisession") # Windows

library(lavaan)
## This is lavaan 0.6-10
## lavaan is FREE software! Please report any bugs.
library(blavaan)
## Loading required package: Rcpp
## This is blavaan 0.4-1
## On multicore systems, we suggest use of future::plan("multicore") or
##   future::plan("multisession") for faster post-MCMC computations.
library(semPlot)
## Found more than one class "family" in cache; using the first, from namespace 'MatrixModels'
## Also defined by 'lme4'
## Found more than one class "family" in cache; using the first, from namespace 'MatrixModels'
## Also defined by 'lme4'
## Found more than one class "family" in cache; using the first, from namespace 'MatrixModels'
## Also defined by 'lme4'
library(bayestestR)
## Warning: package 'bayestestR' was built under R version 4.1.3
library(sjPlot)
## Warning: package 'sjPlot' was built under R version 4.1.3
library(knitr)

#leer la base de datos
datos <- readRDS("data/datos.RDS")

#comparacion de modelos

#MODELO DE REFERENCIA
model_bayesianoref <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fitref <- bsem(
  model = model_bayesianoref,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 26.22 seconds (Warm-up)
## Chain 1:                45.471 seconds (Sampling)
## Chain 1:                71.691 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0.001 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 29.231 seconds (Warm-up)
## Chain 2:                42.445 seconds (Sampling)
## Chain 2:                71.676 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 24.959 seconds (Warm-up)
## Chain 3:                36.155 seconds (Sampling)
## Chain 3:                61.114 seconds (Total)
## Chain 3:
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
## Computing posterior predictives...
summary(fitref,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -519.174       0.209
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.541    0.813
##     F_c30             1.438    0.157    1.177    1.780    0.778    0.939
##   sintomas =~                                                           
##     S_br23            1.000                               0.331    0.588
##     S_c30             2.378    0.656    1.655    3.726    0.787    0.932
##      Rhat    Prior       
##                          
##                          
##     1.000    normal(0,15)
##                          
##                          
##     1.009    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.618    0.443   -2.581   -1.075   -0.989   -0.989
##   CV_Gral ~                                                             
##     Salud      (c)    0.750    0.085    0.563    0.902    0.750    0.765
##     sintomas   (e)   -0.607    7.318  -16.903   13.688   -0.201   -0.110
##     funcionldd (d)    0.341    4.662   -9.169    9.575    0.185    0.101
##   Salud ~                                                               
##     sintomas         -5.149    8.452  -22.773   10.897   -1.704   -0.916
##     funcionldd (b)   -0.593    5.442  -12.004    9.669   -0.321   -0.173
##      Rhat    Prior       
##                          
##     1.006    normal(0,10)
##                          
##     1.001    normal(0,10)
##     1.001    normal(0,10)
##     1.001    normal(0,10)
##                          
##     1.001  normal(-10,10)
##     1.002    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.339    0.071    2.199    2.479    2.339    3.512
##    .F_c30             2.432    0.086    2.261    2.603    2.432    2.933
##    .S_br23            1.767    0.062    1.646    1.887    1.767    3.144
##    .S_c30             2.169    0.089    1.993    2.340    2.169    2.570
##    .CV_Gral           0.846    0.379    0.152    1.667    0.846    0.464
##    .Salud             4.328    0.202    3.944    4.729    4.328    2.328
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.001    normal(0,32)
##     1.001    normal(0,32)
##     1.000    normal(0,32)
##     1.002    normal(0,32)
##     1.001    normal(0,10)
##     1.000    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.150    0.030    0.100    0.219    0.150    0.339
##    .F_c30             0.082    0.028    0.031    0.141    0.082    0.119
##    .S_br23            0.207    0.036    0.148    0.286    0.207    0.654
##    .S_c30             0.093    0.035    0.012    0.161    0.093    0.131
##    .CV_Gral           0.433    0.107    0.190    0.640    0.433    0.131
##    .Salud             1.534    0.333    0.862    2.226    1.534    0.444
##    .funcionalidad     0.007    0.010    0.000    0.038    0.022    0.022
##     sintomas          0.109    0.042    0.038    0.205    1.000    1.000
##      Rhat    Prior       
##     1.000 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.005 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.007 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
plot(fitref)

#SEM Bayesiano final utilizando variables moderadoras

#Modelo 1.0 interaccion Edad 
model_bayesiano1.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad + Edad
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fitedad1.0 <- bsem(
  model = model_bayesiano1.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 46.761 seconds (Warm-up)
## Chain 1:                81.978 seconds (Sampling)
## Chain 1:                128.739 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 46.935 seconds (Warm-up)
## Chain 2:                61.924 seconds (Sampling)
## Chain 2:                108.859 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 47.249 seconds (Warm-up)
## Chain 3:                77.817 seconds (Sampling)
## Chain 3:                125.066 seconds (Total)
## Chain 3: 
## Computing posterior predictives...
summary(fitedad1.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -526.876       0.030
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.537    0.810
##     F_c30             1.435    0.157    1.171    1.779    0.770    0.938
##   sintomas =~                                                           
##     S_br23            1.000                               0.330    0.588
##     S_c30             2.352    0.477    1.669    3.551    0.777    0.930
##      Rhat    Prior       
##                          
##                          
##     1.000    normal(0,15)
##                          
##                          
##     1.001    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.606    0.344   -2.406   -1.097   -0.988   -0.988
##   CV_Gral ~                                                             
##     Salud      (c)    0.742    0.086    0.573    0.905    0.742    0.752
##     sintomas   (e)   -1.593    7.331  -16.493   13.581   -0.526   -0.287
##     funcionldd (d)   -0.210    4.646   -9.875    9.293   -0.113   -0.061
##     Edad             -0.005    0.007   -0.019    0.009   -0.005   -0.033
##   Salud ~                                                               
##     sintomas         -5.530    8.053  -22.505    8.945   -1.827   -0.983
##     funcionldd (b)   -0.842    5.077  -11.808    8.190   -0.452   -0.243
##      Rhat    Prior       
##                          
##     1.001    normal(0,10)
##                          
##     1.001    normal(0,10)
##     1.002    normal(0,10)
##     1.002    normal(0,10)
##     1.000    normal(0,10)
##                          
##     1.004  normal(-10,10)
##     1.004    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.340    0.072    2.198    2.481    2.340    3.534
##    .F_c30             2.435    0.087    2.268    2.610    2.435    2.967
##    .S_br23            1.767    0.064    1.643    1.894    1.767    3.145
##    .S_c30             2.166    0.089    1.992    2.338    2.166    2.593
##    .CV_Gral           1.146    0.576    0.038    2.252    1.146    0.625
##    .Salud             4.331    0.205    3.929    4.736    4.331    2.331
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.001    normal(0,32)
##     1.001    normal(0,32)
##     1.000    normal(0,32)
##     1.001    normal(0,32)
##     1.001    normal(0,10)
##     1.000    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.150    0.029    0.102    0.216    0.150    0.343
##    .F_c30             0.081    0.027    0.031    0.136    0.081    0.120
##    .S_br23            0.207    0.036    0.149    0.287    0.207    0.654
##    .S_c30             0.094    0.034    0.018    0.162    0.094    0.134
##    .CV_Gral           0.433    0.112    0.186    0.642    0.433    0.129
##    .Salud             1.544    0.306    0.972    2.180    1.544    0.447
##    .funcionalidad     0.007    0.010    0.000    0.037    0.023    0.023
##     sintomas          0.109    0.042    0.041    0.203    1.000    1.000
##      Rhat    Prior       
##     1.000 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.006 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD1.0 

blavCompare(fitref, fitedad1.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.

## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  916.356 
## 
## WAIC difference & SE: 
##    -1.214    1.055 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  917.082 
## 
## LOO difference & SE: 
##    -1.500    1.117 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    7.702
#Gana el mod ref 7.185
#confimacion COMPARACION MODREF Vs MOD1.0 
blavCompare(fitedad1.0, fitref)
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.

## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  916.356 
##  object2:  913.927 
## 
## WAIC difference & SE: 
##    -1.214    1.055 
## 
## LOO estimates: 
##  object1:  917.082 
##  object2:  914.083 
## 
## LOO difference & SE: 
##    -1.500    1.117 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):   -7.702
#Gana el mod ref -7.185






#Modelo 2.0 interaccion compañero permanente


model_bayesiano2.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad + Con_compañero_permanente
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit2.0 <- bsem(
  model = model_bayesiano2.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 22.275 seconds (Warm-up)
## Chain 1:                19.466 seconds (Sampling)
## Chain 1:                41.741 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0.001 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 44.229 seconds (Warm-up)
## Chain 2:                88.344 seconds (Sampling)
## Chain 2:                132.573 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0.001 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 40.689 seconds (Warm-up)
## Chain 3:                79.195 seconds (Sampling)
## Chain 3:                119.884 seconds (Total)
## Chain 3:
## Warning: There were 2 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
## Warning: The largest R-hat is 1.66, indicating chains have not mixed.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#r-hat
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
## Warning: blavaan WARNING: at least one parameter has a psrf > 1.2.
## Computing posterior predictives...
## Warning: blavaan WARNING: Small effective sample sizes (< 100) for some
## parameters.
summary(fit2.0,standardized = TRUE)
## ** WARNING ** blavaan (0.4-1) did NOT converge after 500 adapt+burnin iterations
## ** WARNING ** Proceed with caution
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -661.617       0.158
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.932    0.922
##     F_c30             1.458    0.164    1.183    1.817    1.359    0.980
##   sintomas =~                                                           
##     S_br23            1.000                               0.268    0.468
##     S_c30            -5.597   11.799  -30.173    3.510   -1.502   -0.981
##      Rhat    Prior       
##                          
##                          
##     1.029    normal(0,15)
##                          
##                          
##     3.725    normal(0,15)
## Warning in abbreviate(NAMES, minlength = (W - MAX.L), strict = TRUE):
## abreviatura utilizada con caracteres no ASCII
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)    3.452    7.526   -2.374   19.045    0.994    0.994
##   CV_Gral ~                                                             
##     Salud      (c)    0.754    0.075    0.605    0.901    0.754    1.051
##     sintomas   (e)    0.236    7.863  -15.692   16.694    0.063    0.051
##     funcionldd (d)    0.416    3.665   -7.840    8.942    0.387    0.310
##     Cn_cmpñr_p       -0.001    0.158   -0.319    0.307   -0.001   -0.000
##   Salud ~                                                               
##     sintomas         -6.568    8.881  -24.461    9.787   -1.763   -1.011
##     funcionldd (b)    0.589    4.688  -10.666    7.553    0.549    0.315
##      Rhat    Prior       
##                          
##     3.684    normal(0,10)
##                          
##     1.001    normal(0,10)
##     1.017    normal(0,10)
##     1.003    normal(0,10)
##     1.000    normal(0,10)
##                          
##     1.018  normal(-10,10)
##     1.121    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.343    0.073    2.203    2.491    2.343    2.319
##    .F_c30             2.439    0.089    2.268    2.612    2.439    1.759
##    .S_br23            1.765    0.062    1.646    1.882    1.765    3.080
##    .S_c30             2.162    0.091    1.986    2.335    2.162    1.412
##    .CV_Gral           0.834    0.400    0.036    1.617    0.834    0.667
##    .Salud             4.335    0.208    3.921    4.752    4.335    2.486
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.000    normal(0,32)
##     1.001    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     0.999    normal(0,10)
##     1.001    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.152    0.030    0.102    0.218    0.152    0.149
##    .F_c30             0.076    0.027    0.026    0.133    0.076    0.040
##    .S_br23            0.256    0.084    0.152    0.451    0.256    0.781
##    .S_c30             0.087    0.038    0.006    0.161    0.087    0.037
##    .CV_Gral           0.453    0.096    0.247    0.644    0.453    0.290
##    .Salud             1.555    0.313    0.978    2.237    1.555    0.511
##    .funcionalidad     0.010    0.013    0.000    0.047    0.011    0.011
##     sintomas          0.072    0.060    0.001    0.189    1.000    1.000
##      Rhat    Prior       
##     1.014 gamma(1,.5)[sd]
##     1.038 gamma(1,.5)[sd]
##     1.955 gamma(1,.5)[sd]
##     1.038 gamma(1,.5)[sd]
##     1.016 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.115 gamma(1,.5)[sd]
##     1.890 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD2.0 
blavCompare(fitref, fit2.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 20 (25.0%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  936.231 
## 
## WAIC difference & SE: 
##   -11.152    1.910 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  935.829 
## 
## LOO difference & SE: 
##   -10.873    1.930 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):  142.443
#Gana MODREF


#COMPARACION MOD1.0 Vs MOD2.0 
blavCompare(fitedad1.0, fit2.0)
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 20 (25.0%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  916.356 
##  object2:  936.231 
## 
## WAIC difference & SE: 
##    -9.937    2.144 
## 
## LOO estimates: 
##  object1:  917.082 
##  object2:  935.829 
## 
## LOO difference & SE: 
##    -9.373    2.181 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):  134.741
#Gana  MOD2.0 -2.782



#MODELO COMPUESTO 1.0 + 2.0 (Edad + compañero permanente)
model_bayesiano1.0_2.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad + Edad + Con_compañero_permanente
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit1.0_2.0 <- bsem(
  model = model_bayesiano1.0_2.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 53.121 seconds (Warm-up)
## Chain 1:                62.527 seconds (Sampling)
## Chain 1:                115.648 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0.001 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 58.515 seconds (Warm-up)
## Chain 2:                83.624 seconds (Sampling)
## Chain 2:                142.139 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 55.425 seconds (Warm-up)
## Chain 3:                103.268 seconds (Sampling)
## Chain 3:                158.693 seconds (Total)
## Chain 3:
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
## Computing posterior predictives...
summary(fit1.0_2.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -531.206       0.050
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.536    0.810
##     F_c30             1.442    0.157    1.173    1.800    0.772    0.939
##   sintomas =~                                                           
##     S_br23            1.000                               0.330    0.587
##     S_c30             2.357    0.467    1.647    3.429    0.779    0.933
##      Rhat    Prior       
##                          
##                          
##     1.001    normal(0,15)
##                          
##                          
##     1.002    normal(0,15)
## Warning in abbreviate(NAMES, minlength = (W - MAX.L), strict = TRUE):
## abreviatura utilizada con caracteres no ASCII
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.599    0.340   -2.427   -1.071   -0.986   -0.986
##   CV_Gral ~                                                             
##     Salud      (c)    0.741    0.084    0.575    0.906    0.741    0.752
##     sintomas   (e)   -1.125    6.622  -14.628   12.822   -0.372   -0.204
##     funcionldd (d)    0.069    4.178   -8.828    9.195    0.037    0.020
##     Edad             -0.005    0.007   -0.018    0.009   -0.005   -0.033
##     Cn_cmpñr_p       -0.011    0.161   -0.332    0.308   -0.011   -0.003
##   Salud ~                                                               
##     sintomas         -5.107    8.092  -21.858    8.931   -1.687   -0.913
##     funcionldd (b)   -0.599    5.170  -11.708    8.516   -0.321   -0.174
##      Rhat    Prior       
##                          
##     1.002    normal(0,10)
##                          
##     1.000    normal(0,10)
##     1.000    normal(0,10)
##     1.000    normal(0,10)
##     1.001    normal(0,10)
##     1.000    normal(0,10)
##                          
##     1.003  normal(-10,10)
##     1.003    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.341    0.073    2.196    2.482    2.341    3.541
##    .F_c30             2.436    0.089    2.263    2.607    2.436    2.963
##    .S_br23            1.767    0.063    1.647    1.895    1.767    3.141
##    .S_c30             2.167    0.091    1.986    2.339    2.167    2.595
##    .CV_Gral           1.166    0.640   -0.046    2.497    1.166    0.639
##    .Salud             4.332    0.205    3.935    4.732    4.332    2.343
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,10)
##     1.000    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.150    0.028    0.102    0.213    0.150    0.343
##    .F_c30             0.079    0.029    0.022    0.141    0.079    0.117
##    .S_br23            0.207    0.036    0.148    0.290    0.207    0.655
##    .S_c30             0.091    0.035    0.006    0.156    0.091    0.130
##    .CV_Gral           0.447    0.100    0.231    0.655    0.447    0.134
##    .Salud             1.537    0.305    0.976    2.175    1.537    0.450
##    .funcionalidad     0.008    0.012    0.000    0.046    0.028    0.028
##     sintomas          0.109    0.042    0.044    0.205    1.000    1.000
##      Rhat    Prior       
##     1.001 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.012 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.007 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MODCOMPUESTO 1.0 + 2.0  
blavCompare(fitref, fit1.0_2.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.

## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  917.917 
## 
## WAIC difference & SE: 
##    -1.995    1.072 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  918.339 
## 
## LOO difference & SE: 
##    -2.128    1.102 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):   12.032
#Gana MODREF 11.216

#COMPATACION MODCOMPUESTO VS MOD1.0
blavCompare(fit1.0_2.0, fitedad1.0)
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.

## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  917.917 
##  object2:  916.356 
## 
## WAIC difference & SE: 
##    -0.781    0.272 
## 
## LOO estimates: 
##  object1:  918.339 
##  object2:  917.082 
## 
## LOO difference & SE: 
##    -0.629    0.382 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):   -4.330
#Gana MOD1.0 -4.378
#COMPATACION MODCOMPUESTO VS MOD2.0
blavCompare(fit1.0_2.0, fit2.0)
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 20 (25.0%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  917.917 
##  object2:  936.231 
## 
## WAIC difference & SE: 
##    -9.157    2.140 
## 
## LOO estimates: 
##  object1:  918.339 
##  object2:  935.829 
## 
## LOO difference & SE: 
##    -8.745    2.177 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):  130.411
#Gana MOD2.0 -7.160 
#Modelo 3.0 interaccion  + estrato 

model_bayesiano3.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas + Estrato
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad 
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit3.0 <- bsem(
  model = model_bayesiano3.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 22.113 seconds (Warm-up)
## Chain 1:                44.058 seconds (Sampling)
## Chain 1:                66.171 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 27.731 seconds (Warm-up)
## Chain 2:                45.567 seconds (Sampling)
## Chain 2:                73.298 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 24.879 seconds (Warm-up)
## Chain 3:                45.489 seconds (Sampling)
## Chain 3:                70.368 seconds (Total)
## Chain 3: 
## Computing posterior predictives...
summary(fit3.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -524.179       0.294
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.545    0.815
##     F_c30             1.432    0.151    1.170    1.761    0.781    0.943
##   sintomas =~                                                           
##     S_br23            1.000                               0.326    0.582
##     S_c30             2.421    0.534    1.717    3.768    0.790    0.937
##      Rhat    Prior       
##                          
##                          
##     1.000    normal(0,15)
##                          
##                          
##     1.003    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.639    0.382   -2.582   -1.106   -0.981   -0.981
##     Estrato           0.082    0.061   -0.019    0.210    0.151    0.075
##   CV_Gral ~                                                             
##     Salud      (c)    0.757    0.070    0.617    0.894    0.757    0.767
##     sintomas   (e)   -1.446    4.001  -10.507    7.513   -0.472   -0.254
##     funcionldd (d)   -0.159    2.433   -5.409    5.069   -0.087   -0.047
##   Salud ~                                                               
##     sintomas         -3.390    5.438  -16.612    6.421   -1.106   -0.587
##     funcionldd (b)    0.542    3.378   -7.774    6.714    0.295    0.157
##      Rhat    Prior       
##                          
##     1.001    normal(0,10)
##     1.002    normal(0,10)
##                          
##     1.000    normal(0,10)
##     1.002    normal(0,10)
##     1.002    normal(0,10)
##                          
##     1.005  normal(-10,10)
##     1.006    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.226    0.113    1.995    2.427    2.226    3.329
##    .F_c30             2.272    0.150    1.958    2.547    2.272    2.743
##    .S_br23            1.763    0.063    1.637    1.886    1.763    3.147
##    .S_c30             2.162    0.090    1.982    2.336    2.162    2.566
##    .CV_Gral           0.848    0.358    0.157    1.588    0.848    0.456
##    .Salud             4.224    0.389    3.372    4.961    4.224    2.242
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.001    normal(0,32)
##     1.001    normal(0,32)
##     1.001    normal(0,32)
##     1.001    normal(0,32)
##     1.000    normal(0,10)
##     1.002    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.150    0.029    0.103    0.215    0.150    0.335
##    .F_c30             0.077    0.026    0.028    0.132    0.077    0.112
##    .S_br23            0.207    0.036    0.148    0.289    0.207    0.661
##    .S_c30             0.086    0.033    0.013    0.151    0.086    0.121
##    .CV_Gral           0.458    0.085    0.309    0.638    0.458    0.133
##    .Salud             1.599    0.301    1.082    2.265    1.599    0.451
##    .funcionalidad     0.010    0.013    0.000    0.047    0.033    0.033
##     sintomas          0.106    0.042    0.038    0.198    1.000    1.000
##      Rhat    Prior       
##     0.999 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD3.0 
blavCompare(fitref, fit3.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  913.483 
## 
## WAIC difference & SE: 
##    -0.222    1.370 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  913.8 
## 
## LOO difference & SE: 
##    -0.142    1.375 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    5.005
#Gana MODREF 4.229 


#Modelo 4.0 interaccion  nivel educativo


model_bayesiano4.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad + Nivel_educativo
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit4.0 <- bsem(
  model = model_bayesiano4.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0.001 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 34.811 seconds (Warm-up)
## Chain 1:                47.36 seconds (Sampling)
## Chain 1:                82.171 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 41.449 seconds (Warm-up)
## Chain 2:                68.258 seconds (Sampling)
## Chain 2:                109.707 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0.001 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 38.219 seconds (Warm-up)
## Chain 3:                81.969 seconds (Sampling)
## Chain 3:                120.188 seconds (Total)
## Chain 3:
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
## Computing posterior predictives...
summary(fit4.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -523.796       0.079
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.538    0.811
##     F_c30             1.432    0.158    1.155    1.786    0.771    0.938
##   sintomas =~                                                           
##     S_br23            1.000                               0.331    0.588
##     S_c30             2.354    0.504    1.665    3.449    0.778    0.931
##      Rhat    Prior       
##                          
##                          
##     0.999    normal(0,15)
##                          
##                          
##     1.003    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.608    0.345   -2.379   -1.097   -0.988   -0.988
##   CV_Gral ~                                                             
##     Salud      (c)    0.746    0.083    0.568    0.900    0.746    0.744
##     sintomas   (e)   -1.068    7.286  -16.054   14.213   -0.353   -0.191
##     funcionldd (d)    0.162    4.649   -9.703   10.068    0.087    0.047
##     Nivel_dctv        0.115    0.174   -0.223    0.443    0.115    0.030
##   Salud ~                                                               
##     sintomas         -5.638    8.340  -22.695    9.547   -1.864   -1.011
##     funcionldd (b)   -0.942    5.317  -12.104    8.678   -0.507   -0.275
##      Rhat    Prior       
##                          
##     1.001    normal(0,10)
##                          
##     1.000    normal(0,10)
##     1.004    normal(0,10)
##     1.005    normal(0,10)
##     1.000    normal(0,10)
##                          
##     1.002  normal(-10,10)
##     1.002    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.342    0.071    2.200    2.480    2.342    3.530
##    .F_c30             2.436    0.084    2.270    2.599    2.436    2.966
##    .S_br23            1.765    0.063    1.645    1.894    1.765    3.139
##    .S_c30             2.165    0.085    1.998    2.333    2.165    2.591
##    .CV_Gral           0.708    0.449   -0.113    1.642    0.708    0.383
##    .Salud             4.336    0.202    3.946    4.744    4.336    2.351
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,10)
##     1.000    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.151    0.028    0.104    0.213    0.151    0.342
##    .F_c30             0.081    0.028    0.031    0.140    0.081    0.120
##    .S_br23            0.207    0.037    0.148    0.291    0.207    0.654
##    .S_c30             0.093    0.034    0.018    0.160    0.093    0.133
##    .CV_Gral           0.440    0.097    0.239    0.626    0.440    0.129
##    .Salud             1.538    0.321    0.937    2.213    1.538    0.452
##    .funcionalidad     0.007    0.011    0.000    0.040    0.023    0.023
##     sintomas          0.109    0.042    0.043    0.202    1.000    1.000
##      Rhat    Prior       
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     0.999 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.006 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD3.0 
blavCompare(fitref, fit4.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  915.128 
## 
## WAIC difference & SE: 
##    -0.600    0.733 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  915.333 
## 
## LOO difference & SE: 
##    -0.625    0.738 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    4.622
#Gana MODREF 4.092

#COMPARACION MOD3.0 Vs MOD4.0
blavCompare(fit3.0, fit4.0)
## Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.

## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.483 
##  object2:  915.128 
## 
## WAIC difference & SE: 
##    -0.822    1.564 
## 
## LOO estimates: 
##  object1:  913.8 
##  object2:  915.333 
## 
## LOO difference & SE: 
##    -0.767    1.565 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):   -0.383
#Gana MOD4.0 -0.137 #GANADOR A MOD REF



#MODELO COMPUESTO 3.0 + 4.0 (Estrato + nivel educativo)
model_bayesiano3.0_4.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas + Estrato
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad + Nivel_educativo
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit3.0_4.0 <- bsem(
  model = model_bayesiano3.0_4.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 34.49 seconds (Warm-up)
## Chain 1:                42.387 seconds (Sampling)
## Chain 1:                76.877 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 34.316 seconds (Warm-up)
## Chain 2:                72.863 seconds (Sampling)
## Chain 2:                107.179 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0.001 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 31.713 seconds (Warm-up)
## Chain 3:                45.783 seconds (Sampling)
## Chain 3:                77.496 seconds (Total)
## Chain 3: 
## Computing posterior predictives...
summary(fit3.0_4.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -527.810       0.129
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.546    0.816
##     F_c30             1.431    0.149    1.171    1.761    0.781    0.943
##   sintomas =~                                                           
##     S_br23            1.000                               0.323    0.579
##     S_c30             2.443    0.562    1.708    3.876    0.789    0.937
##      Rhat    Prior       
##                          
##                          
##     1.002    normal(0,15)
##                          
##                          
##     1.006    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.658    0.407   -2.674   -1.103   -0.981   -0.981
##     Estrato           0.088    0.060   -0.019    0.214    0.161    0.080
##   CV_Gral ~                                                             
##     Salud      (c)    0.757    0.070    0.619    0.891    0.757    0.759
##     sintomas   (e)   -2.194    3.947  -11.707    5.917   -0.708   -0.375
##     funcionldd (d)   -0.555    2.396   -5.946    4.402   -0.303   -0.161
##     Nivel_dctv        0.147    0.186   -0.215    0.508    0.147    0.037
##   Salud ~                                                               
##     sintomas         -3.394    5.260  -15.586    5.610   -1.095   -0.578
##     funcionldd (b)    0.587    3.200   -6.712    6.343    0.321    0.169
##      Rhat    Prior       
##                          
##     1.004    normal(0,10)
##     1.004    normal(0,10)
##                          
##     1.002    normal(0,10)
##     1.004    normal(0,10)
##     1.003    normal(0,10)
##     1.000    normal(0,10)
##                          
##     1.004  normal(-10,10)
##     1.004    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.216    0.110    1.995    2.427    2.216    3.314
##    .F_c30             2.260    0.148    1.956    2.533    2.260    2.729
##    .S_br23            1.764    0.061    1.646    1.883    1.764    3.163
##    .S_c30             2.164    0.088    1.995    2.335    2.164    2.570
##    .CV_Gral           0.691    0.416   -0.138    1.545    0.691    0.366
##    .Salud             4.215    0.395    3.388    4.977    4.215    2.224
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.004    normal(0,32)
##     1.003    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     1.001    normal(0,10)
##     1.003    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.149    0.029    0.101    0.214    0.149    0.334
##    .F_c30             0.076    0.028    0.022    0.132    0.076    0.110
##    .S_br23            0.207    0.036    0.146    0.291    0.207    0.665
##    .S_c30             0.087    0.036    0.007    0.154    0.087    0.123
##    .CV_Gral           0.461    0.087    0.304    0.647    0.461    0.129
##    .Salud             1.599    0.294    1.095    2.256    1.599    0.445
##    .funcionalidad     0.009    0.013    0.000    0.048    0.032    0.032
##     sintomas          0.104    0.041    0.035    0.196    1.000    1.000
##      Rhat    Prior       
##     1.003 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MODCOMPUESTO 3.0 + 4.0  
blavCompare(fitref, fit3.0_4.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  914.226 
## 
## WAIC difference & SE: 
##    -0.150    1.697 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  914.475 
## 
## LOO difference & SE: 
##    -0.196    1.694 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    8.636
#Gana MODREF 
#MODELO 5.0 Situracion laboral

model_bayesiano5.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas + Situacion_laboral
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad 
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit5.0 <- bsem(
  model = model_bayesiano5.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 36.747 seconds (Warm-up)
## Chain 1:                60.525 seconds (Sampling)
## Chain 1:                97.272 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 38.904 seconds (Warm-up)
## Chain 2:                63.617 seconds (Sampling)
## Chain 2:                102.521 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 39.444 seconds (Warm-up)
## Chain 3:                59.411 seconds (Sampling)
## Chain 3:                98.855 seconds (Total)
## Chain 3: 
## Computing posterior predictives...
summary(fit5.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -524.753       0.194
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.538    0.813
##     F_c30             1.423    0.152    1.162    1.760    0.766    0.936
##   sintomas =~                                                           
##     S_br23            1.000                               0.333    0.591
##     S_c30             2.336    0.484    1.666    3.489    0.777    0.931
##      Rhat    Prior       
##                          
##                          
##     1.000    normal(0,15)
##                          
##                          
##     1.006    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.597    0.347   -2.428   -1.089   -0.987   -0.987
##     Sitcn_lbrl       -0.019    0.050   -0.124    0.080   -0.036   -0.018
##   CV_Gral ~                                                             
##     Salud      (c)    0.765    0.079    0.609    0.919    0.765    0.774
##     sintomas   (e)    0.736    6.023  -12.074   13.353    0.245    0.132
##     funcionldd (d)    1.159    3.813   -6.770    9.183    0.624    0.338
##   Salud ~                                                               
##     sintomas         -4.873    7.308  -20.324    8.656   -1.621   -0.867
##     funcionldd (b)   -0.428    4.601  -10.492    8.101   -0.230   -0.123
##      Rhat    Prior       
##                          
##     1.004    normal(0,10)
##     1.005    normal(0,10)
##                          
##     1.000    normal(0,10)
##     1.002    normal(0,10)
##     1.003    normal(0,10)
##                          
##     1.000  normal(-10,10)
##     1.001    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.374    0.107    2.169    2.584    2.374    3.587
##    .F_c30             2.481    0.141    2.205    2.751    2.481    3.031
##    .S_br23            1.765    0.064    1.642    1.887    1.765    3.136
##    .S_c30             2.163    0.090    1.984    2.342    2.163    2.592
##    .CV_Gral           0.908    0.386    0.189    1.683    0.908    0.491
##    .Salud             4.252    0.355    3.456    4.940    4.252    2.275
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.004    normal(0,32)
##     1.003    normal(0,32)
##     1.002    normal(0,32)
##     1.001    normal(0,32)
##     1.001    normal(0,10)
##     1.000    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.148    0.029    0.100    0.215    0.148    0.339
##    .F_c30             0.083    0.027    0.033    0.139    0.083    0.123
##    .S_br23            0.206    0.037    0.144    0.291    0.206    0.651
##    .S_c30             0.092    0.035    0.020    0.161    0.092    0.133
##    .CV_Gral           0.440    0.099    0.225    0.627    0.440    0.129
##    .Salud             1.552    0.327    0.936    2.244    1.552    0.444
##    .funcionalidad     0.008    0.011    0.000    0.042    0.026    0.026
##     sintomas          0.111    0.042    0.043    0.205    1.000    1.000
##      Rhat    Prior       
##     1.000 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.005 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD5.0 
blavCompare(fitref, fit5.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.

## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  915.641 
## 
## WAIC difference & SE: 
##    -0.857    0.681 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  916.026 
## 
## LOO difference & SE: 
##    -0.972    0.713 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    5.579
#Gana MOD5.0 5.366 ####  GANADOR A MOD REF 



#MODELO 6.0 Regimen de salud

model_bayesiano6.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas 
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad 
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad +Regimen_salud

  # residual correlations

'

fit6.0 <- bsem(
  model = model_bayesiano6.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 40.988 seconds (Warm-up)
## Chain 1:                74.163 seconds (Sampling)
## Chain 1:                115.151 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 47.772 seconds (Warm-up)
## Chain 2:                90.093 seconds (Sampling)
## Chain 2:                137.865 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 46.061 seconds (Warm-up)
## Chain 3:                94.596 seconds (Sampling)
## Chain 3:                140.657 seconds (Total)
## Chain 3:
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
## Computing posterior predictives...
summary(fit6.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -522.831       0.123
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.536    0.810
##     F_c30             1.437    0.152    1.177    1.763    0.770    0.939
##   sintomas =~                                                           
##     S_br23            1.000                               0.330    0.587
##     S_c30             2.354    0.477    1.673    3.503    0.778    0.931
##      Rhat    Prior       
##                          
##                          
##     0.999    normal(0,15)
##                          
##                          
##     1.000    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.602    0.339   -2.375   -1.103   -0.988   -0.988
##   CV_Gral ~                                                             
##     Salud      (c)    0.763    0.091    0.601    0.939    0.763    0.778
##     sintomas   (e)   -0.393    6.938  -14.810   14.189   -0.130   -0.070
##     funcionldd (d)    0.440    4.384   -8.943    9.354    0.236    0.128
##   Salud ~                                                               
##     sintomas         -5.258    8.354  -22.794   10.060   -1.738   -0.924
##     funcionldd (b)   -0.620    5.336  -11.814    9.545   -0.332   -0.177
##     Regimn_sld        0.283    0.316   -0.354    0.915    0.283    0.072
##      Rhat    Prior       
##                          
##     1.000    normal(0,10)
##                          
##     1.006    normal(0,10)
##     1.004    normal(0,10)
##     1.004    normal(0,10)
##                          
##     1.002  normal(-10,10)
##     1.002    normal(0,10)
##     0.999    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.342    0.074    2.197    2.486    2.342    3.540
##    .F_c30             2.439    0.090    2.257    2.620    2.439    2.973
##    .S_br23            1.764    0.064    1.641    1.894    1.764    3.135
##    .S_c30             2.163    0.093    1.973    2.346    2.163    2.589
##    .CV_Gral           0.792    0.405    0.039    1.542    0.792    0.430
##    .Salud             3.878    0.560    2.747    4.947    3.878    2.062
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.001    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.000    normal(0,32)
##     1.006    normal(0,10)
##     1.000    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.151    0.029    0.104    0.215    0.151    0.344
##    .F_c30             0.079    0.026    0.033    0.135    0.079    0.118
##    .S_br23            0.208    0.037    0.145    0.290    0.208    0.655
##    .S_c30             0.092    0.035    0.014    0.163    0.092    0.133
##    .CV_Gral           0.435    0.100    0.211    0.627    0.435    0.128
##    .Salud             1.530    0.330    0.843    2.195    1.530    0.432
##    .funcionalidad     0.007    0.011    0.000    0.039    0.025    0.025
##     sintomas          0.109    0.042    0.043    0.204    1.000    1.000
##      Rhat    Prior       
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.006 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.010 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD6.0 
blavCompare(fitref, fit6.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  915.09 
## 
## WAIC difference & SE: 
##    -0.581    0.948 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  915.447 
## 
## LOO difference & SE: 
##    -0.682    0.962 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    3.657
#Gana MODREF   3.451    ####  

#COMPARACION MOD5.0 VS MOD6.0
blavCompare(fit5.0, fit6.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.

## Warning: 
## 15 (18.8%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  915.641 
##  object2:  915.09 
## 
## WAIC difference & SE: 
##    -0.275    1.156 
## 
## LOO estimates: 
##  object1:  916.026 
##  object2:  915.447 
## 
## LOO difference & SE: 
##    -0.289    1.153 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):   -1.921
#Gana MOD6.0   -1.916     ####  

#MODELO COMPUESTO 5.0 + 6.0 (Situracion laboral + Regimen de salud)
model_bayesiano5.0_6.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas + Situacion_laboral
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad 
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad + Regimen_salud

  # residual correlations

'

fit5.0_6.0 <- bsem(
  model = model_bayesiano5.0_6.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0.001 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 50.725 seconds (Warm-up)
## Chain 1:                78.489 seconds (Sampling)
## Chain 1:                129.214 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 40.133 seconds (Warm-up)
## Chain 2:                59.135 seconds (Sampling)
## Chain 2:                99.268 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 41.795 seconds (Warm-up)
## Chain 3:                107.303 seconds (Sampling)
## Chain 3:                149.098 seconds (Total)
## Chain 3: 
## Computing posterior predictives...
summary(fit5.0_6.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -527.929       0.122
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.542    0.815
##     F_c30             1.423    0.151    1.160    1.761    0.771    0.939
##   sintomas =~                                                           
##     S_br23            1.000                               0.330    0.587
##     S_c30             2.366    0.526    1.672    3.615    0.780    0.931
##      Rhat    Prior       
##                          
##                          
##     1.000    normal(0,15)
##                          
##                          
##     1.007    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.622    0.376   -2.529   -1.091   -0.987   -0.987
##     Sitcn_lbrl       -0.018    0.053   -0.127    0.092   -0.034   -0.017
##   CV_Gral ~                                                             
##     Salud      (c)    0.767    0.083    0.609    0.935    0.767    0.775
##     sintomas   (e)    0.380    6.069  -12.551   12.617    0.125    0.067
##     funcionldd (d)    0.943    3.777   -7.217    8.695    0.511    0.272
##   Salud ~                                                               
##     sintomas         -5.094    7.417  -20.897    8.984   -1.680   -0.887
##     funcionldd (b)   -0.490    4.667  -10.517    8.569   -0.265   -0.140
##     Regimn_sld        0.300    0.317   -0.318    0.898    0.300    0.076
##      Rhat    Prior       
##                          
##     1.005    normal(0,10)
##     1.003    normal(0,10)
##                          
##     1.001    normal(0,10)
##     1.004    normal(0,10)
##     1.004    normal(0,10)
##                          
##     1.001  normal(-10,10)
##     1.001    normal(0,10)
##     1.001    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.369    0.111    2.143    2.583    2.369    3.562
##    .F_c30             2.475    0.148    2.168    2.759    2.475    3.013
##    .S_br23            1.766    0.063    1.639    1.886    1.766    3.146
##    .S_c30             2.166    0.089    1.987    2.341    2.166    2.583
##    .CV_Gral           0.898    0.394    0.120    1.673    0.898    0.479
##    .Salud             3.747    0.647    2.439    5.030    3.747    1.979
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.002    normal(0,32)
##     1.002    normal(0,32)
##     0.999    normal(0,32)
##     1.000    normal(0,32)
##     1.002    normal(0,10)
##     1.002    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.149    0.028    0.101    0.209    0.149    0.336
##    .F_c30             0.080    0.027    0.030    0.137    0.080    0.119
##    .S_br23            0.206    0.036    0.147    0.287    0.206    0.655
##    .S_c30             0.094    0.034    0.018    0.162    0.094    0.134
##    .CV_Gral           0.438    0.103    0.218    0.641    0.438    0.125
##    .Salud             1.551    0.316    0.974    2.239    1.551    0.433
##    .funcionalidad     0.008    0.011    0.000    0.042    0.026    0.026
##     sintomas          0.109    0.042    0.040    0.205    1.000    1.000
##      Rhat    Prior       
##     1.000 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MODCOMPUESTO 5.0 + 6.0  
blavCompare(fitref, fit5.0_6.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 16 (20.0%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  917.345 
## 
## WAIC difference & SE: 
##    -1.709    1.198 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  917.494 
## 
## LOO difference & SE: 
##    -1.705    1.197 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    8.755
#Gana 
#MODELO 7.0 Comorbilidad

model_bayesiano7.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas + Comorbilidad
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad 
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit7.0 <- bsem(
  model = model_bayesiano7.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 28.307 seconds (Warm-up)
## Chain 1:                74.787 seconds (Sampling)
## Chain 1:                103.094 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0.001 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 42.101 seconds (Warm-up)
## Chain 2:                81.058 seconds (Sampling)
## Chain 2:                123.159 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 38.138 seconds (Warm-up)
## Chain 3:                80.093 seconds (Sampling)
## Chain 3:                118.231 seconds (Total)
## Chain 3:
## Warning: There were 2 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: There were 3 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 10. See
## https://mc-stan.org/misc/warnings.html#maximum-treedepth-exceeded
## Warning: Examine the pairs() plot to diagnose sampling problems
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess
## Computing posterior predictives...
## Warning: blavaan WARNING: Small effective sample sizes (< 100) for some
## parameters.
summary(fit7.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -560.082       0.156
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.541    0.813
##     F_c30             1.407    0.146    1.148    1.712    0.761    0.931
##   sintomas =~                                                           
##     S_br23            1.000                               0.340    0.600
##     S_c30             2.286    0.437    1.638    3.360    0.776    0.930
##      Rhat    Prior       
##                          
##                          
##     0.999    normal(0,15)
##                          
##                          
##     1.004    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.580    0.320   -2.351   -1.084   -0.991   -0.991
##     Comorbildd        0.027    0.091   -0.127    0.180    0.049    0.023
##   CV_Gral ~                                                             
##     Salud      (c)    0.676    0.135    0.340    0.860    0.676    0.687
##     sintomas   (e)   -0.738    7.251  -15.716   11.533   -0.251   -0.139
##     funcionldd (d)    0.519    4.628   -8.623    8.892    0.281    0.156
##   Salud ~                                                               
##     sintomas         -2.996   11.556  -24.548   14.344   -1.017   -0.555
##     funcionldd (b)    0.755    7.465  -13.323   12.007    0.408    0.223
##      Rhat    Prior       
##                          
##     1.000    normal(0,10)
##     1.046    normal(0,10)
##                          
##     1.010    normal(0,10)
##     1.039    normal(0,10)
##     1.037    normal(0,10)
##                          
##     1.039  normal(-10,10)
##     1.035    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.299    0.167    2.003    2.601    2.299    3.456
##    .F_c30             2.374    0.228    1.972    2.784    2.374    2.902
##    .S_br23            1.765    0.063    1.643    1.887    1.765    3.120
##    .S_c30             2.163    0.088    1.987    2.330    2.163    2.591
##    .CV_Gral           0.706    0.463   -0.069    1.706    0.706    0.392
##    .Salud             3.437    0.592    2.195    4.499    3.437    1.876
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.037    normal(0,32)
##     1.038    normal(0,32)
##     1.002    normal(0,32)
##     1.000    normal(0,32)
##     1.008    normal(0,10)
##     1.010    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.150    0.030    0.101    0.217    0.150    0.338
##    .F_c30             0.090    0.026    0.044    0.145    0.090    0.134
##    .S_br23            0.205    0.037    0.146    0.290    0.205    0.640
##    .S_c30             0.094    0.036    0.006    0.164    0.094    0.135
##    .CV_Gral           0.412    0.106    0.163    0.605    0.412    0.127
##    .Salud             1.332    0.356    0.533    2.002    1.332    0.397
##    .funcionalidad     0.005    0.007    0.000    0.025    0.017    0.017
##     sintomas          0.115    0.043    0.046    0.213    1.000    1.000
##      Rhat    Prior       
##     1.004 gamma(1,.5)[sd]
##     1.004 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.030 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.017 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD7.0 
blavCompare(fitref, fit7.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 17 (21.2%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  911.13 
## 
## WAIC difference & SE: 
##    -1.399    2.247 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  911.281 
## 
## LOO difference & SE: 
##    -1.401    2.256 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):   40.908
#Gana 



#MODELO 8.0 Estado_del_tumor

model_bayesiano8.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas 
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad + Estado_del_tumor
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad

  # residual correlations

'

fit8.0 <- bsem(
  model = model_bayesiano8.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0.001 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 39.266 seconds (Warm-up)
## Chain 1:                62.839 seconds (Sampling)
## Chain 1:                102.105 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 40.059 seconds (Warm-up)
## Chain 2:                98.515 seconds (Sampling)
## Chain 2:                138.574 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 45.273 seconds (Warm-up)
## Chain 3:                83.996 seconds (Sampling)
## Chain 3:                129.269 seconds (Total)
## Chain 3:
## Warning: There were 1 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 10. See
## https://mc-stan.org/misc/warnings.html#maximum-treedepth-exceeded
## Warning: Examine the pairs() plot to diagnose sampling problems
## Computing posterior predictives...
summary(fit8.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -523.484       0.140
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.535    0.809
##     F_c30             1.443    0.164    1.161    1.822    0.772    0.939
##   sintomas =~                                                           
##     S_br23            1.000                               0.329    0.586
##     S_c30             2.364    0.483    1.692    3.502    0.779    0.931
##      Rhat    Prior       
##                          
##                          
##     1.000    normal(0,15)
##                          
##                          
##     1.001    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.605    0.344   -2.390   -1.093   -0.988   -0.988
##   CV_Gral ~                                                             
##     Salud      (c)    0.754    0.080    0.596    0.911    0.754    0.757
##     sintomas   (e)   -0.820    7.027  -15.022   13.483   -0.270   -0.146
##     funcionldd (d)    0.264    4.402   -8.566    9.549    0.141    0.076
##     Estd_dl_tm       -0.160    0.167   -0.496    0.163   -0.160   -0.041
##   Salud ~                                                               
##     sintomas         -5.204    8.234  -22.638   10.553   -1.714   -0.919
##     funcionldd (b)   -0.614    5.272  -11.517    9.675   -0.328   -0.176
##      Rhat    Prior       
##                          
##     1.002    normal(0,10)
##                          
##     1.000    normal(0,10)
##     1.000    normal(0,10)
##     1.000    normal(0,10)
##     1.000    normal(0,10)
##                          
##     1.009  normal(-10,10)
##     1.008    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.343    0.072    2.202    2.483    2.343    3.542
##    .F_c30             2.438    0.088    2.265    2.610    2.438    2.964
##    .S_br23            1.763    0.064    1.638    1.883    1.763    3.138
##    .S_c30             2.163    0.092    1.979    2.342    2.163    2.586
##    .CV_Gral           1.044    0.422    0.226    1.896    1.044    0.563
##    .Salud             4.339    0.207    3.945    4.748    4.339    2.327
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.003    normal(0,32)
##     1.003    normal(0,32)
##     1.001    normal(0,32)
##     1.004    normal(0,32)
##     1.000    normal(0,10)
##     1.003    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.151    0.030    0.102    0.219    0.151    0.346
##    .F_c30             0.081    0.028    0.027    0.140    0.081    0.119
##    .S_br23            0.207    0.036    0.146    0.289    0.207    0.656
##    .S_c30             0.093    0.034    0.020    0.158    0.093    0.133
##    .CV_Gral           0.437    0.096    0.241    0.620    0.437    0.127
##    .Salud             1.542    0.337    0.909    2.240    1.542    0.444
##    .funcionalidad     0.007    0.011    0.000    0.040    0.023    0.023
##     sintomas          0.108    0.041    0.043    0.202    1.000    1.000
##      Rhat    Prior       
##     1.001 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.005 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
##     1.011 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MOD8.0 
blavCompare(fitref, fit8.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.

## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  915.733 
## 
## WAIC difference & SE: 
##    -0.903    1.001 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  916.152 
## 
## LOO difference & SE: 
##    -1.035    1.000 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):    4.309
#Gana

#MODELO COMPUESTO 7.0 + 8.0 (Comorbilidad +  Estado del tumor)
model_bayesiano7.0_8.0 <- '
  # measurement model
    funcionalidad =~
        prior("normal(0,15)")*F_br23 + prior("normal(0,15)")*F_c30
    sintomas =~
        prior("normal(0,15)")*S_br23 + prior("normal(0,15)")*S_c30

  # regressions
    funcionalidad ~ a*sintomas + Comorbilidad
    CV_Gral ~ c*Salud + e*sintomas + d*prior("normal(0,15)")*funcionalidad + Estado_del_tumor
    Salud ~ prior("normal(-10,10)")*sintomas + b*funcionalidad 

  # residual correlations

'

fit7.0_8.0 <- bsem(
  model = model_bayesiano7.0_8.0,
  data = datos,
  auto.var = TRUE,
  auto.fix.first = TRUE,
  auto.cov.lv.x = TRUE)
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1).
## Chain 1: 
## Chain 1: Gradient evaluation took 0.001 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 41.225 seconds (Warm-up)
## Chain 1:                78.018 seconds (Sampling)
## Chain 1:                119.243 seconds (Total)
## Chain 1: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2).
## Chain 2: 
## Chain 2: Gradient evaluation took 0.001 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 10 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: 46.377 seconds (Warm-up)
## Chain 2:                73.259 seconds (Sampling)
## Chain 2:                119.636 seconds (Total)
## Chain 2: 
## 
## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3).
## Chain 3: 
## Chain 3: Gradient evaluation took 0 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0 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: 44.732 seconds (Warm-up)
## Chain 3:                85.343 seconds (Sampling)
## Chain 3:                130.075 seconds (Total)
## Chain 3:
## Warning: The largest R-hat is 1.06, indicating chains have not mixed.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#r-hat
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#bulk-ess
## Computing posterior predictives...
## Warning: blavaan WARNING: Small effective sample sizes (< 100) for some
## parameters.
summary(fit7.0_8.0,standardized = TRUE)
## blavaan (0.4-1) results of 1000 samples after 500 adapt/burnin iterations
## 
##   Number of observations                            80
## 
##   Number of missing patterns                         1
## 
##   Statistic                                 MargLogLik         PPP
##   Value                                       -558.320       0.108
## 
## Latent Variables:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad =~                                                      
##     F_br23            1.000                               0.542    0.814
##     F_c30             1.409    0.157    1.145    1.755    0.763    0.931
##   sintomas =~                                                           
##     S_br23            1.000                               0.341    0.603
##     S_c30             2.265    0.429    1.629    3.318    0.773    0.930
##      Rhat    Prior       
##                          
##                          
##     1.001    normal(0,15)
##                          
##                          
##     1.001    normal(0,15)
## 
## Regressions:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##   funcionalidad ~                                                       
##     sintomas   (a)   -1.574    0.321   -2.344   -1.080   -0.992   -0.992
##     Comorbildd        0.038    0.089   -0.124    0.184    0.070    0.033
##   CV_Gral ~                                                             
##     Salud      (c)    0.678    0.115    0.384    0.854    0.678    0.679
##     sintomas   (e)    0.392    6.892  -14.293   12.393    0.134    0.072
##     funcionldd (d)    1.289    4.464   -7.662    9.680    0.698    0.378
##     Estd_dl_tm       -0.171    0.173   -0.509    0.174   -0.171   -0.044
##   Salud ~                                                               
##     sintomas         -1.310   11.275  -24.413   14.875   -0.447   -0.242
##     funcionldd (b)    1.842    7.307  -13.557   12.100    0.998    0.539
##      Rhat    Prior       
##                          
##     1.002    normal(0,10)
##     1.072    normal(0,10)
##                          
##     1.001    normal(0,10)
##     1.038    normal(0,10)
##     1.038    normal(0,10)
##     1.000    normal(0,10)
##                          
##     1.069  normal(-10,10)
##     1.068    normal(0,10)
## 
## Intercepts:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            2.279    0.167    1.993    2.599    2.279    3.424
##    .F_c30             2.347    0.225    1.972    2.771    2.347    2.861
##    .S_br23            1.766    0.062    1.646    1.883    1.766    3.119
##    .S_c30             2.164    0.088    1.988    2.333    2.164    2.602
##    .CV_Gral           0.897    0.456    0.075    1.875    0.897    0.485
##    .Salud             3.408    0.618    2.155    4.498    3.408    1.841
##    .funcionalidad     0.000                               0.000    0.000
##     sintomas          0.000                               0.000    0.000
##      Rhat    Prior       
##     1.059    normal(0,32)
##     1.059    normal(0,32)
##     1.001    normal(0,32)
##     1.001    normal(0,32)
##     1.002    normal(0,10)
##     1.008    normal(0,10)
##                          
##                          
## 
## Variances:
##                    Estimate  Post.SD pi.lower pi.upper   Std.lv  Std.all
##    .F_br23            0.150    0.029    0.102    0.214    0.150    0.338
##    .F_c30             0.090    0.028    0.041    0.151    0.090    0.134
##    .S_br23            0.204    0.035    0.147    0.284    0.204    0.637
##    .S_c30             0.094    0.032    0.033    0.160    0.094    0.136
##    .CV_Gral           0.411    0.107    0.155    0.607    0.411    0.120
##    .Salud             1.344    0.340    0.547    1.998    1.344    0.393
##    .funcionalidad     0.004    0.007    0.000    0.021    0.015    0.015
##     sintomas          0.117    0.042    0.048    0.211    1.000    1.000
##      Rhat    Prior       
##     1.005 gamma(1,.5)[sd]
##     1.003 gamma(1,.5)[sd]
##     1.001 gamma(1,.5)[sd]
##     1.008 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.002 gamma(1,.5)[sd]
##     1.007 gamma(1,.5)[sd]
##     1.000 gamma(1,.5)[sd]
#COMPARACION MODREF Vs MODCOMPUESTO 7.0 + 8.0  
blavCompare(fitref, fit7.0_8.0)
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: Some Pareto k diagnostic values are slightly high. See help('pareto-k-diagnostic') for details.
## Warning: 
## 14 (17.5%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## Warning: 
## 17 (21.2%) p_waic estimates greater than 0.4. We recommend trying loo instead.
## 
## WAIC estimates: 
##  object1:  913.927 
##  object2:  912.246 
## 
## WAIC difference & SE: 
##    -0.841    2.724 
## 
## LOO estimates: 
##  object1:  914.083 
##  object2:  912.529 
## 
## LOO difference & SE: 
##    -0.777    2.738 
## 
## Laplace approximation to the log-Bayes factor
## (experimental; positive values favor object1):   39.146
#Gana