Skip to main content

The impact of major depressive disorder on glycaemic control in type 2 diabetes: a longitudinal cohort study using UK Biobank primary care records



This study evaluates longitudinal associations between glycaemic control, measured by mean and within-patient variability of glycated haemaglobin (HbA1c) levels, and major depressive disorder (MDD) in individuals with type 2 diabetes (T2D), focusing on the timings of these diagnoses.


In UK Biobank, T2D was defined using self-report and linked health outcome data, then validated using polygenic scores. Repeated HbA1c measurements (mmol/mol) over the 10 years following T2D diagnosis were outcomes in mixed effects models, with disease duration included using restricted cubic splines. Four MDD exposures were considered: MDD diagnosis prior to T2D diagnosis (pre-T2D MDD), time between pre-T2D MDD diagnosis and T2D, new MDD diagnosis during follow-up (post-T2D MDD) and time since post-T2D MDD diagnosis. Models with and without covariate adjustment were considered.


T2D diagnostic criteria were robustly associated with T2D polygenic scores. In 11,837 T2D cases (6.9 years median follow-up), pre-T2D MDD was associated with a 0.92 increase in HbA1c (95% CI: [0.00, 1.84]), but earlier pre-T2D MDD diagnosis correlated with lower HbA1c. These pre-T2D MDD effects became non-significant after covariate adjustment. Post-T2D MDD individuals demonstrated increasing HbA1c with years since MDD diagnosis (\(\beta =0.51\), 95% CI: [0.17, 0.86]). Retrospectively, across study follow-up, within-patient variability in HbA1c was 1.16 (95% CI: 1.13–1.19) times higher in post-T2D MDD individuals.


The timing of MDD diagnosis is important for understanding glycaemic control in T2D. Poorer control was observed in MDD diagnosed post-T2D, highlighting the importance of depression screening in T2D, and closer monitoring for individuals who develop MDD after T2D.

Peer Review reports


Major depressive disorder (MDD) and type 2 diabetes (T2D) are substantial global health burdens, occurring together at twice the frequency expected by chance [1]. Adults with MDD have a 37% higher risk of developing T2D [2], and people with T2D face a 15% higher risk of developing MDD [3].

For individuals with T2D, comorbid depression is associated with elevated risk of diabetic complications [4] and all-cause mortality [5]. The underlying mechanisms between these disorders and outcomes remain poorly understood, but could include lifestyle factors, non-adherence to T2D treatment, use of antidepressant medication or genetic factors [1].

One potential link between MDD and adverse outcomes in T2D is glycaemic control, with glycated haemoglobin (HbA1c) representing a reliable measure of long-term glycemia. Elevated and more variable HbA1c levels are associated with increased risk of long-term diabetic complications, such as stroke and cardiovascular disease [6,7,8]. Prior studies have shown mixed support for the association between MDD and HbA1c [1, 9], but many are limited to a cross-sectional design. A meta-analysis that considered longitudinal effects of depressive symptoms on HbA1c found that depressive symptoms associated with higher HbA1c, and so poorer glycaemic control, across a mean follow-up of three years (n = 3683 across six studies) [9].

Furthermore, the relative timing of MDD and T2D diagnoses may also impact T2D clinical characteristics. A cross-sectional study showed that depression diagnosed after T2D is linked with poorer glycaemic control, and a higher prevalence of diabetic complications, compared to T2D patients with no or with pre-existing depression [10].

Understanding the impact of MDD on glycaemic control across time is crucial for delivering appropriate clinical care to individuals living with both MDD and T2D. Longitudinal studies to date have not explored the relationship between the relative diagnostic timings of these disorders and HbA1c trends over time. To address this gap, our study uses UK Biobank (UKB) primary care records to perform extensive longitudinal modelling of HbA1c in people with T2D in a retrospective, observational study, using information on MDD diagnosis. In the UK, HbA1c is measured by a general practitioner (GP) every 3–6 months in individuals with T2D [11]. Therefore, the linked primary care data available in UKB provides a unique opportunity to test the longitudinal relationship between HbA1c (mean levels and variability) and MDD over a 10-year period following T2D diagnosis. Our analysis incorporates four MDD exposures:

  1. 1)

    pre-T2D MDD diagnosis (ever diagnosed with MDD prior to T2D),

  2. 2)

    time between pre-T2D MDD diagnosis and T2D,

  3. 3)

    time-varying post-T2D MDD (newly diagnosed with MDD during follow-up period), and

  4. 4)

    time since post-T2D MDD diagnosis.

By considering these exposures, we aim to gain a deeper understanding of how MDD and its timing in relation to T2D affect glycaemic control.


Study population

The UKB is a health study of ~ 500,000 individuals recruited between 2006 and 2010 in the United Kingdom, aged 40–70 [12]. Linked primary care records are available for ~ 230,000 individuals (46%), encompassing clinical events, blood test results and prescriptions, providing longitudinal patient information [13].

T2D Classification and Validation

UKB participants with primary care records were classified into T2D cases and controls. T2D cases met specific T2D diagnostic criteria (detailed below), while controls did not. The T2D diagnostic criteria were validated using T2D polygenic scores (PGSs) in European ancestry participants meeting genetic quality control criteria [14, 15] (Additional file 1: Methods S1).

Type 2 diabetes (T2D) diagnostic criteria

T2D cases were identified based on the presence of any two of the following: 1) a primary care diagnosis code for T2D (Additional file 2: Table S1), 2) an ICD9/ICD10 diagnosis code for T2D (Additional file 2: Table S2), 3) any HbA1c measurement > 48 mmol/mol (6.5%), 4) any prescription for glucose lowering medication (Additional file 1: Methods S2 [16], Additional file 2: Table S3), and 5) a self-reported diagnosis for T2D with reported age at onset > 35 years. T2D diagnosis date was then the earliest occurrence among the identified criteria. T2D cases were excluded if they had a primary care code specific to type 1 diabetes, an insulin prescription within a year of T2D diagnosis, or a prescription for multiple diabetic medications at T2D diagnosis (Additional file 1: Methods S2-S3). Individuals prescribed one diabetic medication (monotherapy) at T2D diagnosis were not excluded.

