Introduction

Epilepsy is one of the most common neurological conditions, affecting over 70 million people worldwide1. Physicians frequently face questions from people with epilepsy concerning physical activity (PA): “Can I engage in physical activities? What level of activity is appropriate for me?” While recent systematic reviews affirm that physical exercise may improve quality of life for the people with epilepsy, such as enhancing fitness and cognitive without increasing seizure frequency2, clinical recommendations remain inconsistent, with most physicians still relying on personal experience or general guidelines rather than individualized, evidence-based advice3. The lack of clear, personalized physical activity guidance for people with epilepsy underscores a critical gap in current practice and highlights the ongoing uncertainty in evidence-based PA management4.

In the general population, appropriate duration and intensity of PA markedly reduce all-cause mortality, cardiovascular disease risk, and incidence of metabolic syndrome5,6. However, managing PA in people with epilepsy is more complex and challenging. Epilepsy is often associated with a higher prevalence of comorbidities, including psychiatric conditions (e.g., depression) and somatic diseases (e.g., cardiovascular disease and diabetes)7,8, which further complicates PA-related decision-making. In some cases, excessive activity may even trigger seizures. Nonetheless, appropriate PA remains essential for improving overall health outcomes, enhancing quality of life, and mitigating health risks in this population.

Evidence suggests that moderate PA helps improve cognitive function and alleviate psychological issues, including anxiety and depression in individuals with epilepsy9, while also enhancing their quality of life and capacity for independent living10. These positive effects may be attributed to PA’s modulation of neurotransmitters, enhancement of neuroplasticity, and improvement of cerebral blood flow. However, both insufficient and excessive levels of physical activity may have adverse effects on individuals with epilepsy. Prolonged sedentary behaviour and low activity levels are associated with increased risks of cardiovascular dysfunction, metabolic disorders (e.g., obesity), and osteoporosis, all of which contribute to higher mortality rates11,12. In contrast, high-intensity PA may trigger seizures by increasing neuronal excitability and stress responses, potentially leading to accidental injuries or even death13. Therefore, identifying appropriate PA patterns for people with epilepsy, particularly those with comorbid conditions, and quantifying optimal levels is crucial for developing effective and personalised health management strategies.

Objective measurement of PA has transformed our understanding of physical behaviour in individuals with epilepsy. Earlier studies largely relied on self-reported questionnaires, which are subject to recall bias and limited accuracy3. The advent of wearable accelerometers enables continuous and objective monitoring of activity patterns, providing a more reliable assessment of physical behaviour14,15,16. Recent investigations analysing data collected from wearable accelerometers have showed that people with epilepsy, especially those with drug-resistant epilepsy, tend to be more sedentary and less physically active than controls, with increased sedentary time associated with poorer postural stability and reduced quality of life17,18. Moreover, wearable devices have been effectively integrated into exercise interventions, with randomized trials in children demonstrating improvements in fitness and well-being without increased risk of seizures19. Despite these advances, a lack of large-scale, longitudinal data and the absence of advanced analytic approaches limit our ability to determine how objectively measured PA influences long-term outcomes. Addressing these gaps is essential to guide the development of personalized management strategies.

In this study, we analysed accelerometer data from 98,561 UK Biobank participants, including 1137 people with epilepsy. We integrated standard epidemiological and explainable machine learning methods to (i) quantify associations and dose-response relationships between objectively measured PA and mortality, and (ii) evaluate the predictive value of accelerometer-derived features for individualised risk stratification. We found that people with epilepsy had a higher mortality risk compared to people without epilepsy (Standardized mortality ratio: 2.39), with distinct physical activity-mortality associations that differed markedly from the general population. Our analysis revealed counterintuitive findings where higher sedentary behaviour was associated with lower mortality risk in people with epilepsy, contrasting with patterns in people without epilepsy. Our machine learning approach incorporating accelerometer features achieved 87% AUC in mortality prediction, representing a significant improvement over demographic and health condition-only models (78% AUC). Our results provide quantitative evidence for evidence-based, personalised PA management in epilepsy and set the stage for digital precision medicine in this field.

Results

This study integrated large-scale, device-measured PA data, clinical information, and survival outcomes to comprehensively evaluate associations between PA patterns and mortality in people with epilepsy (Fig. 1). The analytic workflow consisted of four main components: First, we collected accelerometer-based 7-day PA data, mortality outcomes, and demographic/clinical covariates from 98,561 UK Biobank participants. Second, we characterized PA exposures (sedentary, light, and moderate-to-vigorous PA durations) and conducted primary analyses of temporal activity patterns and standardized mortality ratios. Third, we performed in-depth statistical analyses, including correlation analyses, multivariable Cox regression, dose–response relationships, sensitivity and subgroup analyses, and explored both all-cause and cause-specific mortality. Finally, we developed and evaluated a machine learning model for mortality prediction using both clinical and PA features, and designed a digital PA management tool for people with epilepsy based on our findings.

Fig. 1: Study framework for physical activity patterns and mortality risk analysis in people with epilepsy.
figure 1

