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.