Exclusion criteria for longitudinal analysis

For the longitudinal analysis, we excluded participants meeting any of the following criteria: 1) were a T2D control, 2) had fewer than two HbA1c measurements after T2D diagnosis, 3) had age at T2D diagnosis < 18 years, 4) had no recorded HbA1c measurements > 38 mmol/mol (3.5%) [17] within a six-month window of T2D diagnosis, 5) had diagnostic codes for bipolar, psychotic or substance-use disorders [18], 6) had a MDD diagnosis without a diagnosis date, or 7) were missing self-reported ethnicity (Fig. 1).

Fig. 1
figure 1

Flow diagram of UK Biobank (UKB) participant selection. T2D = type 2 diabetes. MDD = major depressive disorder. HES = hospital episode statistics. HbA1c = glycated haemaglobin. Validation of T2D diagnosis sample = T2D case and controls of European ancestry, meeting eligibility criteria outlined in Methods, including individual-level genetic analysis inclusion criteria (described in Additional File 1: Methods S1). Imputed datasets used for analyses (2) and (3) (adjusted mixed effects model for HbA1c over time and within-individual HbA1c variation)

Outcome measures

For the T2D diagnostic criteria validation, the outcome was T2D case–control status for UKB participants of European ancestry with primary care records available. For the longitudinal analysis, the outcome was repeated measures of HbA1c (mmol/mol) after T2D diagnosis. HbA1c data were taken from: 1) primary care records up to 2017 (Additional file 2: Table S4), where older observations recorded in %-units were converted to mmol/mol [19], and 2) all UKB biomarker assessments (2006–2016), where a validated correction was applied to account for lower average HbA1c values from the UKB biomarker panel compared to primary care [20] (Additional file 1: Methods S4). The indexing date was T2D diagnosis, with a maximum follow-up period of 10 years.


In the longitudinal analysis, four MDD exposure variables were considered simultaneously. Two were related to individuals diagnosed with MDD prior to T2D (pre-T2D MDD), and two were related to individuals diagnosed with MDD after their T2D diagnosis (post-T2D MDD).

Pre-T2D MDD exposures: (1) History of MDD at T2D diagnosis (MDD_index). This binary variable indicates whether an individual had ever received a MDD diagnosis at the index date. (2) Pre-T2D MDD duration at index (years). This semi-continuous variable quantifies the time between MDD diagnosis and T2D diagnosis when MDD_index equals 1, and is 0 otherwise. These time-invariant exposures were used to examine the impact of pre-T2D MDD on HbA1c, including interactions with T2D disease duration.

Post-T2D MDD exposures: (1) Change in MDD diagnosis (MDD_change). A time-varying binary variable indicating, at each observation time (t), whether an individual has been diagnosed with MDD between t and the index date. It captures information about individuals diagnosed with MDD during follow-up. For individuals with no MDD diagnosis occurring before t, and those diagnosed prior to T2D diagnosis, this variable is set to 0. (2) Post-T2D MDD duration (years). A time-varying, semi-continuous variable equalling the time between MDD diagnosis and t if MDD_change equals 1, and 0 otherwise. This variable allows post-T2D MDD participants to have different HbA1c time-slopes after their MDD diagnosis. Note, UKB participants classified as having a MDD diagnosis required at least two diagnostic codes for a depressive disorder or episode diagnosis in the linked primary care records [18] (Additional file 1: Methods S5).


Covariates were extracted from UKB assessments and/or primary care data. Covariates extracted from UKB initial assessments were: sex, assessment centre, self-reported ethnicity, Townend Deprivation Index (TDI), qualifications, ever smoked, and never consumed alcohol. Covariates extracted from both UKB assessments and primary care data were: age at T2D diagnosis, HbA1c at T2D diagnosis, body mass index (BMI) at T2D diagnosis (Additional file 1: Methods S6 [21, 22]), systolic (SBP) and diastolic (DBP) blood pressure at T2D diagnosis (Additional file 1: Methods S6), number of HbA1c, BMI and blood pressure measurements taken prior to T2D diagnosis, and T2D disease duration (time since diagnosis). Covariates extracted from primary care only were diabetic medications. Glucose lowering medication at each HbA1c observation was identified using prescription records up to three months prior to HbA1c measurement (Additional file 1: Methods S2). This information was grouped into four medication categories: 1) M0 (‘no medication’), 2) M1 (‘metformin or a single medication’/ monotherapy), 3) M2 (‘two medications’/ dual-therapy), and 4) M3 (either ‘3 or more medications’ or ‘insulin’). Two medication variables were then created. Firstly, a binary variable indicating monotherapy at T2D diagnosis versus no prescribed T2D medication (M0 vs M1 at diagnosis; recall exclusion criteria removed individuals prescribed multiple medications at diagnosis). Secondly, a time-varying medication variable using the four categories M0–M3.

Apart from T2D disease duration and time-varying medication, covariates were treated as baseline measurements, but it is important to note that the index date and UKB assessment dates are different. For example, measurements from UKB initial assessments (TDI, qualifications, etc.) were collected between 2006 and 2010, and 56% of individuals were diagnosed outside of this timeframe. However, results from models with and without UKB initial assessment covariates yielded similar conclusions (Additional file 2: Table S5). Further details on covariates are available in Additional file 2: Table S6 [18,19,20,21,22,23].

Statistical analysis

All analyses were performed using R version 4.2.2 and visualised using ggplot2.

Validation of T2D diagnostic criteria

To validate the T2D definition, we tested whether PGSs for T2D [24] predicted T2D case–control status. PGSs, calculated using PRSice v2 [25, 26] at eleven P-value thresholds, were tested for association with T2D case–control status, adjusting for six genetic ancestry principal components, assessment centre and genetic batch effect (Additional file 1: Methods S7).

