Within-Subject Mediation Analysis Using Structural Equation Modeling

Within-subject mediation analysis using structural equation modeling. Examine how changes in an outcome variable between two conditions are mediated through one or more variables. Supports within-subject mediation analysis using the 'lavaan' package by Rosseel (2012) , and extends Monte Carlo confidence interval estimation to missing data scenarios using the 'semmcci' package by Pesigan and Cheung (2023) .


wsMed

Mediation and moderated mediation for two-condition within-subject designs.

Install

These tutorials describe wsMed 1.2.0. Install the released package from CRAN:

install.packages("wsMed")

Or install the version on the GitHub master branch:

# install.packages("pak")
pak::pak("Yangzhen1999/wsMed@master")

Restart R after updating. packageVersion("wsMed") shows the installed version.

First analysis

Each row is one participant. The paired mediator columns are A1 / A2 and B1 / B2; the paired outcome columns are D1 / D2. The contrast is condition 2 minus condition 1.

library(wsMed)
data(example_data)

result <- wsMed(
  data = example_data,
  M_C1 = c("A1", "B1"),
  M_C2 = c("A2", "B2"),
  Y_C1 = "D1",
  Y_C2 = "D2"
)

print(result)
summary(result)
plot(result)

This uses the defaults: parallel mediation, listwise deletion, Monte Carlo inference with 20,000 draws, 95% CIs and unstandardized output. The dataset is complete. The Get started guide explains the report and adds a moderator in a second example.

Learn more

Use unordered factors for categorical between-subject covariates and moderators, with the first level as the reference. The categorical predictor guide explains coding and missing-data restrictions.

The empirical manuscript data are included as wsmed_examples. For source editing and tutorial rebuilding, see the maintainer guide.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("wsMed")

1.2.0 by Wendie Yang, 8 hours ago


https://yangzhen1999.github.io/wsMed/


Report a bug at https://github.com/Yangzhen1999/wsMed/issues


Browse source code at https://github.com/cran/wsMed


Authors: Wendie Yang [aut, cre] , Shu Fai Cheung [aut]


Documentation:   PDF Manual  


GPL (>= 3) license


Imports knitr, lavaan, semmcci, mice, semboottools, MASS, rlang, dplyr, ggplot2, methods, stats, graphics, utils

Suggests rmarkdown, devtools, testthat, smcfcs


See at CRAN