Background Chronic psychological issues significantly exacerbate the risk of various diseases among middle-aged and older adults. Although prior research has indicated an association between physical activity and mental health, studies exploring the specific processes underlying this relationship remain insufficient. Therefore, this study aims to systematically investigate the relationship between physical activity and mental health in middle-aged and older populations, specifically by verifying the mediating role of sleep duration and the moderating role of cognitive function. Methods Drawing on data from the China Health and Retirement Longitudinal Study (CHARLS) involving 12,656 middle-aged and older participants, we employed mediation and moderation analyses to explore variable associations. Furthermore, cross-lagged models were utilized to rigorously verify longitudinal causal effects over time. Results Physical activity positively predicted the mental health ( β = 0.002, t = −6.757, p 0.001) and sleep duration ( β = 0.001, t = 2.980, p 0.01) of middle-aged and older adults. Sleep duration positively predicted mental health ( β = 0.031, t = 32.825, p 0.001), thereby verifying its mediating role. Meanwhile, cognitive function moderated the effect of physical activity on sleep duration ( β = 0.001, t = −2.910, p 0.01) and the effect of sleep duration on mental health ( β = 0.009, t = 2.236, p 0.05) in middle-aged and older adults. Regarding sub-dimensions, memory did not show a significant moderating effect. However, executive function significantly moderated the paths from physical activity to sleep duration ( β = 0.001, t = −2.624, p 0.01) and from sleep duration to mental health ( β = 0.023, t = 1.775, p 0.05). In the cross-lagged model, mental health positively predicted sleep duration ( β = −0.129, t = −3.82, p 0.001), and cognitive function moderated the impact of sleep duration on mental health ( β = −0.062, t = −3.82, p 0.05). Conclusion (1) Physical activity is positively correlated with mental health in middle-aged and older adults; (2) sleep duration mediates the relationship between physical activity and mental health; (3) cognitive function plays a moderating role in both stages of the mediation process; (4) the executive function subdomain exhibits differential moderating effects in middle-aged and older adults compared to memory; (5) longitudinally, cognitive function predicts mental health and positively moderates the relationship between sleep duration and mental health.
Zhao et al. (Mon,) studied this question.