Longitudinal analysis

We employed linear mixed effects models (MEMs) to investigate longitudinal associations between HbA1c and MDD using the nlme package [27, 28]. All models incorporated random intercepts and time slopes, with a continuous-time autoregressive 1 (CAR1) residual correlation structure to account for autocorrelation. A series of three analyses were performed.

(1) Unadjusted model with selection

This analysis focused on the primary fixed effects of time (T2D disease duration) and the MDD exposures. Time was included using a restricted cubic spline (RCS) with four knots to allow for a non-linear temporal trend in mean HbA1c [29, 30]. Interactions between the pre-T2D MDD exposures and time-splines were considered, with the impact of post-T2D MDD on HbA1c time-slopes captured by post-T2D MDD duration. Selection of the final model was determined by Akaike Information Criterion (AIC) and likelihood ratio tests (LRTs). Models with semi-continuous exposures required their corresponding binary indicator to be included.

(2) Adjusted model

The selected unadjusted model was extended to include covariates, plus interactions between the time-splines and HbA1c at T2D diagnosis, BMI at T2D diagnosis and the medication variables.

(3) Residual within-subject variation in HbA1c

To explore the association between within-subject variation and MDD, the adjusted model was updated to allow residual variation to differ by MDD diagnosis variables. Firstly, we assessed if pre-T2D MDD (MDD_index) individuals had different residual variation compared to other participants. Secondly, we used MDD_change to investigate if post-T2D MDD individuals had different residual variation after their MDD diagnosis. Thirdly, a retrospective, time-invariant binary indicator for post-T2D MDD individuals was introduced to assess any differences in within-subject variation over all of follow-up. Please see Additional file 1: Methods S8 [27,28,29,30] for a mathematical explanation of these models. Likelihood ratio tests (LRTs) were used to test for MDD diagnosis-related heterogeneity in residual variation.

HbA1c at T2D diagnosis had a high level of missingness (40%), but all included participants had a HbA1c measurement within a six-month window of this date. Multiple imputation (MI) with the Amelia package [31] generated 50 MI datasets (Additional file 1: Methods S9) that were used in analyses (2) and (3). MEM estimates were pooled using Rubin’s method, with pooled Wald-like P-values presented for the fixed effects [32, 33]. Parameter estimates for RCSs are difficult to interpret. Therefore, in addition to a summary of the MDD exposure fixed effects (including P-values from t-tests), results are presented using plots of predicted HbA1c [34, 35]. Details of covariates included in MI and/ or MEMs are given in Additional file 2: Tables S6-S7.


Validation of T2D diagnostic criteria

The eligible UKB sample consisted of 17,712 individuals with T2D (Fig. 2), with 24% of individuals having evidence of T2D from all five data sources considered. Participants with T2D tended to be male (61%) with an average age at T2D diagnosis of 57 years (IQR: 51–64 years). Applying genetic quality control criteria to participants of European ancestry provided 13,799 T2D cases and 73,002 controls. T2D PGSs were significantly associated with T2D case–control status at all P-value thresholds considered and explained up to 2.8% of T2D liability (Additional file 3: Table S1).

Fig. 2
figure 2

Contributions of each input to the T2D phenotype definition. Horizontal bars indicate the number of individuals who met criteria for the corresponding T2D sub-phenotypes. Vertical bars indicate the number of individuals endorsing combinations of the five T2D sub-phenotypes

Longitudinal analysis

In total, 11,837 T2D cases were included, with a median follow-up time of 6.9 years (IQR: 3.5–9.3 years). Table 1 presents sample characteristics stratified by MDD subgroup: ‘no MDD’ (89% without an MDD diagnosis), ‘pre-T2D MDD’ (9% with MDD diagnosed prior to T2D) and ‘post-T2D MDD’ (2% diagnosed with MDD during the 10-year follow-up period). Groups with a diagnosis of MDD include a higher proportion of females and have higher median TDI, which is particularly notable in the post-T2D MDD group (Additional File 4: Figure S1). Additionally, the post-T2D MDD group had an earlier median age at T2D diagnosis, leading to a longer median follow-up time (Additional File 4: Figures S2-S3). This group also had the highest proportion of patients in medication group M3 (insulin and/or three or more T2D medications) by the end of follow-up. A higher proportion of the post-T2D MDD group are missing HbA1c at diagnosis (52% compared to 43% for the pre-T2D MDD group and 42% for the no MDD group). See Additional file 4: Figures S1-S2 and S4-S8 for density plots of continuous covariates included in the MEMs.

Table 1 Characteristics of the longitudinal analysis study participants, stratified by MDD subgroups. Columns present N (%) for categorical variables and median (IQR) for continuous variables

Unadjusted model

The selected unadjusted model included time-splines and the four MDD exposures, with no significant interaction between the pre-T2D MDD exposures and time (p = 0.3072; Table 2). This implies the difference in mean HbA1c between pre-T2D MDD individuals and individuals without MDD depends on the time between MDD and T2D diagnoses, the effect of which is constant over T2D disease duration. Having a history of MDD prior to T2D is associated with a 0.92 mmol/mol increase (95% CI: [0.00, 1.84]) in HbA1c, but earlier onset of pre-T2D MDD is associated with lower HbA1c (Table 3). To illustrate this, Fig. 3 plots predicted HbA1c (mmol/mol) over time for four example individuals with either no MDD or with MDD diagnosed 2.2 years, 10.7 years, or 27.5 years before T2D (10th, 50th and 90th percentile of pre-T2D MDD duration at index respectively). Differences in HbA1c between these three pre-T2D MDD individuals and the no MDD individual at any point during follow-up are 0.72 (95% CI: [-0.11, 1.55]), -0.06 (95% CI: [-0.65, 0.54]) and -1.60 (95 CI: [-2.63, -0.57]) for the 10th, 50th and 90th percentile of pre-T2D MDD duration respectively. Those diagnosed with MDD ~ 10 years before T2D have HbA1c levels over time equivalent to those without MDD, with those diagnosed earlier having lower HbA1c and those diagnosed closer to their T2D diagnosis having higher HbA1c. Our example shows that only individuals diagnosed with MDD many decades before T2D have a 95% CI for difference in HbA1c relative to no MDD that excludes 0 (Additional file 3: Table S2a).

