BACKGROUND: Conceptualising comorbidity is complex and the term is used variously. Here, it is the coexistence of two or more diagnoses which might be defined as 'chronic' and, although they may be pathologically related, they may also act independently. Of interest here is the comorbidity of common psychiatric disorders and impaired cognition. OBJECTIVES: To examine whether anxiety and/or depression are/is important longitudinal predictors of cognitive change. METHODS: UK Biobank participants used at three time points (n=502 664): baseline, first follow-up (n=20 257) and first imaging study (n=40 199). Participants with no missing data were 1175 participants aged 40-70 years, 41% women. Machine learning was applied and the main outcome measure of reaction time intraindividual variability (cognition) was used. FINDINGS: Using the area under the receiver operating characteristic curve, the anxiety model achieves the best performance with an area under the curve (AUC) of 0.68, followed by the depression model with an AUC of 0.63. The cardiovascular and diabetes model, and the covariates model have weaker performance in predicting cognition, with an AUC of 0.60 and 0.56, respectively. CONCLUSIONS: Outcomes suggest that psychiatric disorders are more important comorbidities of long-term cognitive change than diabetes and cardiovascular disease, and demographic factors. Findings suggest that psychiatric disorders (anxiety and depression) may have a deleterious effect on long-term cognition and should be considered as an important comorbid disorder of cognitive decline. CLINICAL IMPLICATIONS: Important predictive effects of poor mental health on longitudinal cognitive decline should be considered in secondary and also primary care.