a Study population including 1167 people with epilepsy and 97,394 controls with 7-day accelerometer data. b Mortality ascertainment for all-cause and cause-specific deaths including cardiovascular, cancer, and epilepsy-related mortality. c Comprehensive demographic and clinical characteristics collection including age, education, smoking status, alcohol use, BMI, overall health, disability status, and Charlson Comorbidity Index. d Physical activity exposure measurements including daily sedentary duration, light PA duration, and MVPA duration (min/day). e Primary analysis incorporating temporal distribution analysis and standardized mortality ratio analysis across groups. f In-depth statistical analysis including correlation analysis of PA patterns with mortality outcomes, proportional hazards regression for all-cause and cause-specific mortality, dose-response analysis, and optimal PA threshold determination across demographic subgroups. g Machine learning framework for mortality prediction using GridSearchCV for kernel SVM with feature extraction, model development and interpretable analysis incorporating PA pattern features (sedentary, light PA, and MVPA duration) and signal features (statistical, time domain, and frequency domain features). h EpiActivity Manager design for PA management and health monitoring in people with epilepsy using smartwatch technology.

Participant Characteristics

We included 98,561 participants who reported their PA-derived temporal duration indicator data derived from sedentary behaviour(hours/day), light physical activity (LPA, hours/day), and moderate-to-vigorous physical activity (MVPA hours/day). The cohort included 1167 (1.2%) people with epilepsy and 97,394 (98.8%) people without epilepsy. During a median follow-up of 7.1 years, we observed 4128 deaths (116 (9.9%) in the epilepsy group vs. 4012 (4.1%) in the group without epilepsy) (Table 1). Using standardized mortality ratio (SMR) adjusted for age and gender with people without epilepsy as the reference, people with epilepsy had a significantly higher mortality rate (SMR: 2.39, 95% CI: 1.97-2.86, p < 0.001). Among people with epilepsy who died during the follow-up period, the primary causes of mortality were cancer (n = 60), cardiovascular diseases (n = 35), cerebrovascular diseases (n = 13), and epilepsy (n = 9). The mean time from baseline assessment to death was 5 years (median: 5, range: 1–9 years). Detailed demographic and clinical characteristics for survivors and cause-specific mortality cases among people with epilepsy are provided in Supplementary Tables 1–5.

Table 1 Baseline characteristics of 98,561 participants

Interaction effect between epilepsy and physical activity on mortality

To explore whether the association between PA patterns and mortality differed between people with and without epilepsy, we conducted interaction analyses using Cox proportional hazards models with the entire cohort after adjusting for covariates. We observed significant interactions for sedentary behaviour duration (HR: 0.85, 95% CI: 0.77-0.93, p < 0.001) and MVPA duration (HR: 1.55, 95% CI: 1.09-2.21, p = 0.016) with epilepsy status, indicating that the relationships between these PA patterns and mortality risk varied between people with and without epilepsy. There was insufficient evidence to conclude that a different effect of LPA on mortality in people with or without epilepsy (HR: 1.09, 95% CI: 0.97-1.23, p = 0.132) (Supplementary Table 6).

Mortality differences in epilepsy with diverse physical activity patterns

To explore differences in daily PA profiles among individuals with epilepsy, we examined 24-h accelerometer-derived PA patterns stratified by survival status (Fig. 2a). Individuals who subsequently experienced all-cause mortality showed consistently lower average acceleration intensity across the day compared to survivors, with the largest differences observed during daytime hours (08:00–22:00). Patterns of 24-h PA by survival status and cause-specific mortality groups are shown in Supplementary Fig. 1.

Fig. 2: Physical activity (PA) patterns and standardized mortality ratios across activity tertiles in people with and without epilepsy.
figure 2

a Hour-level PA patterns showing mean acceleration (milligravity) over 24 h for survivors (blue, n = 1051) and deceased participants (orange, n = 116). The center line denotes the mean and shaded bands indicate 95% confidence intervals (CIs). Hourly values were computed as participant-level means. b Standardized mortality ratios (SMRs) comparing people with epilepsy (orange) to people without epilepsy (blue; reference) across sedentary tertiles. Bars show SMR point estimates with 95% CIs (Byar’s approximation). Across tertiles 1–3, the sample sizes were n = 352/387/428 for people with epilepsy and n = 33,464/33,277/30,653 for people without epilepsy. Statistical significance was assessed using two-sided exact Poisson tests. c SMRs across light PA tertiles, with people without epilepsy as the reference. The sample sizes by tertile were n = 491/358/318 (people with epilepsy) and n = 32,879/32,178/32,337 (people without epilepsy). Statistical comparisons were performed using two-sided exact Poisson tests. d SMRs across moderate-to-vigorous PA tertiles, again using people without epilepsy as the reference. The corresponding sample sizes were n = 590/305/272 and n = 41,504/26,991/28,899, with statistical significance evaluated by two-sided exact Poisson tests. e Internal SMRs (ISMRs) by sedentary tertiles within each group, using the lowest tertile as the internal reference. The sample sizes were n = 352/387/428 (people with epilepsy) and n = 33,464/33,277/30,653 (people without epilepsy). Comparisons between tertiles were analyzed using two-sided exact Poisson tests. f Internal SMRs by light PA tertiles (reference=lowest tertile). Sample sizes were n = 491/358/318 and n = 32,879/32,178/32,337. Statistical significance was determined using two-sided exact Poisson tests. g Internal SMRs by moderate-to-vigorous PA tertiles (reference=lowest tertile). Sample sizes were n = 590/305/272 and n = 41,504/26,991/28,899. Two-sided exact Poisson tests were used for statistical comparisons. Red dashed lines indicate the reference. No adjustments for multiple comparisons were applied. n denotes independent participants.

