Mediation Analysis Calculator

Mediation Analysis Calculator. Enter the path coefficients (a and b) and their standard errors (SEa and SEb) to run a Sobel Test for Mediation Analysis. You get back the Sobel z-statistic, p-value, and indirect effect — telling you whether a mediator variable significantly carries the influence of an independent variable to a dependent variable. Also try the Slope (m) — Slope and Intercept.

Unstandardized regression coefficient for the path from the independent variable (X) to the mediator (M).

Unstandardized regression coefficient for the path from the mediator (M) to the dependent variable (Y), controlling for X.

Standard error of the path coefficient a (X → M).

Standard error of the path coefficient b (M → Y).

Significance threshold for determining whether mediation is statistically significant.

Results

Sobel Z-Statistic

--

Two-Tailed p-Value

--

Indirect Effect (a × b)

--

Standard Error of Indirect Effect

--

Goodman (1959) Z-Statistic

--

Aroian / Goodman (1960) Z-Statistic

--

Mediation Significance

--

Results Table

When you want to understand not just whether variable X affects outcome Y, but how and through what pathway that effect operates, this mediation analysis calculator gives you the precise answer. Rather than a simple association, you get a full effect decomposition — path coefficients, a bootstrapped indirect effect, and a path diagram — so you can confidently explain the causal process driving your findings. Whether you're working in psychology research, epidemiology, public health, econometrics, or any other field built on numerical analysis, understanding the underlying pathway behind an association is what separates insight from mere observation. See also our Linear Regression Calculator.

What Is an Online Mediation Analysis Calculator and When Should You Use It?

Mediation analysis tests whether the effect of an independent variable X on a dependent variable Y operates through an intermediate variable M — called the mediator variable. Rather than simply asking does X affect Y?, mediation asks how does X affect Y? — what is the underlying causal process? Understanding the relationship between variables in this way is foundational to social science, clinical research, and empirical inquiry more broadly. Researchers use it to move beyond causation claims toward testable causal inference, examining whether a third variable M transmits the effect of X to Y in an indirect way — a process sometimes described as facilitation of the X–Y relationship through M.