Table 2 Unadjusted model selection summary. Model 2, with mean HbA1c being a function of time (four knot restricted cubic spline for T2D disease duration), the pre-T2D MDD exposures and the post-T2D exposures, has the lowest AIC and is selected using likelihood ratio tests (LRTs)
Table 3 Fixed effect estimates for MDD exposure variables from the unadjusted and pooled adjusted linear mixed effects models
Fig. 3
figure 3

Predicted HbA1c (mmol/mol) with 95% confidence intervals from the unadjusted model, for four example individuals: no MDD and three pre-T2D MDD individuals diagnosed with MDD 2.2 (10th percentile), 10.7 (median) and 27.5 (90th percentile) years before T2D

For post-T2D MDD individuals, the unadjusted model included a small, non-significant decrease in HbA1c of -0.50 mmol/mol (95% CI: [-1.63, 0.64]) upon MDD diagnosis (Table 3). This initial MDD diagnosis effect is retained in the model due to the significant semi-continuous post-T2D MDD duration variable, capturing time since post-T2D MDD diagnosis (Table 3). For two post-T2D MDD individuals where MDD is diagnosed one year apart, HbA1c is expected to be 0.53 mmol/mol higher (95% CI: [0.19, 0.87]) in the individual diagnosed with MDD one year earlier (Table 3).

Figure 4 presents predicted HbA1c over time for an individual without MDD and three example individuals diagnosed with MDD 1 year, 3.8 years and 7.1 years after T2D (10th, 50th and 90th percentile respectively). The smaller sample size for the post-T2D MDD group is reflected in wider 95% CI after MDD diagnosis. An initial decrease in HbA1c at MDD diagnosis is followed by a steeper increase in HbA1c, so that a post-MDD individual will have a higher HbA1c three years after MDD diagnosis compared to an individual with no MDD diagnosis (i.e. the 95% CI for the difference between predicted HbA1c for a post-T2D MDD individual and an individual without MDD is expected to exclude 0 after three years). Individuals diagnosed with MDD earlier in their follow-up are expected to have higher HbA1c levels after a 10-year T2D disease duration compared to those with later onset MDD or those without MDD diagnoses (Additional file 3: Table S2b). For example, at the end of the 10-year follow-up, an individual diagnosed with MDD one year after T2D is predicted to have a HbA1c of 60.49 (95% CI: [57.83, 63.15]) compared to 56.19 (95% CI: [55.78, 56.61]) for those without MDD.

Fig. 4
figure 4

Predicted HbA1c (mmol/mol) with 95% confidence intervals from the unadjusted model, for four example individuals: no MDD and three post-T2D MDD individuals diagnosed with MDD 1 (10th percentile), 3.8 (median) and 7.1 (90th percentile) years after T2D

Adjusted model

After adjustment for all covariates, the absolute effect sizes for all MDD exposure variables were reduced (Table 3). In particular, the pre-T2D MDD duration effect size is no longer significant (p = 0.1637) suggesting that, given the included covariates, a history of MDD prior to T2D has no effect on HbA1c trends over T2D disease duration.

For the post-T2D MDD exposures, the pooled results from the adjusted model are similar to those from the unadjusted model. The adjusted model suggests a small, non-significant decrease in HbA1c after a diagnosis with MDD during follow-up (p = 0.2555). The adjusted effect size for post-T2D MDD duration is 0.51 (95% CI: [0.17, 0.86]), showing that earlier MDD diagnosis during follow-up is still associated with higher HbA1c. Full model summaries can be found in Additional file 3: Tables S3 and S4 for the unadjusted and adjusted model respectively.

Within-patient HbA1c variability

Non-convergence in the MI datasets was common for models allowing residual variation to differ by MDD_index (24%) and MDD_change (48%). Pooled results from converged models showed that within-patient variability in HbA1c was approximately the same when comparing pre-T2D MDD individuals (using MDD_index) to all others, and post-T2D MDD (using MDD_change) to all others (Table 4). However, when looking retrospectively for post-T2D MDD individuals (i.e. looking across all follow-up rather than only after MDD diagnosis), we found that within-patient HbA1c variation was 1.16 times higher (95% CI: [1.13. 1.19]) for the post-T2D MDD group compared to no MDD and pre-T2D MDD. This suggests that differences in HbA1c for those who develop MDD after T2D, compared to those with no or pre-existing MDD, start prior to MDD diagnosis.

Table 4 Pooled hypothesis testing for within-subject variability in HbA1c differing by MDD diagnosis. The presented parameter estimate for each MDD diagnosis variable represents the ratio of the residual variance estimate for the MDD level relative to the reference


This study tested the hypothesis that people with both T2D and MDD have poorer diabetic control over the course of T2D, as assessed by routine primary care monitoring of HbA1c, focusing on the role of timing and history of MDD diagnosis relative to T2D. We examined whether UKB participants with T2D and MDD have higher and more variable HbA1c levels over time compared to those with T2D alone. To do so, we utilised exposure variables that differentiated between individuals with a history of MDD before their T2D diagnosis (pre-T2D MDD) and those who received their MDD diagnosis after their T2D diagnosis (post-T2D MDD), while also incorporating time since MDD diagnosis.