Motivated by this preliminary finding, we further stratified participants by overall PA levels to evaluate how different PA domains contribute to mortality risk derived from the entire cohort. For each tertile, we computed external SMRs (comparing people with epilepsy to people without epilepsy as a reference within that tertile) and internal SMRs (comparing higher tertiles to the lowest tertile within each group). Across tertiles, external SMRs showed that people with epilepsy consistently had higher mortality than people without epilepsy in the same tertile (Fig. 2b–d). Internal SMRs revealed that, among people with epilepsy, only the middle MVPA tertile (0.4–0.8 h/day) was associated with lower mortality compared to the lowest tertile (< 0.4 h/day; SMR: 1.48, 95% CI: 1.08–2.02, p = 0.043). In contrast, among individuals without epilepsy, higher LPA and MVPA tertiles were associated with lower mortality, while higher sedentary time was associated with increased mortality risk (all p < 0.001; Fig. 2e–g).

Clinical and demographic correlates of physical activity patterns

We conducted multivariable analyses to examine the associations between PA patterns and key clinical and demographic characteristics (Fig. 3). The Spearman’s correlation heatmap reveals that sedentary behaviour, LPA, and MVPA are significantly correlated with several demographic and clinical variables (Fig. 3a). For continuous significant variables, BMI showed positive correlation with sedentary time (r = 0.22, p < 0.001) and negative correlations with LPA (r = −0.21, p < 0.001) and MVPA (r = −0.24, p < 0.001) (Fig. 3b–d). Charlson comorbidity score was positively associated with sedentary time (r = 0.07, p = 0.015) and negatively related to LPA (r = −0.12, p < 0.001) and MVPA (r = −0.17, p < 0.001) (Fig. 3e–g). For categorical variables, significant differences in PA patterns were observed by gender (Fig. 3h–j), disability status (Fig. 3k–m), education level (Fig. 3n–p), and overall health status (Fig. 3q-s). Men showed higher sedentary time and MVPA and lower LPA compared to women (all p < 0.01). Participants with long-term disability had more sedentary time and less LPA and MVPA (all p < 0.05). Higher education level was associated with higher sedentary time (p = 0.008), MVPA (p < 0.001) and lower LPA (p = 0.049) among people with epilepsy. Those reporting excellent health had the most favourable PA profiles, while those in poor health had the least (p < 0.001). Comparable patterns in people without epilepsy are presented in Supplementary Table 7.

Fig. 3: Associations between physical activity and covariates in people with epilepsy.
figure 3

a Spearman correlation heatmap showing associations between sedentary duration, light physical activity (LPA), and moderate-to-vigorous physical activity (MVPA) and covariates. Colors encode Spearman correlation coefficients. b–d Scatter plots showing relationships between BMI and (b) sedentary duration, c LPA, and (d) MVPA. Each point is one independent participant. The solid line is the regression fit; the shaded band denotes the 95% confidence interval. Statistics are Spearman’s rank correlation, two-sided; r and P are shown in-panel. Center and error: regression line and 95% CI. e–g Scatter plots showing relationships between Charlson comorbidity score and (e) sedentary duration, f LPA, and (g) MVPA. Each point is one independent participant. The solid line denotes the regression fit with 95% confidence band. Statistics are Spearman’s rank correlation, two-sided; r and P are shown in-panel. Center and error: regression line and 95% CI. h–j Box plots comparing (h) sedentary duration, i LPA, and (j) MVPA between males and females. Sample sizes per box: Male (n = 559), Female (n = 608). k–m Box plots comparing (k) sedentary duration, l LPA, and (m) MVPA between participants with and without long-term disability. Sample sizes per box: Yes (n = 734), No (n = 433). n–p Box plots comparing (n) sedentary duration, o LPA, and (p) MVPA across education levels. Sample sizes per box: Below college degree (n = 681), Above college degree (n = 486). q–s Box plots comparing (q) sedentary duration, r LPA, and (s) MVPA across self-rated overall health categories. Sample sizes per box: Excellent (n = 161), Good (n = 608), Fair (n = 306), Poor (n = 92). Box-plot definitions (applies to h–s): center line = median; box bounds = 25th and 75th percentiles (IQR); whiskers extend to 1.5 × IQR; points beyond whiskers are outliers. For two-group comparisons (gender, long-term disability, education level), group differences were evaluated using two-sided independent-samples t tests (Welch’s correction). n denotes the number of independent participants; For scatter plots, center and error refer to the fitted line and its 95% CI. All statistical tests were two-sided, and P values < 0.001 are reported in scientific notation in panels.

Physical activity patterns and all-cause mortality

We employed Cox proportional hazards regression to examine the associations between PA patterns and all-cause mortality, with HRs representing the change in mortality risk per one-h increment in each PA variable. The results description is based on fully adjusted models (Model 3), and reported p-values are corrected for multiple comparisons. Among people with epilepsy, higher sedentary duration (hours/day) was associated with lower all-cause mortality (HR: 0.87, 95%CI: 0.78–0.97, p = 0.047). No statistically significant associations were observed between either LPA duration (hours/day) or MVPA duration (hours/day) and mortality (LPA: HR: 0.91, 95% CI: 0.80–1.04, p = 0.268; MVPA: HR: 0.89, 95% CI: 0.61–1.30, p = 0.539). Cox proportional hazards regression results for covariates in the fully adjusted model for individuals with epilepsy are presented in Supplementary Table 8. Among individuals without epilepsy, sedentary duration was not significantly associated with all-cause mortality (HR: 1.01, 95% CI: 0.99–1.03, p = 0.264), whereas both higher LPA and MVPA were significantly associated with lower mortality risk (LPA: HR: 0.94, 95% CI: 0.92–0.96, p < 0.001; MVPA: HR: 0.82, 95% CI: 0.77–0.88, p < 0.001) (Table 2).

Table 2 Hazard ratios (95% CI) for all-cause mortality according to PA among people with and without epilepsy