The total effect (c) of X on Y is decomposed into two components:

  • The indirect effect (a×b) — the portion of X's influence that flows through the mediator M, following the X → M → Y pathway. This is also called the mediated effect or the mediated portion of the total relationship.
  • The direct effect (c') — the remaining effect of X on Y after accounting for the mediator M, representing the part of X's influence that does not pass through M.

Formally, the relationship is expressed as:

$$c = c' + a \times b$$

where path a is the path a coefficient linking X (the predictor, or IV) to the mediator, and path b is the path b coefficient linking the mediator to the outcome Y — the DV — (controlling for X). The product of paths — a×b — quantifies the mediated pathway.

Partial mediation occurs when both the mediated pathway and the direct effect (c') remain significant — the mediator explains some but not all of X's effect on Y. Complete mediation (also called full mediation) occurs when the direct effect (c') becomes non-significant after including M, meaning all of X's effect on Y flows through M. A critical note from Preacher and Hayes (2008): the older Baron and Kenny (1986) requirement of a significant total effect c as a prerequisite for testing mediation is now considered outdated — modern practice evaluates the mediated pathway directly.

When the mediated pathway and direct effect carry opposite signs and cancel out, the total effect can appear near zero even though mediation is present — this is called inconsistent or suppressor mediation, and it highlights why examining all path components separately matters in any rigorous analytical approach.

Causal ordering is a foundational assumption: the model assumes X temporally or causally precedes M, and M precedes Y, reflecting the data-generating process you hypothesise. This causal flow — the X → M → Y sequence — cannot be proven from the values alone; it must be justified by study design, temporal ordering, prior literature, or experimental manipulation. In cross-sectional settings with simultaneous measurement, causal mediation claims require extra care.

Modern bootstrap resampling — not the older Sobel test — is the gold standard for significance testing of the mediated pathway. The sampling distribution of the product term is typically non-normal (often right-skewed), so classical asymptotic intervals from the Sobel approach can be misleading, especially with small samples. The percentile bootstrap CI makes no distributional assumptions and correctly captures the asymmetry of that distribution — this is the approach recommended by MacKinnon and Dwyer and validated across many empirical evaluation studies in psychological methods, multivariate behavioral research, and evaluation review literature.

Understanding the Indirect Effect Formula and Test Statistics

The classical Sobel test provides an analytical approximation to the significance of the mediated pathway. The Sobel test equation computes a z-value:

$$z = \frac{a \times b}{\sqrt{b^{2} s_{a}^{2} + a^{2} s_{b}^{2}}}$$

where \(s_a\) and \(s_b\) are the standard error values for paths a and b respectively — these are the unstandardized coefficient standard errors obtained from your model output. The reported p-value is drawn from the unit normal distribution under the assumption of a two-tailed z-test. The critical values ±1.96 contain the central 95% of this distribution.

Two alternative formulations address a limitation of the Sobel approach. The Aroian test equation — favoured by the original Baron and Kenny framework — adds a third error term:

$$z = \frac{a \times b}{\sqrt{b^{2} s_{a}^{2} + a^{2} s_{b}^{2} + s_{a}^{2} s_{b}^{2}}}$$

The Goodman test equation subtracts this term for an unbiased estimate of the variance of mediated effect:

$$z = \frac{a \times b}{\sqrt{b^{2} s_{a}^{2} + a^{2} s_{b}^{2} - s_{a}^{2} s_{b}^{2}}}$$

The square root in each formula is applied to the combined spread estimate. The Goodman version can occasionally produce a negative spread value — a known limitation. The Aroian and Sobel versions converge closely for sample sizes above ~50, as shown in the original Monte Carlo study by MacKinnon, Warsi, and Dwyer (1995). Treating the product term as arising from two normally distributed variables is the core assumption these formulae rely on — an assumption that breaks down in small sample research and with skewed distributions, which is precisely why bootstrapping is now preferred.

The one-tailed probability and two-tailed probability from these test statistic calculations are the probability values you compare against your significance threshold. Note that any rounding error in path values you enter will propagate into the critical ratio — so use full-precision values from your model output.

Direct Effect Estimation via OLS Regression Equations

Both the direct effect (c') and the individual paths are estimated through OLS — specifically OLS-based mediation using two sequential model equations. First, an M equation regresses the mediator on the predictor X (and any covariates) to obtain path a and its standard error. Second, a Y equation regresses outcome Y on both X and M simultaneously to obtain the path b coefficient and the direct effect c prime (the OLS slope for X in that second equation). The overall effect c comes from a simple model of Y on X alone without M.

This structured combination of multiple modelling steps is why path analysis and structural equation modelling (SEM) are closely related to mediation. When your mediator is a latent construct measured by multiple items — for example, in psychometrics or factor analysislatent variable mediation via SEM handles measurement error that would otherwise bias your estimated path weights. The statsmodels Python library and plotly are commonly used to automate these analyses and produce result visualization programmatically.

Mediator Variable Types and Model Extensions

Standard mediation assumes continuous variables and straight-line associations. When your outcome Y is binary, the Y path uses logistic regression and the mediated pathway is expressed on the log-odds scale (or log-odds ratio). A binary mediator requires a logit model for path a, with the mediated pathway approximated as the product of the log-odds ratio and the OLS path b — or estimated via probit on a standardized scale for a more interpretable result. A binary predictor (e.g., treatment vs. control) requires no special handling — X is simply a 0/1 dummy in both equations, and you can use heteroscedasticity-robust standard errors for robustness in observational settings.

For models with clustered or longitudinal inputs that violate independent observations, consider multilevel mediation via hierarchical modelling (also called linear mixed effects models). Researchers working in prevention studies or group-based intervention settings frequently encounter this need, as noted by Krull and MacKinnon (1999) in multivariate behavioral research. Nonlinear mediation — for curved associations among variables — requires different estimation strategies beyond the standard OLS framework.

How to Run Mediation Analysis Online — Upload Data, Describe & Get Full Results

Step-by-Step: From Data Upload to Indirect Effect Output

Running mediation analysis online with this tool follows a straightforward three-step workflow. You can use this free Sobel test calculator and full mediation suite from your own raw input — no software installation, no SPSS macros, no SAS macros, no local R environment required.

  1. Upload your information — provide a CSV file or Excel file containing your records. Each row is one observation. You need at minimum one predictor column (X), one mediator column (M), and one outcome column (Y). Optional covariate column entries can be included to control for confounders and obtain adjusted path estimates. All variables should be numeric; note in your prompt if any are binary.
  2. Describe the analysis — type a plain-language description naming your column names, specifying the number of bootstrap resamples (5000 is the recommended default), the confidence level, and any additional outputs you need (e.g., proportion mediated, path diagram, sensitivity analysis). The intelligent agent reads your description and writes Python code using statsmodels and plotly to run the full model.
  3. Retrieve full results — output includes all path estimates, the mediated pathway with its bootstrap CI, the direct effect (c'), the total effect (c), the proportion mediated, a path diagram showing all paths, and a resampling distribution plot with clear visualization of the effect. You can explore results interactively and copy the R code or Python script for your methods section.

The tool supports simple mediation models, parallel mediation with multiple mediators, serial mediation chains, and conditional process analysis. Intelligent interpretations accompany the output, explaining what each result means in plain language — making this interactive calculation tool useful for both experienced analysts and those newer to research methods.

Required Data Format — Column Structure and Example Values

Your input should be structured so that each variable occupies its own column. You can upload or drop files directly, or use a provided sample dataset to explore the tool first. Here is the required format:

ColumnWhat to typeWhat it meansExample
X (predictor)Numeric values, one per rowYour predictor or treatment — the variable whose effect you want to decompose into direct and mediated componentsstress_score, dose, SES, treatment (0/1)
M (mediator)Numeric values, one per rowThe intermediate variable through which X is hypothesised to affect Y; the mediator in path notationsleep hours, cortisol, self_efficacy, perceived stress
Y (outcome)Numeric values, one per rowYour outcome — the DV; note if binary outcome (0/1) for logistic adjustmenthealth index, performance, depression score
Covariates (optional)Additional numeric columnsControl variables included as predictors in both the M and Y equations; removes known confounders from path estimatesage, sex, baseline_score, socioeconomic status

Any column names work — simply describe them in your prompt. For binary Y, specify a logit link for the Y path. For binary mediator M, specify a logit link for the M path. Select variables by name in your description, and the tool handles the rest. If you want to examine your records before committing to a model, run summaries first or ask the tool to recommend a test based on your variable types. You can also paste values directly from a spreadsheet into a plain-text prompt if preferred.

Example Prompts for Every Mediation Model Type

The following prompts show exactly what to type in the description box. These worked examples cover the three most common analysis scenarios you will encounter:

Example 1 — Basic single-mediator model (Stress → Sleep → Health):

X = stress, M = sleep, Y = health_index; bootstrap indirect effect 5000 reps; 95% CI; path diagram; report proportion of total effect mediated; test if direct effect becomes non-significant

In this scenario, you are testing whether stress score (X) affects health index (Y) through sleep hours (M). You obtain path a (stress → sleep), path b (sleep → health controlling stress), the direct effect (c') of stress on health after accounting for sleep, and the full 95% bootstrap CI for the mediated pathway. If the interval excludes zero, the mediated pathway is confirmed by significance testing. If the significant direct effect disappears after including M, you have evidence of total mediation; if it remains alongside a meaningful mediated pathway, that indicates partial transmission of the effect.

Example 2 — Serial mediation (three-path mediation with M1 and M2):

serial mediation: X → M1 → M2 → Y; indirect effect through sequential chain; bootstrap CI; report specific indirect effects for each path; X = dose, M1 = performance, M2 = motivation, Y = outcome

This serial mediation model — also called three-path mediation — tests whether X affects Y through a sequential chain of M1 M2 mediators. You get the specific pathway estimates for each sub-path (X→M1→Y, X→M2→Y, X→M1→M2→Y) alongside the total transmitted effect. The 3 mediators variant extends this to a serial chain with additional steps. These multiple mediator models require bootstrapping all pathways simultaneously — something the Sobel approach cannot handle properly. This is where resampling strategies genuinely shine over classical methods. The script output can be adapted for use with SPSS procedures, SAS procedures, or the macros from Preacher and Hayes.

Example 3 — Moderated mediation (mediation varies by a moderator variable):

test whether mediation effect varies by gender (moderator W); index of moderated mediation; conditional indirect effects; report bootstrap CI for index; X = stress, M = sleep, Y = health_index, W = gender

In this conditional process model, a boundary condition W — here a gender moderator — changes the strength or direction of the mediated pathway. The index of moderated mediation tests whether the moderated pathway estimates differ significantly across levels of W. An x×m interaction or an interaction term between M and W in the Y equation captures this. When the index CI excludes zero, the transmission of effects across moderator levels differs significantly — you report pathway estimates at specific values of W (e.g., male vs. female). This extends the standard mediation framework into the broader territory of conditional process analysis — a moderation calculator is useful for examining interaction effects separately before integrating them into the full conditional model.

Interpreting Your Output When You Calculate Mediation Analysis Online

Once you retrieve full results, the output table presents every component of your mediation tests in tabular form alongside graphical results — the path diagram and resampling distribution plot. Here is how to interpret each metric:

OutputDescriptionExample ValueWhat It Means
Path aPath a coefficient: X → M slope from the M equation−0.41A one-unit increase in X is associated with a −0.41-unit change in M; e.g., lower SES → higher perceived stress
Path bPath b coefficient: M → Y slope controlling X, from the Y equation0.52Each one-unit increase in M is associated with a 0.52-unit increase in Y, controlling X; the influence of M on Y
Direct effect (c')X → Y coefficient in the Y equation after including M; direct effect c prime−0.12X's effect on Y not explained by M; if non-significant, total mediation; if significant, partial transmission
Total effect (c)X → Y without M in the model; equals c' + a×b−0.33The overall association between X and Y ignoring the mediator; the baseline before decomposition
Indirect effect (a×b)Product of paths a and b — the mediated effect; effect of X on Y transmitted through M−0.21The core quantity of interest; the transmitted influence passing through M; how x influences y via the mediator
95% Bootstrap CIPercentile CI for the mediated pathway from 5000 bootstrap resamples[−0.38, −0.07]CI excludes zero → significant mediation confirmed; CI includes zero → not significant
Proportion mediateda×b / c — fraction of total effect carried by M; the mediated share of the whole0.64 (64%)64% of X's effect on Y flows through M; the share of total effect explained by the mediator; meaningful only when c and the mediated pathway share the same sign
Path diagramVisual path model with arrows and coefficients showing causal flowSummarises all paths at a glance; arrows represent hypothesised causal direction in the X → M → Y structure
E-valueSensitivity analysis metric — minimum confounding strength needed to explain away the mediated pathway3.2An unmeasured confounder would need a risk ratio of 3.2 with both M and Y to nullify your finding; larger = more robust

When the 95% percentile CI — technically the central 95% of the resampling distribution — excludes zero, the mediated pathway is confirmed at the 5% level. This is your primary criterion for significance, replacing the older Sobel approach. The nominal 95% coverage probability of the percentile bootstrap is well-validated in empirical evaluation studies, especially for n less than 200 where the Sobel approximation degrades. For n less than 100, interpret wide CIs with caution — you may have insufficient power to detect mediation even if true effects exist.

The proportion mediated — also called the mediated effect measure or the mediated share of variance — is calculated as:

$$\text{Proportion mediated} = \frac{a \times b}{c}$$

This share of total effect is only interpretable when both the total and the transmitted pathway share the same sign. When they carry opposite signs — as in suppressor mediation — the proportion can exceed 1 or be negative, indicating a pathway complication that requires careful reporting.

To assess whether you have partial mediation versus complete mediation, examine both the direct effect (c') and its p-value. If both the mediated pathway CI excludes zero and the direct effect remains meaningful, you have partial mediation. If the direct effect c prime is no longer significant after including M, you have complete mediation — the fraction of total effect mediated approaches 100%. This is the modern operationalisation of what the original Baron and Kenny criteria called step 4, refined by subsequent work in psychological methods and social psychological research.

Key Assumptions for Valid Mediation Tests — What to Check Before Interpreting Results

Every mediation test rests on assumptions about the data-generating process. Violating them can render even a significant result misleading. Below are the five core assumptions, with practical diagnostics for each — important whether you are working with observational, survey, or experimental inputs.

  • Linearity assumption — OLS-based mediation and the standard path model assume straight-line associations among X, M, and Y. Inspect scatterplots and residual plots for each equation. For skewed variables or evident curved associations, consider log-transforming variables or adding polynomial terms. In nonlinear mediation contexts, specialist methods are needed beyond what standard OLS provides.
  • Causal ordering — the X → M → Y sequence must be theoretically justified. In experimental design with randomized X, X → M is credible; M → Y still requires theory. Cross-sectional settings with simultaneous measurement make causal claims inherently weaker. Longitudinal structures with temporal ordering strengthen the argument considerably.
  • No unmeasured M → Y confounders — the key causal inference assumption for the mediated pathway. There should be no unmeasured confounders affecting both M and Y simultaneously. Include known confounders as covariates in the Y equation. Use the e-value from sensitivity analysis to quantify how strong m → y confounders would need to be to invalidate your conclusion.
  • No X → Y confoundersx → y confounders bias both the total and direct estimates. When X is randomised (e.g., in experimental manipulation), this assumption is satisfied by design. In nonexperimental and observational designs, controlling for confounders via measured control variables is essential.
  • No interaction between X and M — standard mediation assumes no x×m interaction (i.e., the effect of M on Y is constant across values of X). Test this by adding an interaction term X×M to the Y equation. If the interaction term is significant, adopt a conditional process framework instead, and report pathway estimates at different moderator levels.

For causal mediation in settings with mediation significance as the primary hypothesis — common in prevention studies, epidemiology, and social psychology — also consider power analysis before collection. Monte Carlo power simulation (e.g., via the pwr2ppl r package) can determine the sample size needed for reliable detection of a given effect size in the transmitted pathway. Empirical evaluation research consistently shows that large samples (n ≥ 200) provide reliable bootstrap confidence intervals with correct coverage probability; with small samples, 5000 bootstrap resamples is the minimum recommended — drawn using the percentile bootstrap approach to give stable error estimates and avoid artefacts from the distribution tails.

If your records are clustered (e.g., students within schools, patients within hospitals), standard mediation violates independent observations — use multilevel mediation via hierarchical modelling or linear mixed effects models, drawing on extensions documented in behavior research methods and evaluation review. When M is a latent construct (e.g., a psychometric scale), structural equation modeling (SEM) corrects for measurement error that inflates direct estimates and deflates transmitted pathway estimates in manifest-variable mediation — this is known as latent variable mediation. The SAS procedures PROC CALIS and the R packages lavaan and mediation support SEM-based approaches, as do SPSS procedures through the PROCESS macro developed by Hayes.

For researchers focused on hypothesis testing, this sobel test calculator and broader mediation analysis calculator provides the complete picture: z-value, p-value, bootstrap CI, mediated pathway interval, and e-value — everything required to report mediation test results according to current standards in empirical social science, applied research, and epidemiology. The output also includes model tables you can present directly in your manuscript, covering adjusted path estimates, association summaries, and the X–Y association before and after controlling M — giving your readers the full effect decomposition picture and enabling transparent structural interpretation.

Whether you are conducting a basic two-variable mediation in applied research or a complex parallel mediation with multiple mediators in clinical research, this free Sobel test calculator — combining mediation analysis online accessibility with intelligent interpretations and exportable R code — brings the full power of modern mediation analysis to any researcher's workflow. Use it as your primary interactive mediation tests tool, or as a complement to free analytical calculators for modelling, moderation analysis, and path analysis — all part of a complete empirical and analytical toolkit for social science and beyond. You might also find our Adjusted R-Squared Calculator useful.

What is mediation analysis and when should I use it?

Mediation analysis tests whether a third variable (the mediator) explains the relationship between an independent variable (X) and a dependent variable (Y). Use it when you have a theoretical reason to believe X influences M, and M in turn influences Y — for example, whether stress (X) affects health outcomes (Y) through sleep quality (M).

What does the Sobel test actually measure?

The Sobel test evaluates whether the indirect effect of X on Y through M (calculated as a × b) is statistically different from zero. It computes a z-statistic by dividing the indirect effect by its standard error, then derives a two-tailed p-value. A significant result (typically p < 0.05) indicates meaningful mediation.

What are path coefficients a and b?

Path coefficient a is the unstandardized regression coefficient from the independent variable (X) to the mediator (M). Path coefficient b is the unstandardized regression coefficient from the mediator (M) to the dependent variable (Y), controlling for X. Both come from standard ordinary least squares regression analyses.

What is the difference between Sobel, Goodman (1959), and Aroian test statistics?

All three test the same indirect effect but differ slightly in their standard error formula. The Sobel test omits the term (SEa² × SEb²), the Aroian test includes it, and Goodman's (1959) test subtracts it. The Aroian/Goodman (1960) version is considered the most conservative and is generally recommended for small samples.

Is the Sobel test appropriate for small samples?

No — the Sobel test assumes a normal distribution of the indirect effect, which only holds well in large samples (typically n > 200). For smaller samples, bootstrapping methods (such as those available in Hayes' PROCESS macro) are strongly preferred because they impose no distributional assumptions and tend to be more accurate.

What does a non-significant Sobel test result mean?

A non-significant result (p > α) means there is insufficient evidence that the mediator significantly transmits the effect of X to Y. However, this does not necessarily mean no mediation exists — the test may simply lack power, particularly in small samples. Consider using bootstrapping or increasing your sample size.

What is full versus partial mediation?

Full mediation occurs when the direct effect of X on Y becomes non-significant after controlling for the mediator M, while the indirect effect (a × b) remains significant. Partial mediation means both the direct and indirect effects are significant, indicating M explains some but not all of the X→Y relationship.

How do I obtain the standard errors SEa and SEb for this calculator?

Run two separate regression analyses. First, regress M on X to get coefficient a and its standard error SEa. Second, regress Y on both X and M to get coefficient b and its standard error SEb. Most statistical software (SPSS, R, Python, Stata) reports these standard errors automatically in the regression output table.