Abstract
This research investigated the pathways from math performance to the cognitive (worried thoughts) and affective (emotional tension) dimensions of math anxiety (MA) in high-school and university students. Using the PLS-SEM method, we identified a consistent dual-pathway mediation structure across both groups: Math performance is associated with affective MA via cognitive MA, and with cognitive MA via affective MA. We also explored whether working memory (WM) subsystems, based on Baddeley’s model, moderate these links and found differences between these two successive academic cohorts. In high-school students, phonological loop (verbal) WM moderated the link from math to affective MA, with this effect being evident only for those with medium-to-low capacity. In contrast, for university students, a dual-pathway moderated-mediation structure was found: the pathway to cognitive MA was contingent upon medium-to-high capacity in visuospatial sketchpad (representing image and location) WM, whereas the pathway to affective MA was contingent upon medium-to-high capacity in both phonological and visuospatial WM. However, simpler mediation models without WM interactions consistently showed superior model fit. These findings support a stable interplay between the MA components across the sampled academic stages, emphasizing the explanatory and predictive primacy of these core mediation mechanisms during the transition from adolescence to young adulthood. SUPPLEMENTARY INFORMATION: The online version contains supplementary material available at 10.1038/s41598-026-45516-y.