semmcci

semmcci: Monte Carlo Confidence Intervals in Structural Equation Modeling

https://github.com/jeksterslab/semmcci

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 15 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.9%) to scientific vocabulary

Keywords

confidence-intervals monte-carlo r r-package structural-equation-modeling
Last synced: 6 months ago · JSON representation ·

Repository

semmcci: Monte Carlo Confidence Intervals in Structural Equation Modeling

Basic Info
Statistics
  • Stars: 3
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 7
Topics
confidence-intervals monte-carlo r r-package structural-equation-modeling
Created almost 5 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog License Citation

README.md

semmcci

Ivan Jacob Agaloos Pesigan 2025-07-22

CRAN
Status R-Universe
Status DOI Make
Project R-CMD-check R Package Test
Coverage Lint R
Package Package Website (GitHub
Pages) Compile
LaTeX Shell
Check pages-build-deployment codecov <!-- badges: end -->

Installation

You can install the CRAN release of semmcci with:

r install.packages("semmcci")

You can install the development version of semmcci from GitHub with:

r if (!require("remotes")) install.packages("remotes") remotes::install_github("jeksterslab/semmcci")

Description

In the Monte Carlo method, a sampling distribution of parameter estimates is generated from the multivariate normal distribution using the parameter estimates and the sampling variance-covariance matrix. Confidence intervals for defined parameters are generated by obtaining percentiles corresponding to 100(1 - α)% from the generated sampling distribution, where α is the significance level.

