Mediator or moderator: what's the difference in plain terms?
A mediator is a step in the causal chain. If sleep problems lead to pain partly because they first cause depression, then depression is the middle link: sleep → depression → pain. A moderator is a dial on the relationship itself. If the sleep–pain link is strong for some people and weak or absent for others depending on some third factor, that factor is moderating the link — it changes the strength of the connection rather than sitting inside it.
The distinction matters for treatment. A mediator suggests that addressing depression could interrupt the pathway from poor sleep to pain. A moderator suggests that changing the moderating condition — here, how much people participate in social activities — could weaken the link directly. The evidence points to depression doing the first job and social participation doing the second [1].
Depression sits in the middle of the sleep–pain loop
The clearest test comes from a five-year study of nearly 8,000 middle-aged and older Chinese adults, followed at three time points. Earlier sleep problems predicted later pain, and earlier pain predicted later poor sleep — a genuine two-way street. Crucially, depressive symptoms carried a meaningful share of both directions: roughly 22% of the sleep-to-pain effect and roughly 21% of the pain-to-sleep effect ran through depression [1].
A separate analysis of the same national cohort during the COVID-19 pandemic found the same pattern from a different angle. People sleeping either less or more than an optimal amount reported more frequent pain, and both depression and chronic disease acted as significant mediators of that link [2]. Personal pandemic activity, by contrast, did not mediate it — a useful contrast showing that not every plausible middle factor actually carries the effect.
How a cohort design separates the two roles
The key tool is repeated measurement of the same people. By measuring sleep, pain, depression, and social participation at several time points, researchers can ask whether earlier levels of one variable predict later levels of another after accounting for the earlier levels of that outcome — a cross-lagged model. That temporal ordering is what lets a study argue that depression comes between sleep and pain rather than merely accompanying both [1].
Testing mediation and moderation then becomes a matter of where the third variable enters the model. If depression absorbs part of the sleep–pain association, it is behaving as a mediator. If the sleep–pain association itself differs across levels of social participation, that factor is behaving as a moderator [1]. Simpler longitudinal designs can still track two-way associations — one cohort of schoolteachers followed over time found depression and anxiety acting as confounders in the sleep–back pain relationship rather than as mediators [4] — which shows how the choice of statistical role assigned to a variable shapes what a cohort can conclude.
It is also worth being precise about direction. A prospective study of pregnant women found that mid-pregnancy sleep disorders predicted later perinatal depression, but only among women who were not already depressed early in pregnancy [5]. That is evidence for sleep influencing depression, one arm of the loop — not for depression mediating the sleep–pain relationship, since pain was not part of that study. Keeping the variables and directions straight is exactly what these designs are built to do.
Sources used in this answer
Depression as a Mediator and Social Participation as a Moderator in the Bidirectional Relationship Between Sleep Disorders and Pain: Dynamic Cohort Study
In a five-year cohort of middle-aged and older Chinese adults, sleep disorders and pain predicted each other over time, depressive symptoms mediated roughly 21–22% of each direction, and high social participation weakened both the direct and depression-mediated pathways.
Sleep duration and pain during the COVID-19 pandemic with depression and chronic diseases as mediators
In a cross-sectional analysis of the CHARLS cohort during COVID-19, both shorter and longer sleep duration were associated with more frequent pain, with depression and chronic disease acting as significant mediators but personal activity not.
Sleep quality as a mediator of the relation between depression and chronic pain: a systematic review and meta-analysis
A systematic review and meta-analysis examined sleep quality as a mediator between depression and chronic pain, a different arrangement of roles than depression mediating the sleep–pain link.
Bidirectional associations between chronic low back pain and sleep quality: a cohort study with schoolteachers
In a cohort of schoolteachers, chronic low back pain and sleep quality were bidirectionally associated over time, with depression and anxiety acting as relevant confounders rather than mediators.
The predictive effect of mid-pregnancy sleep disorders on perinatal depression within women with or without depression in early pregnancy: A prospective cohort study
In a prospective pregnancy cohort, mid-pregnancy sleep disorders predicted later perinatal depression among women not depressed early in pregnancy, but not among those already depressed.

Social participation changes the strength of the link
The moderator in this story is social participation. Among people with high levels of social activity, the direct effects of earlier sleep problems on later pain and of earlier pain on later sleep were largely no longer statistically significant, and the depression-mediated pathways also weakened [1]. In other words, the same two-way loop that operates in less socially active people appears substantially muted in more socially active ones.
The study's authors describe social participation as moderating the relationship both directly and indirectly, by affecting depression [1]. That is an interpretation of the pattern rather than proof of a mechanism, but it fits the data: the loop is present, and it is weaker when social engagement is high.