{"id":16178656,"url":"https://github.com/jeksterslab/semmcci","last_synced_at":"2025-10-11T11:16:12.931Z","repository":{"id":59227917,"uuid":"348347880","full_name":"jeksterslab/semmcci","owner":"jeksterslab","description":"semmcci: Monte Carlo Confidence Intervals in Structural Equation Modeling","archived":false,"fork":false,"pushed_at":"2025-07-22T19:00:42.000Z","size":55254,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-06T15:46:53.397Z","etag":null,"topics":["confidence-intervals","monte-carlo","r","r-package","structural-equation-modeling"],"latest_commit_sha":null,"homepage":"https://jeksterslab.github.io/semmcci/","language":"TeX","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeksterslab.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-03-16T12:56:55.000Z","updated_at":"2025-07-22T18:50:26.000Z","dependencies_parsed_at":"2025-04-11T16:36:25.663Z","dependency_job_id":"ef0cb769-2604-49ae-8fc3-deafa94f9027","html_url":"https://github.com/jeksterslab/semmcci","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/jeksterslab/semmcci","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeksterslab%2Fsemmcci","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeksterslab%2Fsemmcci/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeksterslab%2Fsemmcci/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeksterslab%2Fsemmcci/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeksterslab","download_url":"https://codeload.github.com/jeksterslab/semmcci/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeksterslab%2Fsemmcci/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003185,"owners_count":26083533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["confidence-intervals","monte-carlo","r","r-package","structural-equation-modeling"],"created_at":"2024-10-10T05:14:12.316Z","updated_at":"2025-10-11T11:16:12.925Z","avatar_url":"https://github.com/jeksterslab.png","language":"TeX","funding_links":[],"categories":[],"sub_categories":[],"readme":"semmcci\n================\nIvan Jacob Agaloos Pesigan\n2025-07-22\n\n\u003c!-- README.md is generated from .setup/readme/README.Rmd. Please edit that file --\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![CRAN\nStatus](https://www.r-pkg.org/badges/version/semmcci)](https://cran.r-project.org/package=semmcci)\n[![R-Universe\nStatus](https://jeksterslab.r-universe.dev/badges/semmcci)](https://jeksterslab.r-universe.dev/semmcci)\n[![DOI](https://zenodo.org/badge/DOI/10.3758/s13428-023-02114-4.svg)](https://doi.org/10.3758/s13428-023-02114-4)\n[![Make\nProject](https://github.com/jeksterslab/semmcci/actions/workflows/make.yml/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/make.yml)\n[![R-CMD-check](https://github.com/jeksterslab/semmcci/actions/workflows/check-full.yml/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/check-full.yml)\n[![R Package Test\nCoverage](https://github.com/jeksterslab/semmcci/actions/workflows/test-coverage.yml/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/test-coverage.yml)\n[![Lint R\nPackage](https://github.com/jeksterslab/semmcci/actions/workflows/lint.yml/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/lint.yml)\n[![Package Website (GitHub\nPages)](https://github.com/jeksterslab/semmcci/actions/workflows/pkgdown-gh-pages.yml/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/pkgdown-gh-pages.yml)\n[![Compile\nLaTeX](https://github.com/jeksterslab/semmcci/actions/workflows/latex.yml/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/latex.yml)\n[![Shell\nCheck](https://github.com/jeksterslab/semmcci/actions/workflows/shellcheck.yml/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/shellcheck.yml)\n[![pages-build-deployment](https://github.com/jeksterslab/semmcci/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/jeksterslab/semmcci/actions/workflows/pages/pages-build-deployment)\n[![codecov](https://codecov.io/gh/jeksterslab/semmcci/branch/main/graph/badge.svg?token=KVLUET3DJ6)](https://codecov.io/gh/jeksterslab/semmcci)\n\u003c!-- badges: end --\u003e\n\n## Installation\n\nYou can install the CRAN release of `semmcci` with:\n\n``` r\ninstall.packages(\"semmcci\")\n```\n\nYou can install the development version of `semmcci` from\n[GitHub](https://github.com/jeksterslab/semmcci) with:\n\n``` r\nif (!require(\"remotes\")) install.packages(\"remotes\")\nremotes::install_github(\"jeksterslab/semmcci\")\n```\n\n## Description\n\nIn the Monte Carlo method, a sampling distribution of parameter\nestimates is generated from the multivariate normal distribution using\nthe parameter estimates and the sampling variance-covariance matrix.\nConfidence intervals for defined parameters are generated by obtaining\npercentiles corresponding to 100(1 - α)% from the generated sampling\ndistribution, where α is the significance level.\n\nMonte Carlo confidence intervals for free and defined parameters in\nmodels fitted in the structural equation modeling package `lavaan` can\nbe generated using the `semmcci` package. The package has three main\nfunctions, namely, `MC()`, `MCMI()`, and `MCStd()`. The output of\n`lavaan` is passed as the first argument to the `MC()` function or the\n`MCMI()` function to generate Monte Carlo confidence intervals. Monte\nCarlo confidence intervals for the standardized estimates can also be\ngenerated by passing the output of the `MC()` function or the `MCMI()`\nfunction to the `MCStd()` function. A description of the package and\ncode examples are presented in Pesigan and Cheung (2023:\n\u003chttps://doi.org/10.3758/s13428-023-02114-4\u003e).\n\n## Example\n\nA common application of the Monte Carlo method is to generate confidence\nintervals for the indirect effect. In the simple mediation model,\nvariable `X` has an effect on variable `Y`, through a mediating variable\n`M`. This mediating or indirect effect is a product of path coefficients\nfrom the fitted model.\n\n``` r\nlibrary(semmcci)\nlibrary(lavaan)\n```\n\n### Data\n\n``` r\nsummary(df)\n#\u003e        X                  M                   Y           \n#\u003e  Min.   :-3.15272   Min.   :-2.770180   Min.   :-3.15166  \n#\u003e  1st Qu.:-0.68013   1st Qu.:-0.617813   1st Qu.:-0.67360  \n#\u003e  Median : 0.02779   Median :-0.008015   Median :-0.03968  \n#\u003e  Mean   : 0.00338   Mean   : 0.016066   Mean   :-0.02433  \n#\u003e  3rd Qu.: 0.69009   3rd Qu.: 0.668327   3rd Qu.: 0.63753  \n#\u003e  Max.   : 2.90756   Max.   : 2.712008   Max.   : 3.27343  \n#\u003e  NA's   :100        NA's   :100         NA's   :100\n```\n\n### Model Specification\n\nThe indirect effect is defined by the product of the slopes of paths `X`\nto `M` labeled as `a` and `M` to `Y` labeled as `b`. In this example, we\nare interested in the confidence intervals of `indirect` defined as the\nproduct of `a` and `b` using the `:=` operator in the `lavaan` model\nsyntax.\n\n``` r\nmodel \u003c- \"\n  Y ~ cp * X + b * M\n  M ~ a * X\n  X ~~ X\n  indirect := a * b\n  direct := cp\n  total := cp + (a * b)\n\"\n```\n\n### Monte Carlo Confidence Intervals\n\nWe can now fit the model using the `sem()` function from `lavaan`. We\nuse full-information maximum likelihood to deal with missing values.\n\n``` r\nfit \u003c- sem(data = df, model = model, missing = \"fiml\")\n```\n\nThe `fit` `lavaan` object can then be passed to the `MC()` function to\ngenerate Monte Carlo confidence intervals.\n\n``` r\nmc \u003c- MC(fit, R = 20000L, alpha = 0.05)\nmc\n#\u003e Monte Carlo Confidence Intervals\n#\u003e              est     se     R    2.5%  97.5%\n#\u003e cp        0.2491 0.0311 20000  0.1872 0.3099\n#\u003e b         0.4685 0.0321 20000  0.4064 0.5318\n#\u003e a         0.5032 0.0274 20000  0.4500 0.5562\n#\u003e X~~X      1.0556 0.0496 20000  0.9573 1.1532\n#\u003e Y~~Y      0.5830 0.0284 20000  0.5279 0.6393\n#\u003e M~~M      0.6790 0.0328 20000  0.6133 0.7427\n#\u003e Y~1      -0.0307 0.0258 20000 -0.0817 0.0204\n#\u003e M~1       0.0134 0.0278 20000 -0.0410 0.0675\n#\u003e X~1       0.0029 0.0337 20000 -0.0634 0.0695\n#\u003e indirect  0.2358 0.0206 20000  0.1973 0.2777\n#\u003e direct    0.2491 0.0311 20000  0.1872 0.3099\n#\u003e total     0.4849 0.0284 20000  0.4294 0.5406\n```\n\n### Monte Carlo Confidence Intervals - Multiple Imputation\n\nThe `MCMI()` function can be used to handle missing values using\nmultiple imputation. The `MCMI()` accepts the output of `mice::mice()`,\n`Amelia::amelia()`, or a list of multiply imputed data sets. In this\nexample, we impute multivariate missing data under the normal model.\n\n``` r\nmi \u003c- mice::mice(\n  df,\n  method = \"norm\",\n  m = 100,\n  print = FALSE,\n  seed = 42\n)\n```\n\nWe fit the model using lavaan using the default listwise deletion.\n\n``` r\nfit \u003c- sem(data = df, model = model)\n```\n\nThe `fit` `lavaan` object and `mi` object can then be passed to the\n`MCMI()` function to generate Monte Carlo confidence intervals.\n\n``` r\nmcmi \u003c- MCMI(fit, mi = mi, R = 20000L, alpha = 0.05, seed = 42)\nmcmi\n#\u003e Monte Carlo Confidence Intervals (Multiple Imputation Estimates)\n#\u003e             est     se     R   2.5%  97.5%\n#\u003e cp       0.2479 0.0311 20000 0.1874 0.3086\n#\u003e b        0.4689 0.0332 20000 0.4041 0.5338\n#\u003e a        0.5031 0.0275 20000 0.4499 0.5572\n#\u003e X~~X     1.0568 0.0502 20000 0.9587 1.1554\n#\u003e Y~~Y     0.5827 0.0289 20000 0.5257 0.6396\n#\u003e M~~M     0.6794 0.0328 20000 0.6151 0.7433\n#\u003e indirect 0.2359 0.0207 20000 0.1967 0.2775\n#\u003e direct   0.2479 0.0311 20000 0.1874 0.3086\n#\u003e total    0.4838 0.0284 20000 0.4276 0.5396\n```\n\n### Standardized Monte Carlo Confidence Intervals\n\nStandardized Monte Carlo Confidence intervals can be generated by\npassing the result of the `MC()` function or the `MCMI()` function to\n`MCStd()`.\n\n``` r\nMCStd(mc, alpha = 0.05)\n#\u003e Standardized Monte Carlo Confidence Intervals\n#\u003e              est     se     R   2.5%  97.5%\n#\u003e cp        0.2585 0.0318 20000 0.1951 0.3204\n#\u003e b         0.4603 0.0296 20000 0.4017 0.5178\n#\u003e a         0.5315 0.0247 20000 0.4824 0.5791\n#\u003e X~~X      1.0000 0.0000 20000 1.0000 1.0000\n#\u003e Y~~Y      0.5948 0.0260 20000 0.5431 0.6449\n#\u003e M~~M      0.7175 0.0262 20000 0.6646 0.7672\n#\u003e indirect -0.0310 0.0196 20000 0.2072 0.2838\n#\u003e direct    0.0137 0.0318 20000 0.1951 0.3204\n#\u003e total     0.0028 0.0257 20000 0.4508 0.5515\n```\n\n``` r\nMCStd(mcmi, alpha = 0.05)\n#\u003e Standardized Monte Carlo Confidence Intervals\n#\u003e             est     se     R   2.5%  97.5%\n#\u003e cp       0.2626 0.0320 20000 0.1953 0.3195\n#\u003e b        0.4461 0.0304 20000 0.4004 0.5190\n#\u003e a        0.5187 0.0250 20000 0.4819 0.5799\n#\u003e X~~X     1.0000 0.0000 20000 1.0000 1.0000\n#\u003e Y~~Y     0.6105 0.0265 20000 0.5419 0.6460\n#\u003e M~~M     0.7310 0.0265 20000 0.6637 0.7678\n#\u003e indirect 0.2314 0.0196 20000 0.2071 0.2836\n#\u003e direct   0.2626 0.0320 20000 0.1953 0.3195\n#\u003e total    0.4940 0.0260 20000 0.4503 0.5519\n```\n\n## Documentation\n\nSee [GitHub Pages](https://jeksterslab.github.io/semmcci/index.html) for\npackage documentation.\n\n## Citation\n\nTo cite `semmcci` in publications, please cite Pesigan \u0026 Cheung (2023).\n\n## References\n\n\u003cdiv id=\"refs\" class=\"references csl-bib-body hanging-indent\"\nentry-spacing=\"0\" line-spacing=\"2\"\u003e\n\n\u003cdiv id=\"ref-MacKinnon-Lockwood-Williams-2004\" class=\"csl-entry\"\u003e\n\nMacKinnon, D. P., Lockwood, C. M., \u0026 Williams, J. (2004). Confidence\nlimits for the indirect effect: Distribution of the product and\nresampling methods. *Multivariate Behavioral Research*, *39*(1), 99–128.\n\u003chttps://doi.org/10.1207/s15327906mbr3901_4\u003e\n\n\u003c/div\u003e\n\n\u003cdiv id=\"ref-Pesigan-Cheung-2023\" class=\"csl-entry\"\u003e\n\nPesigan, I. J. A., \u0026 Cheung, S. F. (2023). Monte Carlo confidence\nintervals for the indirect effect with missing data. *Behavior Research\nMethods*, *56*(3), 1678–1696.\n\u003chttps://doi.org/10.3758/s13428-023-02114-4\u003e\n\n\u003c/div\u003e\n\n\u003cdiv id=\"ref-Preacher-Selig-2012\" class=\"csl-entry\"\u003e\n\nPreacher, K. J., \u0026 Selig, J. P. (2012). Advantages of Monte Carlo\nconfidence intervals for indirect effects. *Communication Methods and\nMeasures*, *6*(2), 77–98. \u003chttps://doi.org/10.1080/19312458.2012.679848\u003e\n\n\u003c/div\u003e\n\n\u003cdiv id=\"ref-Tofighi-Kelley-2019\" class=\"csl-entry\"\u003e\n\nTofighi, D., \u0026 Kelley, K. (2019). Indirect effects in sequential\nmediation models: Evaluating methods for hypothesis testing and\nconfidence interval formation. *Multivariate Behavioral Research*,\n*55*(2), 188–210. \u003chttps://doi.org/10.1080/00273171.2019.1618545\u003e\n\n\u003c/div\u003e\n\n\u003cdiv id=\"ref-Tofighi-MacKinnon-2015\" class=\"csl-entry\"\u003e\n\nTofighi, D., \u0026 MacKinnon, D. P. (2015). Monte Carlo confidence intervals\nfor complex functions of indirect effects. *Structural Equation\nModeling: A Multidisciplinary Journal*, *23*(2), 194–205.\n\u003chttps://doi.org/10.1080/10705511.2015.1057284\u003e\n\n\u003c/div\u003e\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeksterslab%2Fsemmcci","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeksterslab%2Fsemmcci","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeksterslab%2Fsemmcci/lists"}