For individuals with pre-T2D MDD, longitudinal modelling across 10 years of follow-up found that the time between MDD and T2D diagnoses was informative about HbA1c levels across T2D disease duration. Specifically, individuals diagnosed with MDD decades prior to T2D had lower HbA1c over time compared to individuals without MDD and those diagnosed closer to their T2D diagnosis date. After adjusting for covariates, the pre-T2D MDD variables became non-significant, which may be partly ascribed to the correlation between the time gap from pre-T2D MDD diagnosis to T2D and the age at T2D diagnosis (Spearman’s \(\rho =0.23\)). Here, a longer gap between MDD and T2D diagnoses correlates with a later age at T2D diagnosis (Additional file 3: Table S5). However, the non-significance of pre-T2D MDD exposures after covariate adjustment may also be partly attributed to mediation rather than confounding. For example, increased numbers of pre-T2D measurements for blood pressure, BMI and HbA1c (a proxy for history of healthcare utilisation) were associated with lower HbA1c at T2D diagnosis (Additional file 3: Table S6). Given that an earlier diagnosis with MDD relative to T2D leads to more pre-T2D measurements (Additional file 3: Table S5), it is plausible that mediation is partially responsible for the loss of significance for pre-T2D MDD duration, through increased contact with healthcare professionals. Further work on the impact of pre-T2D MDD is therefore warranted, with extension to additional features of MDD beyond timing of initial diagnosis (e.g. most recent episode, antidepressant prescriptions and number of episodes).

For individuals diagnosed with MDD after T2D, both the unadjusted and adjusted models found that time since MDD diagnosis was important in shaping the trajectory of HbA1c. The earlier the diagnosis of MDD during follow-up, the greater the expected difference in HbA1c between post-T2D MDD individuals and those without MDD at the end of follow-up. Post-T2D individuals also demonstrated some differences in within-patient HbA1c variation. Results suggest that, given the model considered, after diagnosis with MDD during follow-up, within-patient variation does not differ from no MDD and pre-T2D MDD. However, if we look retrospectively across all follow-up and compare post-T2D MDD individuals to all others, we observe that within-patient HbA1c variation is 1.16 times higher for the post-T2D MDD individuals. This greater variability in HbA1c, driven by observations before MDD diagnosis, merits further investigation to ensure appropriate public health and clinical advice is available. Post-T2D MDD individuals may indeed have higher HbA1c variability before MDD diagnosis. This is important because increased variability is associated with increased likelihood of adverse outcomes, including microvascular disease [36]. However, this result may also arise from mean HbA1c trends for post-T2D MDD individuals deviating from those with no or pre-existing MDD before their MDD diagnosis. Given that MDD diagnosis requires the presence of symptoms for two or more weeks, it is plausible that the impact of MDD symptoms on HbA1c begin before formal diagnosis. Additionally, diagnostic delays, as demonstrated in a study of primary care records in Spain (mean delay of 9.89 weeks) [37] may be present. Therefore, exploring the feasibility of using HbA1c trends for MDD prediction in individuals with T2D could be an interesting avenue of research.

Previous work on mean HbA1c has provided inconclusive evidence for the impact of MDD [9]. Nevertheless, in line with our results, two larger studies did find associations between mean HbA1c over time and depression. A meta-analysis found a modest association between depressive symptoms and HbA1c (3-year mean follow-up) [9], and a prospective study in veterans with T2D found that HbA1c was slightly higher for individuals with depression (5-year follow-up) [38].

A previous study [10] showed differences in T2D clinical characteristics by timing of MDD and T2D diagnoses, with a higher rate of diabetic complications in the post-T2D MDD group, but not the pre-TDD MDD group, compared to the no MDD group. Differences in glycaemic control between these MDD subgroups is a possible explanation for the observed clinical differences. The observed increase in HbA1c levels with time since MDD diagnosis for post-T2D MDD individuals, along with the retrospectively identified higher variability across follow-up, supports this hypothesis, demonstrating the potential importance of the relative timing of MDD onset.

Our analysis revealed a linear effect for time since post-T2D MDD diagnosis, meaning the impact of post-T2D MDD increases with years since MDD diagnosis. Due to the smaller sample size of the post-T2D MDD group (n = 226), this study may have been underpowered to detect non-linear trends for this post-T2D MDD duration variable (Additional file 1: Methods S10). Future work using larger samples and different methods of capturing the time between T2D and MDD diagnoses (e.g. joint models for HbA1c over time and time-to-MDD diagnosis) may identify such trends and determine if patients diagnosed with MDD after T2D require closer monitoring, or whether a specific time window is crucial for glycaemic control.

MDD episodes after T2D diagnosis are hypothesised to have a greater effect on glycaemic control, which we have confirmed by showing greater mean and within-subject variability in HbA1c levels for post-T2D MDD individuals. These individuals visited their GP after their T2D diagnosis and had a MDD code recorded. Multiple pathways, particularly behavioural, could explain this association. Several studies have shown that patients with both MDD and T2D have worse T2D self-management, are less able to keep the medical appointments, are less physically active and less able to adhere to dietary requirements, possibly leading to hyperglycaemia [39,40,41]. Our study highlights the importance of diagnosis timing, with possible need for targeted interventions based on clinical history.

This study has several limitations. Firstly, primary care data are collected when patients visit their GP, and between-patient differences in this visiting process can bias results [42, 43]. Individuals with T2D should see their GP every 3–6 months [11] and differences may affect results. For example, less healthy individuals may interact with GPs more frequently and contribute more observations. The models used attempted to reduce this potential bias, as the CAR1 error structure ensured that observations measured closely in time provided less information than those taken far apart. However, T2D cases with MDD may miss more scheduled appointments, and our analysis does not account for this.

Secondly, as a retrospective observational study, confounding may bias results. For example, antidepressant medication can lead to weight gain [44], which can negatively affect HbA1c levels [45]. While we adjusted for confounders such as BMI and blood pressure, these covariates were time invariant, and the timing of measurement differed for each participant (Additional file 1: Methods S6). Future studies could consider time-varying confounding and include additional risk factors (e.g. antidepressant medications, cardiovascular conditions).

Thirdly, HbA1c at T2D diagnosis had a high level of missingness, which disproportionately affected individuals in the post-T2D MDD group and highlights the challenges of working with real-world data. While we utilised MI, this approach has limitations and depends on the model selected and data availability. However, results for the post-T2D MDD exposures were similar in the unadjusted model (no MI required) and the adjusted model (MI used).

