What is mediation analysis?
sobes.tech AI
Answer from AI
Mediation analysis is a method in causal analysis that helps to understand through which intermediate variables (mediators) the effect of one variable (e.g., treatment or factor) is transmitted to another variable (outcome).
Simply put, if we have a variable X (cause), a variable Y (effect), and a variable M (mediator), mediation analysis helps to estimate which part of the effect of X on Y occurs directly, and which part is mediated through M.
Example: the impact of an advertising campaign (X) on sales (Y) may partly pass through increased brand awareness (M). Mediator analysis will help to quantitatively assess this pathway.
A typical approach involves building regression models to estimate direct and indirect effects and testing the statistical significance of the mediator.
# Example in Python using statsmodels
import statsmodels.api as sm
# X - independent variable
# M - mediator
# Y - dependent variable
# 1. Regression of M on X
model_M = sm.OLS(M, sm.add_constant(X)).fit()
# 2. Regression of Y on X and M
model_Y = sm.OLS(Y, sm.add_constant(np.column_stack((X, M)))).fit()
# Estimation of direct and indirect effects based on coefficients