Package: wsMed 1.2.0

Wendie Yang

wsMed: 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) <doi:10.18637/jss.v048.i02>, and extends Monte Carlo confidence interval estimation to missing data scenarios using the 'semmcci' package by Pesigan and Cheung (2023) <doi:10.3758/s13428-023-02114-4>.

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

wsMed_1.2.0.tar.gz
wsMed_1.2.0.zip(r-4.7-any)wsMed_1.2.0.zip(r-4.6-any)
wsMed_1.2.0.tar.gz(r-4.7-any)wsMed_1.2.0.tar.gz(r-4.6-any)
wsMed_1.2.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html✨
DESCRIPTION |NEWS
card.svg |card.png
wsMed/json (API)

# Install 'wsMed' in R:
install.packages('wsMed', repos = c('https://cran.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/yangzhen1999/wsmed/issues

Pkgdown/docs site:https://yangzhen1999.github.io

Datasets:

On CRAN:

Conda:

4.85 score 28 scripts 281 downloads 23 exports 88 dependencies

Last updated from:9645d50d87. Checks:6 OK. Indexed: no.

TargetResultTimeFilesSyslog
linux-develOK335
source / vignettesOK240
linux-releaseOK325
windows-develOK195
windows-releaseOK287
wasm-releaseOK147

Exports:GenerateModelCNGenerateModelCPGenerateModelCustomGenerateModelPGenerateModelPCImputeDataMCMI2plot_conditional_effectsplot_contrastsplot_effectsplot_moderation_curvePrepareDataPrepareMissingDataprintGMstandardize_moderationwsMedwsmed_contrastswsmed_effectswsmed_fitwsmed_inferwsmed_inspectwsmed_modelwsmed_reproducibility

Dependencies:backportsbitbit64bootbroomclicliprcodetoolscpp11crayondplyrevaluatefarverforcatsforeachgenericsGGallyggplot2ggstatsglmnetglueGPArotationgtablehavenhighrhmsisobanditeratorsjomoknitrlabelinglatticelavaanlavaan.printerlifecyclelme4magrittrMASSMatrixmiceminqamitmlmnormtnlmenloptrnnetnumDerivordinalpanpatchworkpbivnormpillarpkgconfigprettyunitsprogresspsychpurrrquadprogR6rbibutilsRColorBrewerRcppRcppEigenRdpackreadrreformulasrlangrpartS7scalessemboottoolssemmccishapestringistringrsurvivaltibbletidyrtidyselecttzdbucminfutf8vctrsviridisLitevroomwithrxfunyaml

Analysis options: a complete walkthrough
Start with the defaults | Paired variables | Choose the mediator structure | Predefined models | User-defined models | Add optional model components | Covariates | Moderators | Missing data and confidence intervals | Choose a missing-data strategy | Choose the inference method | Standardized effects | Inspect and present the results | Manuscript data

Last update: 2026-10-28
Started: 2025-12-11

Choose an analysis
Prepare your data | Choose your model | Add moderation | Handle missing data | Read, compare and present results | Go further when you need it

Last update: 2026-10-28
Started: 2026-10-28

Comparing wsMed and MEMORE
What is compared? | Parallel mediation | Serial mediation | Reading the comparison

Last update: 2026-10-28
Started: 2025-12-11

Diagnostics, reproducibility, and migration
Fit once and keep the inference settings | Inspect fitted datasets and inference separately | Interpret the effect being reported | Saved-object compatibility | Export a compact analysis manifest | Move from the previous one-call workflow | Statistical scope of validation

Last update: 2026-10-28
Started: 2026-10-28

Get started: two mediation examples
Install wsMed | Match your columns to the two conditions | Example 1: parallel mediation | Run the analysis | Read the results | Plot the indirect effects | Example 2: add a continuous moderator | Read the conditional effects | Plot how the indirect effects change | Specify more only when you need it | Continue with your own analysis

Last update: 2026-10-28
Started: 2026-10-28

Inspecting generated SEM syntax
Demonstration of printGM() | Using printGM() with wsMed() | Using printGM() with GenerateModel*()

Last update: 2026-10-28
Started: 2025-12-11

Model equations: parallel mediation
Difference scores and centered averages | Regression equations | Relation to the two condition equations | Indirect pathways | Total effects and contrasts | Condition-specific slopes | Standardization and moderation

Last update: 2026-10-28
Started: 2025-12-11

Model equations: parallel-serial mediation
Difference scores and centered averages | Regression equations | Indirect pathways | Total effects and contrasts | Condition-specific slopes | Standardization and moderation

Last update: 2026-10-28
Started: 2025-12-11

Model equations: serial mediation
Difference scores and centered averages | Regression equations | Indirect pathways | Total effects and contrasts | Condition-specific slopes | Standardization and moderation

Last update: 2026-10-28
Started: 2025-12-11

Model equations: serial-parallel mediation
Difference scores and centered averages | Regression equations | Indirect pathways | Total effects and contrasts | Condition-specific slopes | Standardization and moderation

Last update: 2026-10-28
Started: 2025-12-11

Model-compatible multiple imputation
Match imputation to the analysis | Generate the illustrative incomplete data | Impute using the outcome interaction | Use either wsMed interface | What the validation can establish

Last update: 2026-10-28
Started: 2026-10-28

Plotting mediation effects and contrasts
Choose a figure | Reproducible two-condition data | A consistent plot method | Interval conventions | Optional named plotting helpers | Forest plots | Conditional effects by group or selected level | Differences need their own intervals | Conditional curves and their highlighted ranges | Inspect and export

Last update: 2026-10-28
Started: 2026-09-18

Read and export results
Read the default report | Get a statistical summary | Plot the results | Choose more specific output | Request standardized effects | Select an effect family | Change the confidence level | Choose moderator values | Compare two pathways | Extract or export results when needed

Last update: 2026-10-28
Started: 2026-10-28

Reuse a fit: the staged workflow
The workflow at a glance | 1. Specify the model | What can you inspect now? | 2. Fit the model | What can you extract from the fit? | 3. Perform inference | What can you extract from inference? | 4. Read and extract effect results | What can you extract from the summary? | Decide where to restart after a change | Add a custom structure and moderator | Handle missing data at the fitting stage | What changes in extraction after MI? | Relate the stages to a one-call analysis | Save a stage and continue later

Last update: 2026-10-28
Started: 2026-10-28

Specifying user-defined mediation models
Mediator numbering | Specifying a custom model | Fitting the complete model with wsMed | Input requirements | Indirect effects | Parameter labels | Add a moderator | Choose the moderated paths | Fit and read the results | Choose moderator values | Use a categorical moderator | Standardized moderated custom models | Optional: inspect the generated equations | [M_

Last update: 2026-10-28
Started: 2026-09-18

Standardized effects
Request standardized results | What is standardized? | Continuous moderators: two different quantities | Fit a reproducible example | Categorical moderators | Confidence intervals, bootstrap and both engines | Missing data and reporting | More plots for reporting | Imputation compatibility | Optional implementation checks | Check the stored point estimates | Legacy moderation tables

Last update: 2026-10-28
Started: 2026-09-18

Working with categorical predictors
Supported variable roles | Choose the reference category | Fit categorical moderated mediation | Conditional effects and group differences | Optional: fit the same model in stages | Categorical covariates | Missing categorical predictors

Last update: 2026-10-28
Started: 2026-10-28

Readme and manuals

Help Manual

Help pageTopics
Simulated data for mediation tutorialsexample_data
Generate a serial mediation modelGenerateModelCN
Generate a serial-parallel mediation modelGenerateModelCP
Generate a user-defined mediation modelGenerateModelCustom
Generate a parallel mediation modelGenerateModelP
Generate a parallel-serial mediation modelGenerateModelPC
Impute missing data using multiple imputationImputeData
Monte Carlo confidence intervals for multiple imputation SEM modelsMCMI2
Plot conditional effects at moderator levelsplot_conditional_effects
Plot differences between mediation effectsplot_contrasts
Forest plot of mediation effectsplot_effects
Plot conditional effects across a continuous moderatorplot_moderation_curve
Prepare data for two-condition mediationPrepareData
Prepare data with missing values for mediation analysisPrepareMissingData
Print formatted SEM model syntaxprintGM
Standardize conditional mediation results using existing joint drawsstandardize_moderation
Analyze two-condition within-subject mediationwsMed
Categorical predictors and supported variable typeswsmed_categorical
Contrast effects using their joint stored drawswsmed_contrasts
Extract effects from fitted models or stored inferencewsmed_effects
Data for the manuscript exampleswsmed_examples
Fit a specified mediation model without simulationwsmed_fit
Apply uncertainty quantification to an existing fitwsmed_infer
Inspect a modular workflow without recomputationwsmed_inspect
Methods for modular wsMed objectsas.data.frame.wsmed_results coef.wsMed coef.wsmed_fit coef.wsmed_inference coef.wsmed_results confint.wsMed confint.wsmed_fit confint.wsmed_inference confint.wsmed_results nobs.wsMed nobs.wsmed_fit nobs.wsmed_inference print.summary_wsmed print.summary_wsmed_fit print.wsMed print.wsmed_fit print.wsmed_inference print.wsmed_model print.wsmed_results summary.summary_wsmed summary.wsMed summary.wsmed_fit summary.wsmed_inference summary.wsmed_results vcov.wsMed vcov.wsmed_fit vcov.wsmed_inference vcov.wsmed_results wsmed_methods
Specify a two-condition mediation modelwsmed_model
Plot mediation effects from workflow objectsplot.wsMed plot.wsmed_fit plot.wsmed_inference plot.wsmed_results wsmed_plots
Export the settings and provenance of an analysiswsmed_reproducibility