The validity of the age at MDD onset, determined using the date of the first MDD diagnostic code, presents a further limitation. For older individuals the validity of their MDD onset is unknown, given primary care records are only available after 1990, while mean age at diagnosis of MDD is around 30 years [46]. Replication in the Clinical Practice Research Datalink, which has GP records from 1987 and no age limits, would therefore be useful [47].


This study, utilising UKB primary care records, highlights the importance of considering the temporal relationships between T2D and MDD in the context of glycaemic control. Findings reveal a non-linear trend in HbA1c levels over time and demonstrated that within a 10-year window, those who develop MDD after T2D diagnosis had increased HbA1c levels and, prior to MDD diagnosis, greater variability, supporting the finding that individuals with both conditions have poorer health outcomes. Regular routine screening for depression, integrated mental health support and closer monitoring may reduce the adverse consequences associated with both T2D and MDD.

Availability of data and materials

The data used in this study are available for approved researchers from the UK Biobank. Permissions are required to access UK Biobank data. Researchers can register and apply at R code used for data management and analysis are available here:



Glycated haemaglobin


Type 2 diabetes


Major depressive disorder


UK Biobank


General practioner


Polygenic score


Body mass index


Systolic blood pressure


Diastolic blood pressure


Mixed effects model


Continuous-time autoregressive 1


Likelihood ratio test


Multiple imputation


Confidence interval


Interquartile range


