Skip to contents

Start with your research question, then follow the relevant guide. For a first analysis, complete Get started; it uses wsMed() throughout. All models here require two within-subject conditions with paired measurements.

Prepare your data

Use one row per participant, separate columns for the two conditions, and the same mediator order in both conditions. Decide which condition is subtracted from which before fitting: wsMed uses condition 2 minus condition 1.

Choose your model

Research structure form Meaning / next step
Parallel pathways "P" Each mediator forms a separate pathway; start with the quick start.
Serial pathways "CN" Each mediator predicts every later mediator in the supplied order.
Serial-parallel structure "CP" The first mediator (M1) predicts all remaining mediators.
Parallel-serial structure "PC" All remaining mediators predict the first mediator (M1).
User-defined pathways "UD" Set form = "UD" and list each mediator-to-mediator or mediator-to-outcome arrow in paths; see the example below.

The four predefined models are shown below. Each includes paths from the condition to every mediator and to the outcome, and from every mediator to the outcome. Choose the structure and mediator order from your research design; CP and PC place M1 at opposite ends of the mediator connections.

P: Parallel

P model: parallel mediator pathways

No directed connections among mediators. Model equations.

CN: Serial

CN model: earlier mediators predict later mediators

Each earlier mediator predicts every later mediator. Model equations.

CP: Serial-parallel

CP model: M1 predicts the remaining parallel mediators

M1 predicts M2, M3, and so on. Model equations.

PC: Parallel-serial

PC model: the parallel mediators predict M1

M2, M3, and so on predict M1. Model equations.

Click a diagram to enlarge it. In these difference-score diagrams, diff denotes condition 2 minus condition 1 and avg denotes the centered average; the triangle represents the constant used to estimate condition effects.

For user-defined models, M1, M2, and so on refer to the positions in M_C1 and M_C2; Y refers to the pair supplied through Y_C1 and Y_C2. For example, with M_C1 = c("A1", "B1", "C1") and M_C2 = c("A2", "B2", "C2"), the following specifies A to C, C to the outcome, and B to the outcome:

custom_paths <- c(
  "M1 -> M3",  # A to C
  "M3 -> Y",   # C to the outcome
  "M2 -> Y"    # B to the outcome
)

Pass this vector as paths = custom_paths together with form = "UD" in wsMed(). Write one arrow per string using these model labels, not the raw column names. Only the listed mediator connections are included: this example omits M1 -> Y. Condition-to-mediator paths and the direct condition-to-outcome path are added automatically. The worked UD example shows the complete call, input rules, and resulting indirect effects.

To add a moderator to this UD model, keep custom_paths and add W = "D3" and MP = c("b_1_3", "b3") to the call. Here, D3 is the moderator column; b_1_3 and b3 select the M1-to-M3 and M3-to-outcome slopes. Use coefficient labels in MP, not the arrow strings used in paths. The UD moderation example shows the complete call, how to choose other paths, and how to read conditional effects at selected moderator values.

Add moderation

Moderator Guide What to report
Continuous Specify moderated paths Conditional effects at meaningful raw values, with a curve or selected-level plot.
Categorical Fit and compare groups Reference coding, group-specific effects and intervals for group differences.

Declare categorical between-subject covariates and moderators as unordered factors before using either interface. Set factor levels explicitly; the first level is the reference group. The categorical predictor guide shows binary and multicategory coding. Specify which paths are moderated rather than assuming that every path includes an interaction.

Handle missing data

Situation Where to start
Complete data or deliberate complete-case analysis Na = "DE"; inspect the number of retained participants.
Full-information maximum likelihood Na = "FIML"; see options and restrictions.
Multiple imputation Na = "MI"; see imputation options.
Multiple imputation with moderation interactions Model-compatible imputation, including external completed datasets.

The choice depends on the missing-data assumptions and variable types. Default main-effects imputation may not preserve moderation interactions. Do not treat successful fitting or reproducible output as proof that an imputation model is suitable. Missing categorical predictors have additional restrictions.

Read, compare and present results

Go further when you need it

Task Guide
Specify, fit, infer, and inspect or extract at each stage Staged workflow
Inspect generated SEM syntax Model syntax
Check warnings, diagnostics and reproducibility Diagnostics and migration
Read mathematical definitions and software comparisons All articles

Next: run a first analysis or read its results.