Skip to main content
Applied Psychological Measurement logoLink to Applied Psychological Measurement
. 2022 Jan 9;46(2):159–161. doi: 10.1177/01466216211063233

SEMsens: An R Package for Sensitivity Analysis of Structural Equation Models With the Ant Colony Optimization Algorithm

Zuchao Shen 1,2,, Walter L Leite 1,2
PMCID: PMC8908408  PMID: 35281342

The SEMsens package (Leite & Shen, 2021) for the R statistical software (R Core Team, 2021) implements the framework proposed by Leite et al. (in press) to conduct sensitivity analysis for structural equation modeling (SEM) against a potential missing confounder using the ant colony optimization (ACO) algorithm. A potential missing confounder is specified as a phantom variable, a latent variable without manifest indicators, such that the sensitivity of SEM can be assessed through comparing results from models with and without the phantom variable (Harring et al., 2017). The current SEMsens package can provide results and summary tables of sensitivity analysis for SEM with respect to the objective functions pre-coded in the package, such as objective functions based on p-values, parameter estimates, and model fit, or customized by users. The automation method works by sampling different phantom variables with probabilities according to the rank of solutions to maximize the objective function with the use of the ant colony optimization algorithm for continuous domains (Socha & Dorigo, 2008).

The SEMsens package investigates problems for external model misspecification (Kaplan, 1990) by allowing researchers to understand the extent that each path coefficient in a model is vulnerable to a potential omitted confounder. If the magnitude or p-value of a path coefficient is found to be likely to change substantially if a weak or moderate confounder is included, researchers can consult theory to review the possibility of such a confounder and possibly expand the model in future studies. If only strong confounders would change the conclusions for the model, that provides additional evidence for the validity of the model.

Currently, the package is designed to work with SEM models with raw data or sample variance covariance matrices, estimating SEM models through the lavaan package in R (Rosseel, 2012). The main function of the SEMsens package is the sa.aco function, performing sensitivity analysis for an SEM model following the procedures outlined in Leite et al. (in press). The output of this function includes the model results for the analytical model and results of all sensitivity analysis models associated with all sets of sensitivity parameters. The algorithm will stop at maximum number of iterations, or convergence solutions if any, or targeted maximum optimal values if possible.

The sens.tables function summarizes the sensitivity analysis results provided by the sa. aco function. The sens.tables function provides five summary tables. The first table provides the average estimation of results for models with and without sensitivity parameters across all iterations. The second table provides the summary of sensitivity parameters. The third table summarizes the values of sensitivity parameters that result in the minimum path coefficient estimation in a sensitivity analysis model across all iterations. The fourth table provides the values of sensitivity parameters that lead to the maximum path coefficient estimation in a sensitivity analysis model across all iterations. The fifth table provides sensitivity parameters that lead to a change of significance for each path of the analytical model, if any.

SEMsens is freely available on the Comprehensive R Archive Network (CRAN) at http://www.cran.r-project.org. Users can install it through R (R Core Team, 2021) or RStudio (RStudio Team, 2021) by running install.packages (“SEMsens”). Detailed function options and examples are documented in the package manual, which is also available on CRAN. Windows, Mac, and Linux users can access the package by downloading and installing a proper version of R and/or RStudio.

Footnotes

Declaration of conflicting interests: The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.

Funding: The author(s) received no financial support for the research, authorship, and/or publication of this article.

ORCID iDs

Zuchao Shen https://orcid.org/0000-0003-3483-0451

Walter L. Leite https://orcid.org/0000-0001-7655-5668

References

  1. Harring J. R., McNeish D. M., Hancock G. R. (2017). Using phantom variables in structural equation modeling to assess model sensitivity to external misspecification. Psychological Methods, 22(4), 616–631. 10.1037/met0000103 [DOI] [PubMed] [Google Scholar]
  2. Kaplan D. (1990). Evaluating and modifying covariance structure models: A review and recommendation. Multivariate Behavioral Research, 25(2), 137–155. 10.1207/s15327906mbr2502_1 [DOI] [PubMed] [Google Scholar]
  3. Leite W., Shen Z. (2021). SEMsens: A tool for sensitivity analysis in structural equation modeling. Available from: https://cran.r-project.org/package=SEMsens, Version 1.0.1[Software]. [DOI] [PMC free article] [PubMed] [Google Scholar]
  4. Leite W., Shen Z., Marcoulides K., Fish C., Harring J. (in press). Using ant colony optimization for sensitivity analysis in structural equation modeling. Structural Equation Modeling: A Multidisciplinary Journal. 10.1080/10705511.2021.1881786 [DOI] [Google Scholar]
  5. R Core Team (2021). R: A language and environment for statistical computing. R Foundation for Statistical Computing. Available from: http://www.R-project.org [Google Scholar]
  6. Rosseel Y. (2012). Lavaan: An R package for structural equation modeling and more. version 0.5–12 (BETA). Journal of Statistical Software, 48(2), 1–36. 10.18637/jss.v048.i02 [DOI] [Google Scholar]
  7. RStudio Team (2021). RStudio. Integrated Development for R. RStudio, PBC. http://www.rstudio.com/ [Google Scholar]
  8. Socha K., Dorigo M. (2008). Ant colony optimization for continuous domains. European Journal of Operational Research, 185(3), 1155–1173. 10.1016/j.ejor.2006.06.046 [DOI] [Google Scholar]

Articles from Applied Psychological Measurement are provided here courtesy of SAGE Publications

RESOURCES