Hospital episode statistics


  1. Holt RIG, de Groot M, Golden SH. Diabetes and depression. Curr DiabRep. 2014;14:491.

    Article  CAS  Google Scholar 

  2. Knol MJ, Twisk JWR, Beekman ATF, Heine RJ, Snoek FJ, Pouwer F. Depression as a risk factor for the onset of type 2 diabetes mellitus. A meta-analysis Diabetologia. 2006;49:837.

    Article  CAS  PubMed  Google Scholar 

  3. Mezuk B, Eaton WW, Albrecht S, Golden SH. Depression and type 2 diabetes over the lifespan. Diabet Care. 2008;31:2383.

    Article  PubMed  PubMed Central  Google Scholar 

  4. Nouwen A, Adriaanse MC, van Dam K, Iversen MM, Viechtbauer W, Peyrot M, et al. Longitudinal associations between depression and diabetes complications: a systematic review and meta-analysis. Diabet Med. 2019;36:1562–72.

    Article  CAS  PubMed  Google Scholar 

  5. Wu C, Hsu L, Wang S. Association of depression and diabetes complications and mortality: a population-based cohort study. epidemiology and psychiatric sciences 2020;29.

  6. Martín-Timón I, Sevillano-Collantes C, Segura-Galindo A, Del Cañizo-Gómez F. Type 2 diabetes and cardiovascular disease: Have all risk factors the same strength? World J Diabetes. 2014;5:444–70.

    Article  PubMed  PubMed Central  Google Scholar 

  7. Gorst C, Kwok CS, Aslam S, Buchan I, Kontopantelis E, Myint PK, et al. Long-term glycemic variability and risk of adverse outcomes: a systematic review and meta-analysis. Diabet Care. 2015;38:2354–69.

    Article  CAS  PubMed  Google Scholar 

  8. Sherwani S, Khan H, Ekhzaimy A, Masood A, Sakharkar M. Significance of HbA1c Test in diagnosis and prognosis of diabetic patients. Biomarker Insight. 2016;11:95–104.

    Article  CAS  Google Scholar 

  9. Beran M, Muzambi R, Geraets A, Albertorio-Diaz JR, Adriaanse MC, Iversen MM, et al. The bidirectional longitudinal association between depressive symptoms and HbA1c : A systematic review and meta-analysis. Diabet Med. 2022;39: e14671.

    Article  CAS  PubMed  Google Scholar 

  10. Bruce DG, Davis WA, Cetrullo V, Starkstein SE, Davis TME. Clinical impact of the temporal relationship between depression and type 2 diabetes: the fremantle diabetes study phase II. PLoS ONE. 2013;8: e81254.

    Article  CAS  PubMed  PubMed Central  Google Scholar 

  11. McGuire H, Longson D, Adler A, Farmer A, Lewin I. Management of type 2 diabetes in adults: summary of updated NICE guidance. BMJ. 2016;353: i1575.

    Article  PubMed  Google Scholar 

  12. Sudlow C, Gallacher J, Allen N, Beral V, Burton P, Danesh J, et al. UK Biobank: An open access resource for identifying the causes of a wide range of complex diseases of middle and old age. PLoS Med. 2015;12: e1001779.

    Article  PubMed  PubMed Central  Google Scholar 

  13. The UK Biobank. Primary Care Linked Data 2024.

  14. Hagenaars SP, Coleman JRI, Choi SW, Gaspar H, Adams MJ, Howard DM, et al. Genetic comorbidity between major depression and cardio-metabolic traits, stratified by age at onset of major depression. Am J Med Genet B Neuropsychiatr Genet. 2020;183:309–30.

    Article  PubMed  PubMed Central  Google Scholar 

  15. Bycroft C, Freeman C, Petkova D, Band G, Elliott LT, Sharp K, et al. The UK Biobank resource with deep phenotyping and genomic data. Nature. 2018;562:203–9.

    Article  CAS  PubMed  PubMed Central  Google Scholar 

  16. Farmer RE, Beard I, Raza SI, Gollop ND, Patel N, Tebboth A, et al. Prescribing in type 2 diabetes patients with and without cardiovascular disease history: a descriptive analysis in the UK CPRD. Clin Ther. 2021;43:320–35.

    Article  CAS  PubMed  Google Scholar 

  17. Holm N-CR, Belstrøm D, Østergaard JA, Schou S, Holmstrup P, Grauballe MB. Identification of individuals with undiagnosed diabetes and pre-diabetes in a Danish cohort attending dental treatment. J Periodontol 2016;87:395–402.

  18. Fabbri C, Hagenaars SP, John C, Williams AT, Shrine N, Moles L, et al. Genetic and clinical characteristics of treatment-resistant depression using primary care records in two UK cohorts. Mol Psychiatry. 2021;26:3363–73.

    Article  PubMed  PubMed Central  Google Scholar 

  19. NGSP. IFCC Standardization of HbA1c n.d.

  20. Young KG, McDonald TJ, Shields BM. Glycated haemoglobin measurements from UK Biobank are different to those in linked primary care records: implications for combining biochemistry data from research studies and routine clinical care. Int J Epidemiol. 2022;51:1022–4.

    Article  PubMed  Google Scholar 

  21. Ko S, German CA, Jensen A, Sinsheimer JS, Zhou H, Zhou JJ. GWAS of longitudinal trajectories at biobank scale. AJHG. 2022;109:433–45.

    Article  CAS  PubMed  PubMed Central  Google Scholar 

  22. Bhaskaran K, Forbes HJ, Douglas I, Leon DA, Smeeth L. Representativeness and optimal use of body mass index (BMI) in the UK Clinical Practice Research Datalink (CPRD). BMJ Open 2013;3.

  23. Hanscombe K. ukbkings: KCL interface to UKB Project Data on Rosalind/CREATE HPC. 2022. Available online:

  24. Scott RA, Scott LJ, Mägi R, Marullo L, Gaulton KJ, Kaakinen M, et al. An Expanded Genome-Wide Association Study of Type 2 Diabetes in Europeans. Diabetes. 2017;66:2888–902.

    Article  CAS  PubMed  PubMed Central  Google Scholar 

  25. Choi SW, O’Reilly PF. PRSice-2: Polygenic Risk Score software for biobank-scale data. GigaScience 2019;8:giz082.

  26. Choi SW, Mak TS-H, O’Reilly PF. Tutorial: a guide to performing polygenic risk score analyses. Nature Protocols 2020;15:2759–72.

  27. Pinheiro J, Bates D. Mixed-Effects Models in S and S-PLUS. New York: Springer; 2000.

    Book  Google Scholar 

  28. Pinheiro J, Bates D, R Core Team. nlme: Linear and nonlinear mixed effects models. 2022. R package version 3.1-159.

  29. Harrell F. Regression Modeling Strategies: With applications to linear models, logistic regression, and survival analysis. New York: Springer-Verlag; 2001.

  30. Gauthier J, Wu QV, Gooley TA. Cubic splines to model relationships between continuous variables and outcomes: a guide for clinicians. Bone Marrow Transplant. 2020;55:675–80.

    Article  CAS  PubMed  Google Scholar 

  31. Honaker J, King G, Blackwell M. Amelia II: A Program for Missing Data. J Stat Soft. 2011;45:1–47.

    Article  Google Scholar 

  32. Li K-H, Meng X-L, Raghunathan TE, Rubin DB. Significance levels from repeated p-values with multiply-imputed data. Stat Sin. 1991;1:65–92.

  33. Marshall A, Altman DG, Holder RL, Royston P. Combining estimates of interest in prognostic modelling studies after multiple imputation: current practice and guidelines. BMC Med Res Methodol. 2009;9:57.

    Article  PubMed  PubMed Central  Google Scholar 

  34. Shepherd BE, Rebeiro PF, the Caribbean C and SA network for H epidemiology. Brief report: assessing and interpreting the association between continuous covariates and outcomes in observational studies of HIV using splines. J Acquir Immune Defic Syndr 2017;74.

  35. Perperoglou A, Sauerbrei W, Abrahamowicz M, Schmid M. A review of spline function procedures in R. BMC Med Res Methodol. 2019;19:46.

    Article  PubMed  PubMed Central  Google Scholar 

  36. Škrha J, Šoupal J, Škrha J, Prázný M. Glucose variability, HbA1c and microvascular complications. Rev Endocr Metab Disord. 2016;17:103–10.

    Article  CAS  PubMed  Google Scholar 

  37. Huerta-Ramírez R, Bertsch J, Cabello M, Roca M, Haro JM, Ayuso-Mateos JL. Diagnosis delay in first episodes of major depression: A study of primary care patients in Spain. J Affect Disord. 2013;150:1247–50.

    Article  PubMed  Google Scholar 

  38. Richardson LK, Egede LE, Mueller M, Echols CL, Gebregziabher M. Longitudinal effects of depression on glycemic control in veterans with Type 2 diabetes. Gen Hosp Psychiatry. 2008;30:509–14.

    Article  PubMed  Google Scholar 

  39. Schmitt A, Reimer A, Hermanns N, Kulzer B, Ehrmann D, Krichbaum M, et al. Depression is linked to hyperglycaemia via suboptimal diabetes self-management: A cross-sectional mediation analysis. J Psychosom Res. 2017;94:17–23.

    Article  PubMed  Google Scholar 

  40. Lustman PJ, Clouse RE. Depression in diabetic patients: The relationship between mood and glycemic control. J Diabetes Complications. 2005;19:113–22.

    Article  PubMed  Google Scholar 

  41. Gonzalez JS, Peyrot M, McCarl LA, Collins EM, Serpa L, Mimiaga MJ, et al. Depression and diabetes treatment nonadherence: a meta-analysis. Diabetes Care. 2008;31:2398.

    Article  PubMed  PubMed Central  Google Scholar 

  42. Lokku A, Lim LS, Birken CS, Pullenayegum EM, on behalf of the TARGet Kids! Collaboration. Summarizing the extent of visit irregularity in longitudinal data. BMC Medical Research Methodology 2020;20:135.

  43. Kalia S, Saarela O, Escobar M, Moineddin R, Greiver M. Estimation of marginal structural models under irregular visits and unmeasured confounder: calibrated inverse probability weights. BMC Med Res Methodol. 2023;23:4.

    Article  CAS  PubMed  PubMed Central  Google Scholar 

  44. Gafoor R, Booth HP, Gulliford MC. Antidepressant utilisation and incidence of weight gain during 10 years’ follow-up: population based cohort study. BMJ 2018;361.

  45. Gummesson A, Nyman E, Knutsson M, Karpefors M. Effect of weight reduction on glycated haemoglobin in weight loss trials in patients with type 2 diabetes. Diabetes Obes Metab. 2017;19:1295–305.

    Article  CAS  PubMed  Google Scholar 

  46. Kessler RC, Berglund P, Demler O, Jin R, Merikangas KR, Walters EE. Lifetime prevalence and age-of-onset distributions of DSM-IV Disorders in the national comorbidity survey replication. Arch Gen Psychiatry. 2005;62:593–602.

    Article  PubMed  Google Scholar 

  47. Herrett E, Gallagher AM, Bhaskaran K, Forbes H, Mathur R, van Staa T, et al. Data resource profile: clinical practice research datalink (CPRD). Int J Epidemiol. 2015;44:827–36.

    Article  PubMed  PubMed Central  Google Scholar 

  48. King’s College London. King’s Computational research, engineering and technology environment (CREATE). 2022.