Monte Carlo confidence intervals for free and defined parameters in models fitted in the structural equation modeling package lavaan can be generated using the semmcci package. The package has three main functions, namely, MC(), MCMI(), and MCStd(). The output of lavaan is passed as the first argument to the MC() function or the MCMI() function to generate Monte Carlo confidence intervals. Monte Carlo confidence intervals for the standardized estimates can also be generated by passing the output of the MC() function or the MCMI() function to the MCStd() function. A description of the package and code examples are presented in Pesigan and Cheung (2023: https://doi.org/10.3758/s13428-023-02114-4).

Example

A common application of the Monte Carlo method is to generate confidence intervals for the indirect effect. In the simple mediation model, variable X has an effect on variable Y, through a mediating variable M. This mediating or indirect effect is a product of path coefficients from the fitted model.

r library(semmcci) library(lavaan)

Data

``` r summary(df)

> X M Y

> Min. :-3.15272 Min. :-2.770180 Min. :-3.15166

> 1st Qu.:-0.68013 1st Qu.:-0.617813 1st Qu.:-0.67360

> Median : 0.02779 Median :-0.008015 Median :-0.03968

> Mean : 0.00338 Mean : 0.016066 Mean :-0.02433

> 3rd Qu.: 0.69009 3rd Qu.: 0.668327 3rd Qu.: 0.63753

> Max. : 2.90756 Max. : 2.712008 Max. : 3.27343

> NA's :100 NA's :100 NA's :100

```

Model Specification

The indirect effect is defined by the product of the slopes of paths X to M labeled as a and M to Y labeled as b. In this example, we are interested in the confidence intervals of indirect defined as the product of a and b using the := operator in the lavaan model syntax.

r model <- " Y ~ cp * X + b * M M ~ a * X X ~~ X indirect := a * b direct := cp total := cp + (a * b) "

Monte Carlo Confidence Intervals

We can now fit the model using the sem() function from lavaan. We use full-information maximum likelihood to deal with missing values.

r fit <- sem(data = df, model = model, missing = "fiml")

The fit lavaan object can then be passed to the MC() function to generate Monte Carlo confidence intervals.

``` r mc <- MC(fit, R = 20000L, alpha = 0.05) mc

> Monte Carlo Confidence Intervals

> est se R 2.5% 97.5%

> cp 0.2491 0.0311 20000 0.1872 0.3099

> b 0.4685 0.0321 20000 0.4064 0.5318

> a 0.5032 0.0274 20000 0.4500 0.5562

> X~~X 1.0556 0.0496 20000 0.9573 1.1532

> Y~~Y 0.5830 0.0284 20000 0.5279 0.6393

> M~~M 0.6790 0.0328 20000 0.6133 0.7427

> Y~1 -0.0307 0.0258 20000 -0.0817 0.0204

> M~1 0.0134 0.0278 20000 -0.0410 0.0675

> X~1 0.0029 0.0337 20000 -0.0634 0.0695

> indirect 0.2358 0.0206 20000 0.1973 0.2777

> direct 0.2491 0.0311 20000 0.1872 0.3099

> total 0.4849 0.0284 20000 0.4294 0.5406

```

Monte Carlo Confidence Intervals - Multiple Imputation

The MCMI() function can be used to handle missing values using multiple imputation. The MCMI() accepts the output of mice::mice(), Amelia::amelia(), or a list of multiply imputed data sets. In this example, we impute multivariate missing data under the normal model.

r mi <- mice::mice( df, method = "norm", m = 100, print = FALSE, seed = 42 )

We fit the model using lavaan using the default listwise deletion.

r fit <- sem(data = df, model = model)

The fit lavaan object and mi object can then be passed to the MCMI() function to generate Monte Carlo confidence intervals.

``` r mcmi <- MCMI(fit, mi = mi, R = 20000L, alpha = 0.05, seed = 42) mcmi

> Monte Carlo Confidence Intervals (Multiple Imputation Estimates)

> est se R 2.5% 97.5%

> cp 0.2479 0.0311 20000 0.1874 0.3086

> b 0.4689 0.0332 20000 0.4041 0.5338

> a 0.5031 0.0275 20000 0.4499 0.5572

> X~~X 1.0568 0.0502 20000 0.9587 1.1554

> Y~~Y 0.5827 0.0289 20000 0.5257 0.6396

> M~~M 0.6794 0.0328 20000 0.6151 0.7433

> indirect 0.2359 0.0207 20000 0.1967 0.2775

> direct 0.2479 0.0311 20000 0.1874 0.3086

> total 0.4838 0.0284 20000 0.4276 0.5396

```

Standardized Monte Carlo Confidence Intervals

Standardized Monte Carlo Confidence intervals can be generated by passing the result of the MC() function or the MCMI() function to MCStd().

``` r MCStd(mc, alpha = 0.05)

> Standardized Monte Carlo Confidence Intervals

> est se R 2.5% 97.5%

> cp 0.2585 0.0318 20000 0.1951 0.3204

> b 0.4603 0.0296 20000 0.4017 0.5178

> a 0.5315 0.0247 20000 0.4824 0.5791

> X~~X 1.0000 0.0000 20000 1.0000 1.0000

> Y~~Y 0.5948 0.0260 20000 0.5431 0.6449

> M~~M 0.7175 0.0262 20000 0.6646 0.7672

> indirect -0.0310 0.0196 20000 0.2072 0.2838

> direct 0.0137 0.0318 20000 0.1951 0.3204

> total 0.0028 0.0257 20000 0.4508 0.5515

```

``` r MCStd(mcmi, alpha = 0.05)

> Standardized Monte Carlo Confidence Intervals

> est se R 2.5% 97.5%

> cp 0.2626 0.0320 20000 0.1953 0.3195

> b 0.4461 0.0304 20000 0.4004 0.5190

> a 0.5187 0.0250 20000 0.4819 0.5799

> X~~X 1.0000 0.0000 20000 1.0000 1.0000

> Y~~Y 0.6105 0.0265 20000 0.5419 0.6460

> M~~M 0.7310 0.0265 20000 0.6637 0.7678

> indirect 0.2314 0.0196 20000 0.2071 0.2836

> direct 0.2626 0.0320 20000 0.1953 0.3195

> total 0.4940 0.0260 20000 0.4503 0.5519

```

Documentation

See GitHub Pages for package documentation.

Citation

To cite semmcci in publications, please cite Pesigan & Cheung (2023).

References

MacKinnon, D. P., Lockwood, C. M., & Williams, J. (2004). Confidence limits for the indirect effect: Distribution of the product and resampling methods. *Multivariate Behavioral Research*, *39*(1), 99–128.
Pesigan, I. J. A., & Cheung, S. F. (2023). Monte Carlo confidence intervals for the indirect effect with missing data. *Behavior Research Methods*, *56*(3), 1678–1696.
Preacher, K. J., & Selig, J. P. (2012). Advantages of Monte Carlo confidence intervals for indirect effects. *Communication Methods and Measures*, *6*(2), 77–98.
Tofighi, D., & Kelley, K. (2019). Indirect effects in sequential mediation models: Evaluating methods for hypothesis testing and confidence interval formation. *Multivariate Behavioral Research*, *55*(2), 188–210.
Tofighi, D., & MacKinnon, D. P. (2015). Monte Carlo confidence intervals for complex functions of indirect effects. *Structural Equation Modeling: A Multidisciplinary Journal*, *23*(2), 194–205.

Owner

  • Name: Ivan Jacob Agaloos Pesigan
  • Login: jeksterslab
  • Kind: user
  • Company: University of Macau

Citation (CITATION.cff)

# --------------------------------------------
# CITATION file created with {cffr} R package
# See also: https://docs.ropensci.org/cffr/
# --------------------------------------------
 
cff-version: 1.2.0
message: 'To cite package "semmcci" in publications use:'
type: software
license: MIT
title: 'semmcci: Monte Carlo Confidence Intervals in Structural Equation Modeling'
version: 1.1.5
doi: 10.3758/s13428-023-02114-4
identifiers:
- type: doi
  value: 10.32614/CRAN.package.semmcci
abstract: Monte Carlo confidence intervals for free and defined parameters in models
  fitted in the structural equation modeling package 'lavaan' can be generated using
  the 'semmcci' package. 'semmcci' has three main functions, namely, MC(), MCMI(),
  and MCStd(). The output of 'lavaan' is passed as the first argument to the MC()
  function or the MCMI() function to generate Monte Carlo confidence intervals. Monte
  Carlo confidence intervals for the standardized estimates can also be generated
  by passing the output of the MC() function or the MCMI() function to the MCStd()
  function. A description of the package and code examples are presented in Pesigan
  and Cheung (2023) <https://doi.org/10.3758/s13428-023-02114-4>.
authors:
- family-names: Pesigan
  given-names: Ivan Jacob Agaloos
  email: r.jeksterslab@gmail.com
  orcid: https://orcid.org/0000-0003-4818-8420
preferred-citation:
  type: article
  title: Monte Carlo confidence intervals for the indirect effect with missing data
  authors:
  - family-names: Pesigan
    given-names: Ivan Jacob Agaloos
    email: r.jeksterslab@gmail.com
    orcid: https://orcid.org/0000-0003-4818-8420
  - family-names: Cheung
    given-names: Shu Fai
    email: shufai.cheung@gmail.com
    orcid: https://orcid.org/0000-0002-9871-9448
  year: '2023'
  doi: 10.3758/s13428-023-02114-4
  journal: Behavior Research Methods
repository: https://CRAN.R-project.org/package=semmcci
repository-code: https://github.com/jeksterslab/semmcci
url: https://jeksterslab.github.io/semmcci/
contact:
- family-names: Pesigan
  given-names: Ivan Jacob Agaloos
  email: r.jeksterslab@gmail.com
  orcid: https://orcid.org/0000-0003-4818-8420
keywords:
- confidence-intervals
- monte-carlo
- r
- r-package
- structural-equation-modeling

GitHub Events

Total
  • Watch event: 1
  • Push event: 24
Last Year
  • Watch event: 1
  • Push event: 24

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 394
  • Total Committers: 3
  • Avg Commits per committer: 131.333
  • Development Distribution Score (DDS): 0.096
Past Year
  • Commits: 44
  • Committers: 1
  • Avg Commits per committer: 44.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
jeksterslab l****b@g****m 356
jeksterslab s****b@g****m 37
Shu Fai Cheung s****g@g****m 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 2
  • Total pull requests: 5
  • Average time to close issues: 4 months
  • Average time to close pull requests: 6 minutes
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.8
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jeksterslab (2)
Pull Request Authors
  • jeksterslab (5)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 272 last-month
  • Total docker downloads: 1,473
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
cran.r-project.org: semmcci

Monte Carlo Confidence Intervals in Structural Equation Modeling

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 272 Last month
  • Docker Downloads: 1,473
Rankings
Stargazers count: 28.5%
Forks count: 28.8%
Dependent packages count: 29.8%
Dependent repos count: 35.5%
Average: 39.1%
Downloads: 73.0%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.0.0 depends
  • lavaan * depends
  • methods * depends
  • stats * depends
  • MASS * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat * suggests
.github/workflows/check-full.yml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/latex.yml actions
  • actions/checkout v4 composite
  • s0/git-publish-subdir-action develop composite
.github/workflows/lint.yml actions
  • actions/checkout v4 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/make-all.yml actions
  • actions/checkout v4 composite
.github/workflows/make.yml actions
  • actions/checkout v4 composite
  • devops-infra/action-commit-push master composite
.github/workflows/pkgdown-gh-pages.yml actions
  • JamesIves/github-pages-deploy-action v4 composite
  • actions/checkout v4 composite
.github/workflows/shellcheck.yml actions
  • actions/checkout v4 composite
  • ludeeus/action-shellcheck master composite
.github/workflows/source.yml actions
  • actions/checkout v4 composite
  • s0/git-publish-subdir-action develop composite
.github/workflows/test-coverage.yml actions
  • actions/checkout v4 composite
  • actions/upload-artifact v3 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.devcontainer/Dockerfile docker
  • ijapesigan/r2u-r-project latest build
.github/workflows/rhub-cran-add-01.yml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
.github/workflows/rhub-cran-add-02.yml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
.github/workflows/rhub-cran.yml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
.github/workflows/rhub-donttest.yml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
.github/workflows/rhub-etc.yml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite