class: center, middle, inverse, title-slide .title[ # 10 Pasos del Checklist WAMBS ] .subtitle[ ## When to worry and how to Avoid the Misuse of Bayesian Statistics ] .author[ ### Dr. José Ventura-León ] .date[ ### 2024-03-05 ] --- --- # PASO PREVIO: Cargamos la base de datos e invertimos los items ``` r df_new <- read_excel("Autoestima_Data.xlsx") df_new <- invertir_items(df_new, items = c("RSE2", "RSE5", "RSE8", "RSE9", "RSE10"), num_respuestas = 4, comienza_con_cero = FALSE) ``` --- # PASO 1: Especificar y entender los priors (utilizando los priors por defecto) En este paso se revisa la configuración de los priors por defecto que utiliza blavaan. La función dpriors() muestra los parámetros de los priors que se aplicarán al modelo. NOTA: Al no especificar un argumento "dp", se utilizan los priors por defecto. Es fundamental conocer y justificar los priors utilizados, ya que su especificación puede influir notablemente en los resultados de la estimación Bayesiana. Según la WAMBS-checklist, se recomienda: - Documentar la forma y los hiperparámetros de cada prior. - Justificar la elección de usar priors por defecto (o específicos) con base en el conocimiento teórico o estudios previos. Esta revisión contribuye a la transparencia y replicabilidad del análisis. --- ``` r dpriors() ``` ``` ## nu alpha lambda beta ## "normal(0,32)" "normal(0,10)" "normal(0,10)" "normal(0,10)" ## theta psi rho ibpsi ## "gamma(1,.5)[sd]" "gamma(1,.5)[sd]" "beta(1,1)" "wishart(3,iden)" ## tau ## "normal(0,1.5)" ``` --- # PASO 2: Estimar el Modelo (configuración inicial con priors por defecto) En este paso definimos el modelo de medida para un análisis factorial confirmatorio enmarcado en una estimación Bayesiana (BCFA) y lo ajustamos usando los priors por defecto. NOTA: Según la WAMBS-checklist (Depaoli & van de Schoot), es fundamental documentar: - La especificación del modelo (variables latentes e indicadores). - Los parámetros del algoritmo MCMC: número de cadenas, iteraciones de burn-in y muestreo. - La semilla de aleatorización para asegurar la reproducibilidad. --- # PASO 2: Estimar el Modelo (configuración inicial con priors por defecto) ``` r # Modelo: Se asume un factor latente "F1" que se carga sobre 10 indicadores (RSE1 a RSE10). model1 <- "F1 =~ RSE1 + RSE2 + RSE3 + RSE4 + RSE5 + RSE6 + RSE7 + RSE8 + RSE9 + RSE10" # Ajuste del modelo mediante la función bcfa (deblavaan u otro paquete similar) # Configuramos 3 cadenas MCMC, 1000 iteraciones para burn-in y 1000 para el muestreo posterior. # La semilla se fija para permitir la reproducibilidad de los resultados. fit1_default <- bcfa(model1, data = df_new, n.chains = 3, # Número de cadenas MCMC burnin = 1000, # Número de iteraciones descartadas (burn-in) sample = 1000, # Número de iteraciones utilizadas para el muestreo posterior seed = 12345, verbose = F) # Semilla para la reproducibilidad ``` ``` ## ## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 1). ## Chain 1: ## Chain 1: Gradient evaluation took 0.000293 seconds ## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 2.93 seconds. ## Chain 1: Adjust your expectations accordingly! ## Chain 1: ## Chain 1: ## Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup) ## Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup) ## Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup) ## Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup) ## Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup) ## Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup) ## Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling) ## Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling) ## Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling) ## Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling) ## Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling) ## Chain 1: Iteration: 2000 / 2000 [100%] (Sampling) ## Chain 1: ## Chain 1: Elapsed Time: 2.3 seconds (Warm-up) ## Chain 1: 2.657 seconds (Sampling) ## Chain 1: 4.957 seconds (Total) ## Chain 1: ## ## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 2). ## Chain 2: ## Chain 2: Gradient evaluation took 0.000172 seconds ## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 1.72 seconds. ## Chain 2: Adjust your expectations accordingly! ## Chain 2: ## Chain 2: ## Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup) ## Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup) ## Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup) ## Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup) ## Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup) ## Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup) ## Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling) ## Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling) ## Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling) ## Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling) ## Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling) ## Chain 2: Iteration: 2000 / 2000 [100%] (Sampling) ## Chain 2: ## Chain 2: Elapsed Time: 2.302 seconds (Warm-up) ## Chain 2: 2.443 seconds (Sampling) ## Chain 2: 4.745 seconds (Total) ## Chain 2: ## ## SAMPLING FOR MODEL 'stanmarg' NOW (CHAIN 3). ## Chain 3: ## Chain 3: Gradient evaluation took 0.000172 seconds ## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 1.72 seconds. ## Chain 3: Adjust your expectations accordingly! ## Chain 3: ## Chain 3: ## Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup) ## Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup) ## Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup) ## Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup) ## Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup) ## Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup) ## Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling) ## Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling) ## Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling) ## Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling) ## Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling) ## Chain 3: Iteration: 2000 / 2000 [100%] (Sampling) ## Chain 3: ## Chain 3: Elapsed Time: 2.324 seconds (Warm-up) ## Chain 3: 2.152 seconds (Sampling) ## Chain 3: 4.476 seconds (Total) ## Chain 3: ## Computing post-estimation metrics (including lvs if requested)... ``` ``` r # Visualización de un resumen del modelo: # Se muestran los parámetros estimados y, opcionalmente, se incluyen los coeficientes estandarizados. summary(fit1_default, standardized = TRUE) ``` ``` ## blavaan 0.5.6 ended normally after 1000 iterations ## ## Estimator BAYES ## Optimization method MCMC ## Number of model parameters 20 ## ## Number of observations 500 ## ## Statistic MargLogLik PPP ## Value -5430.199 0.000 ## ## Parameter Estimates: ## ## ## Latent Variables: ## Estimate Post.SD pi.lower pi.upper Std.lv Std.all ## F1 =~ ## RSE1 1.000 0.431 0.580 ## RSE2 1.377 0.134 1.144 1.668 0.594 0.728 ## RSE3 0.605 0.078 0.467 0.767 0.261 0.430 ## RSE4 0.999 0.097 0.817 1.207 0.431 0.611 ## RSE5 0.960 0.128 0.726 1.230 0.414 0.443 ## RSE6 1.152 0.109 0.958 1.394 0.497 0.666 ## RSE7 1.122 0.106 0.932 1.357 0.484 0.658 ## RSE8 0.273 0.102 0.077 0.477 0.118 0.134 ## RSE9 1.282 0.141 1.033 1.584 0.553 0.585 ## RSE10 1.598 0.157 1.327 1.930 0.689 0.710 ## Rhat Prior ## ## ## 1.005 normal(0,10) ## 1.004 normal(0,10) ## 1.004 normal(0,10) ## 1.001 normal(0,10) ## 1.003 normal(0,10) ## 1.004 normal(0,10) ## 1.000 normal(0,10) ## 1.003 normal(0,10) ## 1.005 normal(0,10) ## ## Variances: ## Estimate Post.SD pi.lower pi.upper Std.lv Std.all ## .RSE1 0.366 0.027 0.318 0.423 0.366 0.663 ## .RSE2 0.313 0.026 0.267 0.368 0.313 0.470 ## .RSE3 0.301 0.020 0.264 0.343 0.301 0.815 ## .RSE4 0.312 0.023 0.269 0.359 0.312 0.627 ## .RSE5 0.702 0.047 0.616 0.801 0.702 0.804 ## .RSE6 0.309 0.023 0.268 0.355 0.309 0.556 ## .RSE7 0.306 0.023 0.264 0.355 0.306 0.566 ## .RSE8 0.755 0.049 0.663 0.856 0.755 0.982 ## .RSE9 0.589 0.044 0.507 0.681 0.589 0.658 ## .RSE10 0.468 0.038 0.397 0.548 0.468 0.496 ## F1 0.186 0.031 0.130 0.250 1.000 1.000 ## Rhat Prior ## 1.002 gamma(1,.5)[sd] ## 1.000 gamma(1,.5)[sd] ## 0.999 gamma(1,.5)[sd] ## 1.002 gamma(1,.5)[sd] ## 0.999 gamma(1,.5)[sd] ## 0.999 gamma(1,.5)[sd] ## 0.999 gamma(1,.5)[sd] ## 1.000 gamma(1,.5)[sd] ## 1.000 gamma(1,.5)[sd] ## 1.000 gamma(1,.5)[sd] ## 1.002 gamma(1,.5)[sd] ```