Download references


This research has been conducted using the UKB Resource under Application Number 82087- we are grateful to all UKB staff and participants. The authors acknowledge use of the research computing facility at King’s College London, CREATE [48]. For the purpose of open access, the author has applied a Creative Commons Attribution (CC BY) licence to any Author Accepted Manuscript version arising.


This paper represents independent research part-funded by the National Institute for Health Research (NIHR) Maudsley Biomedical Research Centre at South London and Maudsley NHS Foundation Trust and King’s College London. The views expressed are those of the author(s) and not necessarily those of the NHS, the NIHR, or the Department of Health and Social Care. This research is supported by the Medical Research Council (MR/S0151132; MR/N015746; MR/X009815/1). JT and FC are supported by an Academy of Medical Sciences (AMS) Springboard award, which is supported by the AMS, the Wellcome Trust, GCRF, the Government Department of Business, Energy and Industrial strategy, the British Heart Foundation and Diabetes UK [SBF004\1079]. KGY is supported by Research England’s Expanding Excellence in England (E3) fund. HG is funded by an E3 Independent Research Fellowship.

Author information

Authors and Affiliations



ACG, SPH, JT, CML and FC contributed to the conception of this study. ACG, SPH, JT and CML contributed to the study design. KGY and HG advised on using primary care records for the analysis of T2D patients. ACG, SPH and DH conducted the T2D validation, including PGS creation. ACG conducted the longitudinal analysis. ACG and SPH wrote the first draft, and CML and JT were major contributors to writing the manuscript. All authors read and approved the final manuscript.

Authors’ Twitter handles

Alexandra Gillett: @alex_c_gillett.

Cathryn Lewis: @cathrynlewis.

Jess Tyrrell: @JSTyrrell.

Corresponding author

Correspondence to Alexandra C. Gillett.

Ethics declarations

Ethics approval and consent to participate

This research has been conducted using the UK Biobank Resource under Application Number 82087, with ethical approval granted by the NHS North West Research Ethics Committee (REC reference 11/NW/0382). All participants gave informed consent to participate and be followed up through data-linkage.

Consent for publication

Not applicable.

Competing interests

No potential or existing conflicts of interest relevant to this article were reported.

Additional information

Publisher’s Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Supplementary Information


Additional file 1: Supplementary methods. Methods S1- Participant-level QC for analysis with genetic data. Methods S2- Diabetic medicine extraction and variable creation. Methods S3- T2D diagnosis exclusion criteria. Methods S4- Valid HbA1c. Methods S5- MDD diagnosis. Methods S6- BMI, SBP and DBP at T2D diagnosis. Methods S7- T2D polygenic score. Methods S8- Residual within-subject variability analysis. Methods S9- Multiple imputation. Methods S10- Non-linear time-trend for post-T2D MDD individuals.


Additional file 2: Supplementary Tables for the Methods section of the main paper. Table S1- GP codes for diabetes. Table S2- HES codes for diabetes (ICD9 and 10 codes). Table S3- Glucose lowering medication codes. Table S4- HbA1c read 2 and read 3 codes. Table S5- Sensitivity analysis excluding covariates not measured approximately at T2D diagnosis. Table S6- Details on all variables extracted for this analysis. Table S7- Description of which variables are used in the fixed effects model for all models run in this study.


Additional file 3: Supplementary Tables for the Results section of the main paper. Table S1- Validation of T2D diagnosis: Association between T2D case-control status and T2D polygenic scores. Table S2- Predicted HbA1c values (mmol/mol) over time (years), with 95% CIs, from the unadjusted model for a selection of hypothetical example individuals. Table S3- Unadjusted model summary. Table S4- Adjusted model summary (pooled from 50 MI datasets). Table S5- Exploring the relationship between pre-T2D MDD duration, up to T2D diagnosis, and covariates. Table S6- Characterising those missing HbA1c at T2D diagnosis.


Additional file 4: Supplementary Figures S1-S8. All figures present a density plot for a continuous variable stratified by MDD subgroup. Figure S1- TDI (at UKB initial assessment). Figure S2- Age (years) at T2D diagnosis. Figure S3- Follow-up time (years). Figure S4- Total number of observations prior to T2D diagnosis. Figure S5- BMI at T2D diagnosis. Figure S6- SBP at T2D diagnosis. Figure S7- DBP at T2D diagnosis. Figure S8- HbA1c (mmol/mol) at T2D diagnosis.

Rights and permissions

Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit The Creative Commons Public Domain Dedication waiver ( applies to the data made available in this article, unless otherwise stated in a credit line to the data.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Gillett, A.C., Hagenaars, S.P., Handley, D. et al. The impact of major depressive disorder on glycaemic control in type 2 diabetes: a longitudinal cohort study using UK Biobank primary care records. BMC Med 22, 211 (2024).

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: