Differences between revisions 2 and 3
Revision 2 as of 2026-02-17 15:44:50
Size: 976
Comment: Relationship -> Association
Revision 3 as of 2026-02-17 16:58:26
Size: 1735
Comment: More thorough notes
Deletions are marked like this. Additions are marked like this.
Line 16: Line 16:

First, consider the case where the mediator explains all causation. In this example, controlling for ''M'' explains all correlation.

{{{
> X <- rbinom(1000, 1, 0.5)
> M <- rbinom(1000, 1, 0.9*(1-X) + 0.1*X)
> Y <- rbinom(1000, 1, 0.9*(1-M) + 0.1*M)
> cor(X,Y)
[1] 0.6440206
> cor(X[Z==1], Y[Z==1])
[1] 0.02818287
> cor(X[Z==0], Y[Z==0])
[1] 0.0464756
}}}

Note that in [[R]], the [[Analysis/BernoulliDistribution|Bernoulli distribution]] is handled as a special case of the [[Analysis/BinomialDistribution|Binomial distribution]]. Note furthermore the similarities between this and [[Statistics/Confounder|confounding]].

Consider now the more general case, where some but not all causation is mediated. This can be explained visually as:

Mediator

A mediator is a variable M that is caused by some variable X and itself causes a variable Y.

Not to be confused with a moderator.


Description

Mediators are one possible failure of causal inference. An association has been identified between two variables, X and Y, but in actuality there is a mediator M between them. X causes M and M causes Y. This is called mediation.

First, consider the case where the mediator explains all causation. In this example, controlling for M explains all correlation.

> X <- rbinom(1000, 1, 0.5)
> M <- rbinom(1000, 1, 0.9*(1-X) + 0.1*X)
> Y <- rbinom(1000, 1, 0.9*(1-M) + 0.1*M)
> cor(X,Y)
[1] 0.6440206
> cor(X[Z==1], Y[Z==1])
[1] 0.02818287
> cor(X[Z==0], Y[Z==0])
[1] 0.0464756

Note that in R, the Bernoulli distribution is handled as a special case of the Binomial distribution. Note furthermore the similarities between this and confounding.

Consider now the more general case, where some but not all causation is mediated. This can be explained visually as:

path.png

The causal effects are:

  • direct effect of X on Y = β1

  • direct effect of X on M = β2

  • direct effect of M on Y = β3

  • indirect effect of X on Y = β23

  • total effect of X on Y = β1 + (β23)

See here for analysis of this system.


CategoryRicottone

Statistics/Mediator (last edited 2026-02-17 16:58:26 by DominicRicottone)