semboottools::standardizedSolution_boot

library(semboottools)
library(lavaan)

Function Syntax

standardizedSolution_boot(object,
                          level = .95,
                          type = "std.all",
                          boot_delta_ratio = FALSE,
                          boot_ci_type = c("perc", "bc", "bca.simple"),
                          save_boot_est_std = TRUE,
                          boot_pvalue = TRUE,
                          boot_pvalue_min_size = 1000,
                          ...)

Arguments

Argument Description
object A model fitted by lavaan.
level Confidence level for the confidence intervals. For example, .95 gives 95% confidence intervals.
type Type of standardized coefficients. Same as in lavaan::standardizedSolution(), such as "std.all" or "std.lv".
boot_delta_ratio Whether to calculate how wide the bootstrap confidence interval is compared to the usual confidence interval (delta method). Useful for comparing both methods.
boot_ci_type Method for forming bootstrap confidence intervals. "perc" gives percentile intervals; "bc" and "bca.simple" give bias-corrected intervals.
save_boot_est_std Whether to save the bootstrap estimates of standardized coefficients in the result. Saved in the attribute boot_est_std if TRUE.
boot_pvalue Whether to compute asymmetric p-values based on bootstrap results. Only available when percentile confidence intervals are used.
boot_pvalue_min_size Minimum number of valid bootstrap samples needed to compute asymmetric p-values. If fewer samples are available, p-values will not be computed and will be shown as NA.
... Additional arguments passed to lavaan::standardizedSolution().

Example

Data and Model

# Set seed for reproducibility
set.seed(1234)

# Generate data
n <- 1000
x <- runif(n) - 0.5
m <- 0.20 * x + rnorm(n)
y <- 0.17 * m + rnorm(n)
dat <- data.frame(x, y, m)

# Specify mediation model in lavaan syntax
mod <- '
  m ~ a * x
  y ~ b * m + cp * x
  ab := a * b
  total := a * b + cp
'

Basic usage: default settings

# (should use ≥2000 in real studies)
fit <- sem(mod, data = dat, se = "boot", bootstrap = 500)
#> Warning: lavaan->lav_model_nvcov_bootstrap():  
#>    2 bootstrap runs failed or did not converge.
std_boot <- standardizedSolution_boot(fit)
#> Warning in standardizedSolution_boot(fit): The number of bootstrap samples
#> (498) is less than 'boot_pvalue_min_size' (1000). Bootstrap p-values are not
#> computed.
print(std_boot)
#> 
#> Bootstrapping:
#>                                     
#>  Valid Bootstrap Samples: 498       
#>  Level of Confidence:     95.0%     
#>  CI Type:                 Percentile
#>  Standardization Type:    std.all   
#> 
#> Parameter Estimates Settings:
#>                                                 
#>  Standard errors:                      Bootstrap
#>  Number of requested bootstrap draws:  500      
#>  Number of successful bootstrap draws: 498      
#> 
#> Regressions:
#>                   Std    SE     p  CI.Lo CI.Up   bSE bCI.Lo bCI.Up
#>  m ~                                                              
#>   x (a)         0.027 0.034 0.425 -0.040 0.095 0.035 -0.047  0.088
#>  y ~                                                              
#>   m (b)         0.174 0.032 0.000  0.111 0.237 0.032  0.108  0.237
#>   x (cp)       -0.005 0.032 0.873 -0.067 0.057 0.032 -0.068  0.059
#> 
#> Variances:
#>                   Std    SE     p  CI.Lo CI.Up   bSE bCI.Lo bCI.Up
#>   .m            0.999 0.002 0.000  0.996 1.003 0.002  0.992  1.000
#>   .y            0.970 0.011 0.000  0.948 0.992 0.011  0.944  0.986
#>    x            1.000                                             
#> 
#> Defined Parameters:
#>                   Std    SE     p  CI.Lo CI.Up   bSE bCI.Lo bCI.Up
#>  ab (ab)        0.005 0.006 0.428 -0.007 0.017 0.006 -0.008  0.017
#>  total (total) -0.000 0.033 0.993 -0.065 0.064 0.033 -0.066  0.065
#> 
#> Footnote:
#> - Std: Standardized estimates.
#> - SE: Delta method standard errors.
#> - p: Delta method p-values.
#> - CI.Lo, CI.Up: Delta method confidence intervals.
#> - bSE: Bootstrap standard errors.
#> - bCI.Lo, bCI.Up: Bootstrap confidence intervals.
# this function also do not require 'se = "boot"' when fitting the model
fit2 <- sem(mod, data = dat, fixed.x = FALSE)
fit2 <- store_boot(fit2, R = 500)
std_boot2 <- standardizedSolution_boot(fit2)
#> Warning in standardizedSolution_boot(fit2): The number of bootstrap samples
#> (500) is less than 'boot_pvalue_min_size' (1000). Bootstrap p-values are not
#> computed.
print(std_boot)
#> 
#> Bootstrapping:
#>                                     
#>  Valid Bootstrap Samples: 498       
#>  Level of Confidence:     95.0%     
#>  CI Type:                 Percentile
#>  Standardization Type:    std.all   
#> 
#> Parameter Estimates Settings:
#>                                                 
#>  Standard errors:                      Bootstrap
#>  Number of requested bootstrap draws:  500      
#>  Number of successful bootstrap draws: 498      
#> 
#> Regressions:
#>                   Std    SE     p  CI.Lo CI.Up   bSE bCI.Lo bCI.Up
#>  m ~                                                              
#>   x (a)         0.027 0.034 0.425 -0.040 0.095 0.035 -0.047  0.088
#>  y ~                                                              
#>   m (b)         0.174 0.032 0.000  0.111 0.237 0.032  0.108  0.237
#>   x (cp)       -0.005 0.032 0.873 -0.067 0.057 0.032 -0.068  0.059
#> 
#> Variances:
#>                   Std    SE     p  CI.Lo CI.Up   bSE bCI.Lo bCI.Up
#>   .m            0.999 0.002 0.000  0.996 1.003 0.002  0.992  1.000
#>   .y            0.970 0.011 0.000  0.948 0.992 0.011  0.944  0.986
#>    x            1.000                                             
#> 
#> Defined Parameters:
#>                   Std    SE     p  CI.Lo CI.Up   bSE bCI.Lo bCI.Up
#>  ab (ab)        0.005 0.006 0.428 -0.007 0.017 0.006 -0.008  0.017
#>  total (total) -0.000 0.033 0.993 -0.065 0.064 0.033 -0.066  0.065
#> 
#> Footnote:
#> - Std: Standardized estimates.
#> - SE: Delta method standard errors.
#> - p: Delta method p-values.
#> - CI.Lo, CI.Up: Delta method confidence intervals.
#> - bSE: Bootstrap standard errors.
#> - bCI.Lo, bCI.Up: Bootstrap confidence intervals.

standardizedSolution_boot(): Different Options

# Change confidence level
std_boot <- standardizedSolution_boot(fit, level = 0.99)
# Use bias-corrected bootstrap CIs
std_boot <- standardizedSolution_boot(fit, boot_ci_type = "bc")
std_boot <- standardizedSolution_boot(fit, boot_ci_type = "bca.simple")
# Compute delta ratio
std_boot <- standardizedSolution_boot(fit, boot_delta_ratio = TRUE)
# Do not save bootstrap estimates
std_boot <- standardizedSolution_boot(fit, save_boot_est_std = FALSE)
# Turn off asymmetric bootstrap p-values
std_boot <- standardizedSolution_boot(fit, boot_pvalue = FALSE)
# Combine options
std_boot <- standardizedSolution_boot(fit,
                                      boot_ci_type = "bc",
                                      boot_delta_ratio = TRUE)