Dose–response associations between PA variables and all-cause mortality were evaluated using Cox proportional hazards regression models with restricted cubic spline (RCS) functions to flexibly characterize potential nonlinear relationships. Among people with epilepsy, both the PA-adjusted and fully adjusted models indicated nonlinear associations between PA and all-cause mortality risk. Specifically, in the fully adjusted model, sedentary behaviour duration between 7 and 13 h per day was associated with lower all-cause mortality rate (p nonlinear=0.025), with the lowest estimated hazard ratio observed at 10.9 h/day (HR: 0.56, 95% CI: 0.36–0.85); For LPA, a significant nonlinear association was present only in the PA-adjusted model (Supplementary Fig. 2). For MVPA, the fully adjusted model also showed a nonlinear association, durations between 0.1 and 0.2 h per day were associated with lower mortality (p nonlinear=0.005), with the nadir at 0.2 h/day (HR: 0.69, 95% CI: 0.51–0.93) (Fig. 4a–c). Among individuals without epilepsy, sedentary duration exhibited a U-shaped association with mortality risk; however, across the entire observed range, longer sedentary time was still associated with higher mortality rate. In contrast, both LPA and MVPA showed L-shaped relationships, with greater durations strongly associated with lower mortality rate (Supplementary Fig. 3).

Fig. 4: Dose-response relationships between physical activity patterns and cause-specific mortality risk in people with epilepsy.
figure 4

a All-cause mortality hazard ratios by sedentary duration. b All-cause mortality hazard ratios by light physical activity duration. c All-cause mortality hazard ratios by moderate-to-vigorous physical activity duration. d Cardiovascular death hazard ratios by sedentary duration. e Cardiovascular death hazard ratios by light physical activity duration. f Cardiovascular death hazard ratios by moderate-to-vigorous physical activity duration. g Cerebrovascular death hazard ratios by sedentary duration. h Cerebrovascular death hazard ratios by light physical activity duration. i Cerebrovascular death hazard ratios by moderate-to-vigorous physical activity duration. j Epilepsy death hazard ratios by sedentary duration. k Epilepsy death hazard ratios by light physical activity duration. l Epilepsy death hazard ratios by moderate-to-vigorous physical activity duration. m Cancer death hazard ratios by sedentary duration. n Cancer death hazard ratios by light physical activity duration. o Cancer death hazard ratios by moderate-to-vigorous physical activity duration. The red solid curve is the point estimate of the hazard ratio (center) from the restricted cubic spline (RCS) Cox model; the pink shaded band denotes the model-based 95% confidence interval (error band) around the estimated HR. Overall and non-linear association P values are from Wald tests of the spline terms (anova on the RCS model), two-sided. The number of knots was selected by minimum AIC. The reference exposure is the prob-quantile (prob=0.10), at which HR = 1.

Physical Activity Patterns and Cause-Specific Mortality

In contrast, for associations between PA patterns and specific-causes mortality, despite Cox proportional hazard analysis capturing no significant associations (Supplementary Table 9) among people with epilepsy, RCS analysis suggests complex relationships between PA patterns and cause-specific mortality. Sedentary behaviour showed a linear relationship between epilepsy cause mortality (p = 0.027) and cancer cause mortality (p = 0.011). LPA shows a nonlinear relationship with cardiovascular cause (p = 0.033), cerebrovascular cause (p = 0.045) mortality and epilepsy cause mortality (p = 0.037). MVPA shows nonlinear relationship with cardiovascular cause mortality (p = 0.005) (Fig. 4d-o).

Subgroup and comorbidity analysis

In gender-stratified analyses, no significant associations were observed between PA patterns and all-cause mortality in women after fully adjustment and multiple testing corrections. In men, greater sedentary duration was associated with lower mortality risk (HR: 0.84, 95% CI: 0.73–0.96, p = 0.028), while LPA and MVPA were not significantly associated with mortality (Supplementary Table 10). RCS analyses in men demonstrated a nonlinear inverse association between sedentary duration and all-cause mortality risk (p-overall=0.003, p-nonlinear=0.018), with the risk decreasing and plateauing at higher durations. No significant nonlinear associations were identified for LPA or MVPA in either gender (Supplementary Fig. 4). No significant associations were found for any PA patterns in age-based subgroups after fully adjustment (Supplementary Table 11). RCS analyses revealed that in participants aged ≥65 years, sedentary duration showed a nonlinear trend toward lower mortality risk (p-nonlinear=0.042), while in those <65 years, no significant nonlinear associations were observed (Supplementary Fig. 5).

To assess potential effect modification by comorbidities, we first tested for statistical interactions between each PA patterns and the presence of individual comorbidities in relation to mortality risk among individuals with epilepsy. Using Cox proportional hazards models adjusted for demographic, socioeconomic, and health-related covariates, we tested for statistical interactions between each PA exposures (sedentary behaviour, LPA, and MVPA duration) and five prevalent comorbidities. Among the 15 interaction terms tested (3 PA variables × 5 comorbidities), none reached statistical significance after correction for multiple comparisons (Supplementary Table 12). The most notable trend was observed for the interaction between LPA duration and peripheral vascular disease (HR: 0.72, 95% CI: 0.54–0.97, adjusted p = 0.093), which approached but did not achieve statistical significance. Similarly, the interaction between sedentary behaviour duration and diabetes showed a trend (adjusted p = 0.099) but was not statistically significant after multiple comparison correction. These results indicate that we did not detect statistically significant effect modification by comorbidities in the association between PA patterns and mortality risk among people with epilepsy.

Sensitivity analysis

To enhance the specificity of epilepsy case identification and validate our main findings, we performed sensitivity analyses by redefining the epilepsy cohort based on both diagnostic records and concurrent use of antiseizure medications (ASM), resulting in more stringently identified participants. Among individuals meeting these stricter criteria, Cox proportional hazard analysis assessed the relationship between PA variables and all-cause mortality. In the fully adjusted model after multiple testing corrections, higher LPA duration was significantly associated with lower mortality rate (HR: 0.74, 95% CI: 0.56–0.96, p = 0.037). Similarly, greater sedentary duration was associated with lower mortality (HR: 0.76, 95% CI: 0.60–0.96, p = 0.037) (Supplementary Table 13). RCS analysis indicated linear associations between sedentary duration (p-overall=0.018, p-nonlinear=0.103) and all-cause mortality rate and a nonlinear relationship between MVPA (p-overall=0.038, p-nonlinear=0.018) and all-cause mortality rate) (Supplementary Fig. 6). The association between sedentary behaviour and reduced mortality was robust across definitions. In contrast, the association of LPA with lower mortality emerged only in the ASM-defined people with epilepsy cohort, with dose-response patterns remaining consistent.

Machine learning analysis for mortality prediction

We developed a mortality prediction model for individuals with epilepsy using a random forest algorithm, with hyperparameters optimized through grid search cross-validation. Propensity score matching (PSM) was performed prior to model training to create balanced cohorts of deceased and surviving individuals, each comprising 116 participants. We extracted 777 time- and frequency-domain PA features derived from raw accelerometer data. Using random forest–based feature selection on the training set, we identified the eight most informative PA features to include in the final predictive model.

We compared our comprehensive machine learning model incorporating the selected PA features with a baseline model including only demographic and health-related variables. Our comprehensive model substantially outperformed the baseline model, with the area under the receiver operating characteristic curve (AUROC) of 0.87 (95% CI: 0.79–0.96) versus 0.78 (95% CI: 0.74–0.81) (p < 0.001), and the area under the precision-recall curve (AUPRC) of 0.82 (95% CI: 0.77–0.88) versus 0.75 (95% CI: 0.72–0.78) (p < 0.001; Fig. 5a–d; Supplementary Fig. 7). Detailed performance metrics and difference are provided in Supplementary Table 14. As an additional external validation, we applied the comprehensive model to the cohort of unmatched individuals identified during PSM. In this cohort (N = 935), all samples were survivors at the end of follow-up, with no recorded mortality events (Supplementary Table 15). The model achieved a specificity of 0.82 (95% CI: 0.76–0.88) in this population.

Fig. 5: Model performance and feature importance for mortality prediction in people with epilepsy.
figure 5

Integrating demographic, health-related, and advanced accelerometer-derived physical activity features with machine learning substantially improves individualized mortality risk prediction in people with epilepsy. a Receiver operating characteristic (ROC) curves for the baseline model (demographics and health-related features; AUROC = 77.6%) and the comprehensive model (demographics, health-related, and RFE-selected time- and frequency-domain PA features; AUROC = 86.7%), both using optimally tuned random forest classifiers. The comprehensive model shows markedly improved discrimination. b Precision–recall curves for the same two models as in (a), with the area under the precision–recall curve (AUPRC) increasing from 74.7% (baseline) to 82.2% (comprehensive model). All results are based on models with optimal hyperparameters. c Confusion matrix for the baseline model, showing predicted versus true labels (Survived, Deceased). The baseline model demonstrates moderate classification performance. d Confusion matrix for the comprehensive model, indicating improved sensitivity and specificity for mortality prediction upon inclusion of physical activity features. e Kaplan–Meier survival curves stratified by quartiles of predicted mortality risk from the comprehensive model. Survival probabilities decrease significantly across risk quartiles (log-rank p = 1.70e-05), indicating effective risk stratification. f Scatter plot of predicted mortality risk versus time to death or last follow-up, colored by true outcome (alive or deceased). A significant negative correlation (Two side spearman r = –0.40, p = 0.0051) demonstrates that higher predicted risk is associated with shorter survival time. g SHAP (SHapley Additive exPlanations) summary plot showing the top feature contributions in the comprehensive model. Blue bars represent PA features (time and frequency domain), and orange bars represent demographic and health-related features. The most important features include age at onset of epilepsy, mean change in moderate activity, and several high-frequency PA intensity measures.

Kaplan–Meier survival curves by risk quartile showed significant differences in survival (Log-rank p < 0.001; Fig. 5e). Furthermore, a significant negative correlation was observed between predicted mortality risk and time to death in test sets (Spearman r = –0.40, p = 0.005; Fig. 5f), indicating that higher predicted probabilities corresponded to earlier mortality events.

We analysed feature importance using SHAP values, which indicated that age at epilepsy onset was the most influential predictor, followed by the mean change in moderate physical activity and several high-frequency PA intensity features (Fig. 5g). The top five PA-related predictors included high-frequency PA intensity, PA phase components, and light PA duration. SHAP value analysis indicated that younger age at onset, lower Charlson comorbidity index, and higher frequency PA signals were all associated with lower predicted mortality risk (Supplementary Table 16).

Smartwatch-based prototype for personalized physical activity management

To translate these research insights into potential clinical applications, we have developed a preliminary prototype for “EpiActivity Manager,” a smartwatch-based application designed to apply our findings in real-world settings (Supplementary Fig. 8). This digital health tool aims to integrate our observed activity pattern associations and machine learning predictions to provide personalised physical activity guidance for people with epilepsy. The application could offer customised activity recommendations based on individual characteristics and comorbidities, monitor activity patterns in real time, and provide feedback when activity patterns deviate significantly from personalised targets.

Discussions

We present a comprehensive assessment of the associations between PA patterns and mortality risk, leveraging high-resolution accelerometer-derived data from 98,561 UK Biobank participants. Our findings reveal distinct PA–mortality relationships in individuals with and without epilepsy. Among those without epilepsy, higher levels of LPA and MVPA were significantly associated with lower mortality. In contrast, among individuals with epilepsy, only sedentary duration showed a significant inverse association with mortality. Dose–response analyses further demonstrated divergent PA–mortality relationships by epilepsy status. Moreover, we showed that incorporating accelerometer-derived PA features into predictive models substantially improved mortality risk stratification in the epilepsy population.

The ILAE Task Force on Sports and Epilepsy has highlighted the safety of moderate exercise for people with epilepsy4, suggesting that regular PA does not trigger seizures or affect their frequency20. Despite recommendations, many people with epilepsy engage in limited PA, with less than one-third meeting recommended levels21,22. Survey data show that people with epilepsy are less likely to follow exercise advice than the general population, and are more likely to have sedentary lifestyles (25% vs. 13%)23,24. Previous research on the relationship between physical activity and mortality in epilepsy has been limited by reliance on self-reported questionnaires. Some studies indicate that lack of regular physical activity may be linked to a higher risk of sudden unexpected death in epilepsy (SUDEP), and long-term follow-up data suggest lower mortality rates among those who engage in regular exercise compared to those who do not25,26. Our study adds to the evidence by using objective accelerometer measurements and identifying potentially meaningful nonlinear relationships that may inform physical activity guidance.

Accelerometer data confirms these activity pattern differences and shows a complex relationship between PA pattern and mortality rate in epilepsy. We found that higher sedentary behaviour duration was associated with lower all-cause mortality in people with epilepsy, which contrasts sharply with findings in the general population where sedentary behaviour is typically associated with increased mortality risk. For sedentary behaviour, we observed a nonlinear relationship with all-cause mortality, with potentially sedentary lasting 7-13 h per day was associated with a lower mortality, with the lowest estimated hazard ratio observed at 10.9 h per day. These findings may challenge the widely accepted notion that “sedentary behaviour is harmful” while suggesting that people with epilepsy may have distinct physiological responses to activity patterns. For MVPA, the nonlinear relationship suggested that durations of 0.1 to 0.2 h per day (6–12 min) were associated with lower mortality rate. These patterns differ substantially from those observed in people without epilepsy, where higher LPA and MVPA were consistently associated with lower mortality risk, suggesting that PA recommendations may need to be tailored specifically for people with epilepsy.

The biological mechanisms underlying these distinct associations remain speculative. In animal models, moderate exercise has been associated with enhanced brain-derived neurotrophic factor expression, neurogenesis, and improved synaptic plasticity27. Regular exercise may modulate inflammatory responses by reducing pro-inflammatory factors (IL-1β, TNF-α) and increasing anti-inflammatory factors (IL-10)28,29, potentially influencing seizure control. While most people with epilepsy report benefits from moderate exercise, ~15.3% have reported that high-intensity exercise might be associated with seizures, particularly under conditions of fatigue, dehydration, or overexertion24. Previous work linked increased seizure incidence to fatigue, which can be influenced by excessive activity30. Thus, in people with epilepsy, appropriate sedentary periods might help prevent fatigue-related seizures.

We developed a predictive machine learning model for mortality risk and found that incorporating detailed PA features substantially improved its accuracy compared to a model based solely on demographic and health-related variables. The random forest-based model identified age at onset of epilepsy, mean change in moderate activity, and several complex time and frequency-domain physical activity features as the most influential predictors. These physical activity metrics capture features such as high-frequency intensity components, activity variability indices, and temporal phase relationships, reflecting aspects of movement patterns that go beyond simple duration-based measures used in clinical practice. Notably, high-frequency intensity components reflect rapid transitions and bursts of activity, which may relate to physiological fluctuations relevant to epilepsy management. Activity variability indices provide insights into day-to-day stability, while phase components characterise the temporal organisation of activity and potential circadian rhythm stability. The prominence of these features in the model suggests that the temporal structure and variability of physical activity, rather than just the total volume, may play an important role in health outcomes for people with epilepsy.

Several limitations should be considered. First, the observational nature of the design means we cannot establish causality between physical activity patterns and mortality. Second, while ICD-10 coding is the standard approach for classifying cause-specific mortality in large-scale studies31,32, some recent work has flagged its potential limitations in accurately capturing epilepsy-related deaths, which may contribute to underestimation or misclassification in our cohort33,34. Moreover, due to the lack of detailed cause-of-death information in the UK Biobank, deaths attributable to specific epilepsy-related outcomes such as SUDEP could not be identified or reliably classified. Third, detailed information on important epilepsy-specific factors such as seizure frequency, epilepsy duration, and specific epilepsy syndromes was not available, though these could influence physical activity patterns and mortality risk. Due to potential selection bias, the UK Biobank-based population may limit generalisability across different populations. Additionally, our machine learning models were developed and evaluated within a single cohort without external validation, this may limit the generalizability of our findings to broader populations. Lastly, 3–7 days accelerometer measurements have been validated to represent longer-term physical activity patterns in general populations.  However, more epilepsy-specific evidence is needed to confirm whether such measurements are representative of habitual activity patterns.

In summary, our study provides the largest and most comprehensive objective assessment to date of physical activity and mortality in people with epilepsy. We reveal for the first time a counterintuitive association between higher sedentary behaviour and lower mortality risk in this population. Our integration of advanced machine learning and detailed accelerometer-derived features demonstrates that the variability and temporal structure of physical activity are powerful predictors of mortality risk. These findings bridge key gaps in the literature and highlight the potential of wearable data and digital phenotyping for personalized health management in epilepsy.

Methods

Study population

This prospective cohort study analysed data from 98,561 UK Biobank participants who provided valid wrist-worn accelerometer data, including 1167 people with epilepsy and 97,394 people without epilepsy. The UK Biobank is a comprehensive longitudinal study that recruited over 500,000 participants aged 40–69 between 2006 and 2010. The North West Multi-Centre Research Ethics Committee approved the study (R21/NW/0157), and all participants provided informed consent35. This study was conducted under UK Biobank application number 162384 (epilepsy and comorbidity), with the research protocol reviewed and approved as part of the original data access application process. Between February 2013 and December 2015, 236,519 UK Biobank participants were invited to participate in an accelerometer study. Of these, 106,053 agreed to participate and wore wrists that were worn accelerometers (Axivity AX3). The UK Biobank accelerometer expert working group processed the raw accelerometer data from 103,682 participants. For our analysis, we included participants who had at least three days (72 h) of accelerometer data and coverage of each hour of the 24-h cycle. Hourly sedentary behaviour, LPA, and MVPA metrics were derived from the raw accelerometer data (field ID: 1020:40032, 40033, 40034).

We integrated self-reported epilepsy diagnoses and relevant coding in electronic health records. According to the International Classification of Diseases 9th (ICD-9) and 10th (ICD-10) editions, epilepsy codes included ICD-9: 345 (epilepsy), ICD-10: G40 (epilepsy). Additionally, we excluded 349 persons with ICD-10 code R56 (convulsions, not elsewhere classified) from the group of people without epilepsy. The final sample included 1167 people with epilepsy and 97,394 people without.

Accelerometer-based physical activity measurement and processing

Participants were instructed to wear an Axivity AX3 triaxial accelerometer on their dominant wrist for 7 days, continuously including sleep. The device recorded acceleration at 100 Hz with a dynamic range of ± 8 g. Raw acceleration signals were aggregated into 5-second epochs, representing mean vector magnitude. Detailed data collection and processing methods are available in the provided reference36. UK Biobank researchers employed previously published machine learning algorithms to classify activity behaviours into accurately sedentary, LPA, MVPA and sleep based on wrist accelerometer data. This showed an 88% classification accuracy with a Cohen’s kappa coefficient of 0.803. The average proportion of time spent in sedentary, LPA, and MVPA was estimated for each hour during wakefulness. Data were stored as comma-separated values of 24, each representing one hour of the day, from midnight to 11 PM.

Mortality ascertainment

The primary outcome of this study was all-cause mortality among people with epilepsy. Secondary outcomes included cause-specific mortality, focusing on epilepsy-related, cardiovascular disease, cerebrovascular disease, and cancer mortality. Mortality information was obtained through the NHS Central Register death registration databases. Cause-specific mortality was determined based on the ICD-10. Death dates and causes were retrieved from NHS Central Register death datasets. Follow-up time was estimated from the date of completing accelerometer wear until death, withdrawal from the study, or the last follow-up date (October 17, 2023), whichever occurred first.

Covariate assessment

We included the following covariates: demographic factors (age, gender, ethnicity, education level, Townsend deprivation index), lifestyle factors (smoking status, alcohol consumption), health status indicators (disability status, overall health rating), and comorbidities index. Age was measured in years as a continuous variable. Ethnicity was classified as white or others. Education level was categorised into two groups: those with a bachelor’s degree or above, and those without a degree. The Townsend deprivation index, a measure of material deprivation based on unemployment, non-car ownership, non-home ownership, and household overcrowding, was calculated from participants’ postcodes at recruitment, with higher scores indicating greater deprivation. Smoking status was categorised as never, previous, or current smoker. Alcohol consumption was similarly classified as never, previous, or current. Disability status was self-reported as either present or absent. Overall health rating was self-reported on a four-point scale: excellent, good, fair, or poor. Comorbidity index was obtained through self-reported medical history and hospital records. We estimated a Charlson Comorbidity Index (CCI) based on the UK Biobank ICD-10 records to quantify the comorbidity burden. The CCI assigns weights to various comorbid conditions (i.e., myocardial infarction, congestive heart failure, peripheral vascular disease, cerebrovascular disease, dementia, chronic pulmonary disease, connective tissue disease, peptic ulcer disease, mild liver disease, diabetes without chronic complication, diabetes with chronic complication, hemiplegia or paraplegia, renal disease, any malignancy (including leukemia and lymphoma), moderate or severe liver disease, metastatic solid tumor, and AIDS/HIV) and sums these weights to create a composite score that predicts mortality risk.

Statistical analysis

Statistical analysis incorporated three main components: exploratory data analysis, survival analysis and nonlinear relationship exploration, subgroup and sensitivity analysis and machine learning-based mortality prediction. We used Python 3.11 and R 4.4.1 for the analysis. We applied Benjamini-Hochberg to perform multiple comparisons when assessing the three PA variables (sedentary behaviour, LPA, and MVPA) in primary analysis and subgroup analysis.

We conducted exploratory data analysis, describing continuous variables using means and standard deviations, and categorical variables as frequencies and percentages. Differences between groups were assessed using t-tests for continuous variables and χ² tests for categorical variables. Missing data were imputed using the MISSFOREST algorithm37.

We assessed relationships between the three exposure variables (sedentary behaviour, LPA and MVPA) and covariates using Spearman correlation analysis. We further examined the strength and direction of associations for continuous variables, which showed significant correlations. For categorical variables, we investigated differences in physical activity patterns across different categories using t-tests. To ensure our analyses were not affected by multicollinearity, we calculated variance inflation factors (VIF) among sedentary behaviour, LPA, and MVPA. The VIF values ranged from 1.05 to 1.96, indicating low multicollinearity among these variables (Supplementary Table 17).

We conducted SMR analyses to account for differences in follow-up duration, age, and gender distribution. The SMR was estimated as the ratio of observed deaths to expected deaths. For the epilepsy group, expected deaths were estimated based on age-specific (5-year bands) and gender-specific mortality rates from the people without epilepsy, which served as the reference population.

We also examined SMRs across tertiles of sedentary behaviour, LPA, and MVPA to explore potential nonlinear relationships. We estimated external SMRs (comparing each tertile in the epilepsy group to the corresponding tertile in the group of people without epilepsy) and internal SMRs (using the first tertile within each group as the reference). These analyses provided insights into how mortality risk in epilepsy varies across different levels of physical activity while accounting for demographic differences.

We began our survival analysis by examining the interaction effects between PA patterns and the presence or absence of epilepsy on mortality risk in the entire cohort using Cox proportional hazard models. We then employed Cox proportional hazard models to evaluate relationships between the three PA exposures (sedentary behaviour (hours/day), LPA (hours/day), and MVPA (hours/day)) and all-cause and cause-specific mortality risks, estimating hazard ratios (HRs) and their 95% confidence intervals (CIs) for people with epilepsy and people without epilepsy.

We constructed three models with increasing levels of adjustment: Model 1 included only the three PA exposure indicators (sedentary behaviour (hours/day), LPA (hours/day), and MVPA (hours/day)); Model 2 incorporated demographic variables (gender, age, BMI, ethnicity, education level and lifestyles) and socioeconomic status (Townsend Deprivation Index); Model 3 (fully adjusted model) included all variables from Model 2 and additionally adjusted for health conditions (Overall health, disability status, and comorbidity index).

To explore potential nonlinear relationships between PA patterns and mortality, we applied RCS models based on the fully adjusted Cox proportional hazards regression (Model 3). RCS models were optimised using Akaike Information Criterion to determine the optimal number of knots. This analysis allowed us to investigate dose-response relationships between continuous measures of physical activity (sedentary behaviour, LPA, and MVPA) and mortality in people with epilepsy and people without epilepsy.

Within the epilepsy group, we conducted stratified analyses by gender (men, women) and age subgroups (<65 years, ≥65 years), repeating Cox proportional hazard models and RCS analyses. We further tested for interactions effect between PA patterns and five major comorbidities (diabetes, hypertension, cardiovascular disease, cerebrovascular disease, and peripheral vascular disease). Stratified analyses were conducted only for comorbidities with significant interactions.

As a sensitivity analysis, we applied a definition of epilepsy that requires a self-report or ICD-based diagnosis and documented use of an antiseizure medication (ASM). They were systematically identified according to four major described mechanisms of action38. (1) sodium channel blockers, (2) gamma-aminobutyric acid (GABA) analogues, (3) synaptic vesicle protein 2 A (SV2A) binding agents, and (4) agents with multiple mechanisms. Using these criteria, we identified 527 individuals as ASM users.

Lastly, we developed a mortality prediction model based on machine learning for people with epilepsy. We first employed propensity score matching (PSM) based on age and gender to create balanced groups of people with epilepsy either deceased or alive. The dataset was then randomly split into a training set (80%) and a testing set (20%). We extracted features from the minute-epoch acceleration summaries using the ‘tsfresh’ library, which generated comprehensive time and frequency domain features from the raw accelerometer signals15. To improve computational efficiency and reduce overfitting, we applied random forest-based recursive feature elimination (RFE) to select the most informative features from the initial pool of 777 time-frequency domain features. We retained 8 key features for the final model on the training sets.

We developed multiple prediction models with increasing complexity: (1) a baseline random forest model including demographic factors (age, gender, ethnicity, education level, Townsend deprivation index), lifestyle factors (smoking status, alcohol consumption), health status indicators (disability status, overall health rating), comorbidities status and ASM-related variables, and (2) the full random forest model incorporating the selected PA patterns (sedentary duration, LPA duration, MVPA duration) and time-frequency features ((Mean change in moderate activity, High-frequency PA intensity (FFT 33), High-frequency PA (imaginary, FFT 16), Very high-frequency PA phase (FFT 56), Low-frequency PA (imaginary, FFT 3), Activity variability (std), Ultra high-frequency PA (imaginary, FFT 91), Short-term PA trend (5-epoch max))). Hyperparameter optimisation was performed exclusively on the training dataset using GridSearchCV (Supplementary Table 18)39.

Model performance was evaluated using accuracy, area under the receiver operating characteristic curve (AUROC), sensitivity, specificity, F1 score, and area under the precision-recall curve (AUPRC). We conducted ablation studies to quantify the incremental value of accelerometer-derived features beyond traditional clinical predictors. All model development and reporting adhered to the TRIPOD + AI guidelines for transparent reporting of prediction models using machine learning methods40.

To enhance interpretability, we analysed feature importance using Shapley Additive Explanations (SHAP) values41, which quantify each feature’s contribution to individual predictions. We also explored the relationship between the predicted probability (fully adjust-model) of death and actual time-to-death using Spearman correlation analysis and created calibration plots to visualise the agreement between predicted probabilities and observed mortality rates in the test set.