{'fraction_non_alphanumeric': 0.033810719031448395, 'fraction_numerical': 0.013214232983906688, 'mean_word_length': 5.358366580614879, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Reallocation of time between device-measured movement behaviours and risk of incident cardiovascular disease

Objective To improve classification of movement behaviours in free-living accelerometer data using machine-learning methods, and to investigate the association between machine-learned movement behaviours and risk of incident cardiovascular disease (CVD) in adults. Methods Using free-living data from 152 participants, we developed a machine-learning model to classify movement behaviours (moderate-to-vigorous physical activity behaviours (MVPA), light physical activity behaviours, sedentary behaviour, sleep) in wrist-worn accelerometer data. Participants in UK Biobank, a prospective cohort, were asked to wear an accelerometer for 7 days, and we applied our machine-learning model to classify their movement behaviours. Using compositional data analysis Cox regression, we investigated how reallocating time between movement behaviours was associated with CVD incidence. Results In leave-one-participant-out analysis, our machine-learning method classified free-living movement behaviours with mean accuracy 88% (95% CI 87% to 89%) and Cohen’s kappa 0.80 (95% CI 0.79 to 0.82). Among 87 498 UK Biobank participants, there were 4105 incident CVD events. Reallocating time from any behaviour to MVPA, or reallocating time from sedentary behaviour to any behaviour, was associated with lower CVD risk. For an average individual, reallocating 20 min/day to MVPA from all other behaviours proportionally was associated with 9% (95% CI 7% to 10%) lower risk, while reallocating 1 hour/day to sedentary behaviour from all other behaviours proportionally was associated with 5% (95% CI 3% to 7%) higher risk. Conclusion Machine-learning methods classified movement behaviours accurately in free-living accelerometer data. Reallocating time from other behaviours to MVPA, and from sedentary behaviour to other behaviours, was associated with lower risk of incident CVD, and should be promoted by interventions and guidelines.

'Ground truth' labelling of movement behaviours in image data As described in the main text, to provide the 'ground truth' labels for machine-learning based behaviour classification, finegrained behaviour annotations of image data were mapped to sleep, sedentary behaviour, light physical activity behaviours and moderate-to-vigorous physical activity behaviours based on the definition in the main text. In practice, this involved the following steps (the final mapping is given in Supplementary Table 1): 1. The fine-grained annotation for sleeping was assigned to sleep. 2. Behaviours at 3 or more METs (Metabolic Equivalent of Task, where 1 MET is energy expenditure in quiet sitting), as described in Compendium of Physical Activities [1], were assigned to moderate-to-vigorous physical activity behaviours. 3. For waking behaviours at <3 METs, if the fine-grained annotation indicated a sitting, lying or reclining posture, the behaviour was assigned to sedentary behaviour. 4. Waking behaviours at <3 METs not assigned to sedentary behaviour were assigned to light physical activity behaviours. 5. All labels were reviewed by two reviewers. Where reviewers agreed the fine-grained annotation was typically used by annotators for behaviours in a different category to the label given, the fine-grained annotation was recoded. This review was performed prior to model training, and no changes were made after results were obtained.
BMJ Publishing Group Limited (BMJ) disclaims all liability and responsibility arising from any reliance Supplemental material placed on this supplemental material which has been supplied by the author(s)

Machine-learning methods
As described in the main text, a Random Forest (RF) with 100 decision trees was developed to classify 30-second time windows as sleep, sedentary behaviour, light physical activity behaviours or moderate-to-vigorous physical activity behaviours using the time and frequency domain features outlined in Supplementary Table 2. A Hidden Markov model (HMM) was then employed to use time sequence information to improve on the RF-assigned label sequence. As described in the main text, models were trained using labelled data from the CAPTURE-24 study, in which participants wore wearable cameras and kept time use diaries alongside wearing an accelerometer.

Machine-learning methods: Features
Time windows of acceleration were classified using a list of features (variables) based on features used in the study of Willetts et al (this included time and frequency domain features e.g. mean and kurtosis of the acceleration vector magnitude, and power at different frequencies from the Fast Fourier Transform of acceleration vector magnitude) [2]. In the present study, only rotationinvariant features were used (see Supplementary Table 2). This addressed concerns about risk of overfitting and possible time trends in the data driven by sensitivity to device orientation within the wrist strap (orientation became more standardised over [2013][2014][2015]. Machine-learning methods: Random Forest models Random Forests are based on decision trees. Decision trees assign class labels based on splits of the data using feature value thresholds (as shown in the example in Supplementary Figure 11). They can be trained using the Classification and Regression Tree (CART) algorithm [3].
In a RF, many decision trees are used. When training the trees (using the CART algorithm), randomness is introduced by (i) training each tree on a set of data points picked randomly (with replacement) and (ii) at each split node, restricting the choice of splitting feature to a randomly picked subset of features.
To classify a data point using an RF, it is classified by each decision tree. Because they are trained on different subsets of data and use different features, different trees in the RF may classify data points differently. The overall classification given by the RF is the class that is assigned to the data point by the largest number of trees. This approach, whereby multiple randomly-differing instances are used in order to reduce variance on the output, is the technique of bootstrap-aggregating or 'bagging' [4].
For this application, a balanced RF was used. The fact some behaviours are much more common than others in the labelled data (e.g. sleep is much more common than moderate-to-vigorous physical activity behaviours) can cause a standard RF, which is trained by picking N examples at random with replacement, to favour assigning common labels at the expense of less common behaviours [2]. Using the balanced RF, if there were nrare examples of the rarest behaviour, nrare examples of each behaviour were picked with replacement to train each tree.
Machine-learning methods: Hidden Markov models In a HMM, there is a sequence of unobserved hidden states, which is assumed to have the Markov property (i.e. future states only depend on past states through present states). This sequence is governed by transition probabilities, which determine the probability of transitioning between each pair of states. There is a sequence of observed states, which depend probabilistically on the sequence of hidden states (described as 'emissions' from the sequence of hidden states; Supplementary Figure 12).
Here, the hidden states were the true behaviours, and the emissions were the RF-assigned labels. The Viterbi algorithm, the standard approach to this problem, was used to estimate the most likely true behaviour sequence given the observed sequence of RF-assigned labels [5]. Applying the Viterbi algorithm required estimates of: 1. Transition probabilities between hidden states: Transition probabilities between behaviour pairs were estimated using the proportions of transitions that occurred between each behaviour pair in the labelled data. 2. Emission probabilities of observed states from hidden states: To estimate emission probabilities, time windows were first classified using out-of-bag predictions from the RF i.e. trees were used to classify data points on which they were not trained. This mimics use on unseen data, without requiring additional data. Emission probabilities were then estimated using the proportions of different pairs of true behaviour and RF out-of-bag estimate.
By using this HMM to estimate the most likely true behaviour sequence given the RF-assigned labels, a more plausible sequence of states was obtained. The HMM re-labelled behaviours which formed unrealistic sequences and were likely to be attributable to misclassification (e.g. short periods of moderate-to-vigorous physical activity behaviours during sleep time). Therefore, compared to the unadjusted RF-assigned labels, the labels after using the HMM gave improved measures of the behaviours of interest for subsequent epidemiological analyses.

Machine-learning methods: Evaluation
All metrics were calculated in Leave-One-Participant-Out Cross-Validation. Leave-One-Participant-Out Cross-Validation allows evaluation of the performance of the models on data not used in training, while retaining the maximal amount of data for use in training these models. Moreover, all of the data can then be used to train the final model used for classification.
For model performance, the following evaluation metrics were used: 1. We reported mean per-participant accuracy across all behaviours. This is a simple, intuitive metric of model performance, describing the proportion of 30-second time windows that were correctly classified. Using mean per-participant accuracy, rather than aggregate accuracy over all data, prevents the result being dominated by performance on a few participants with larger amounts of data (important as there may be inter-individual differences in classification performance). 2. We reported mean per-participant Cohen's kappa across all behaviours. This is a metric of interrater reliability. It evaluates how much higher the agreement between two raters (here, annotator-assigned 'ground truth' label and modelassigned label) is than that which would be achieved by chance, given the proportions in each class. It is preferable to accuracy, as it takes into account the proportions in each class (in particular, in data where some classes are dominant, a classifier assigning solely to the dominant classes can achieve high accuracy but not high Cohen's kappa). 3. We reported mean per-participant precision and recall for each behaviour. Precision for a given behaviour is the proportion of examples labelled by the model as that behaviour which are 'true' examples of that behaviour. Recall for a given behaviour is the proportion of 'true' examples of that behaviour labelled as that behaviour. Again, taking the mean across participants prevents performance being dominated by performance on participants with larger amounts of data. However, it also upweights the contribution of individuals with very small amounts of data for a given behaviour. Therefore, precision and recall were additionally calculated after excluding participants with up to 20 minutes in the behaviour.
Taken together, these metrics help to understand the validity of the model as a method to derive measures of movement behaviours for subsequent epidemiological analyses. After applying the model to derive measures of movement behaviours for UK Biobank participants, face validity was assessed by plotting behaviour profiles over the day.
Machine-learning methods: model in participants aged 38 years or older We also carried out the above steps using only data from participants aged 38 years or older i.e. nearer to the age group represented in the UK Biobank sample. The age group 38+ years was used as this corresponds to the information available in a release version of this dataset.
In A Compositional Data Analysis approach to movement behaviour data Log-ratio transformation A Compositional Data Analysis approach is a set of methods for working with compositional data, based on the use of logtransformed ratios to describe the data [6][7][8]. Ratios between behaviours are used to describe compositional data as they capture the relative values of the different behaviours. Log-transforming ratios ensures the relationships and distances between different compositions are well-described: using log-transformed ratios is equivalent to working with compositional data in a 'natural' space for it, with operations which map compositions to genuine compositions and an appropriate distance metric [9,10]. For statistical purposes, log-transformed ratios are also typically more conveniently distributed than ratios [11].
While many different sets of log-transformed ratios can be used, isometric log-ratio pivot coordinates are widely used in movement behaviour research [12] and were used in this study. They were calculated as follows: Interpreting isometric log-ratio pivot coordinates As the coefficients in the model relate to the isometric log-ratio pivot coordinates, rather than the raw behaviour variables, interpreting them is not straightforward.
The first coordinate describes the balance between sleep and all other behaviours. Therefore, the coefficient of the first coordinate can be interpreted as the effect of reallocating time to sleep from all other behaviours proportionally i.e. if the coefficient of the first coordinate is greater than 0 (its exponent is greater than 1) reallocating time to sleep from all other behaviours proportionally is associated with higher risk of cardiovascular disease. However, the second and third coordinates are harder to interpret analogously. Therefore, to interpret individually the effect of reallocating time to each behaviour from all others proportionally, and following standard methods in movement behaviour research, one model per behaviour was produced (with different first coordinate). This approach was used to present the model parameters in Supplementary Table 5 and Supplementary Table 6 (note that, in consequence, they do not parametrise a single model).
However, even using this approach, the magnitudes of the coefficients are hard to interpret. Therefore, as described in the main text, and following established methods, model estimates of the hazard ratio at different compositions relative to the mean behaviour composition were reported e.g. using pairwise time reallocation plots.
In detail, suppose we have a Cox regression model in the isometric log-ratio pivot coordinates laid out above: and that the value of the coordinates at the mean behaviour composition is ( _ , _ , _ ). [This notation is not misleading: the value of the coordinates at the compositional mean behaviour composition is also the mean of the coordinate values.].
Then, we consider a new behaviour composition, which corresponds to isometric log-ratio pivot coordinate values ( , , ). In particular, when considering a pairwise time reallocation plot we use would use a new composition where time in two behaviours remained at its value in the mean behaviour composition, a value was subtracted from time in one of the remaining behaviours, and that value added to the time in the other behaviour. The log hazard ratio, now relative to the mean behaviour composition, is then calculated as: The standard error on this can be calculated using the variance-covariance matrix of the coefficients = ( , , ), denoted . To ensure results were plotted within the range supported by the data, times plotted were truncated at the 5 th and 95 th centile for the behaviour in the pair for which this range was narrower.

Zero values
All participants recorded time in sleep, sedentary behaviour and light physical activity behaviours, but 1% of participants recorded no time in moderate-to-vigorous physical activity behaviours. As zero values cannot be incorporated directly into the coordinates above, different approaches to work with them have been developed. The appropriate method depends on the source of the zero values: 1. 'Rounded' zeroes relate to measurement precision: even where no time in a given behaviour was observed, had the wear time been long enough, or the time resolution of the measurement short enough, some time in the behaviour would be expected. If data contains rounded zeroes, they can be imputed as small positive values [16]. 2. 'True' zeroes occur where no matter the precision of the measurement, no time in that behaviour would be observed. For example, this may occur in movement behaviour research if someone is physically unable to take part in certain behaviours. If data contains true zeroes, participants with a true zero in a particular behaviour should be excluded from the main analysis and analysed separately.
We followed established methods in movement behaviour research by considering zero values to be 'rounded' and imputing them using the log-ratio expectation maximization algorithm from the 'zCompositions' R package [8,[15][16][17]. We used the smallest observed value in the data as the detection limit (0.0001 on the unitless scale, corresponding to 0.14 min/day). Sensitivity of results to the method of treating zero values (imputation or exclusion) under the Compositional Data Analysis approach was examined by performing an analysis restricted to participants with non-zero values in all behaviour variables. This did not materially impact the results (Supplementary Figure 13). Software Development of the machine-learning models and processing of accelerometer data used Python 3.6.6, with the 'biobankAccelerometerAnalysis' tool[2,18,19] for preparing accelerometer data and training machine-learning models.
Data preparation was performed in Python 3.6.6 and R 4.0.5, and used the 'ukb_download_and_prep_template' tool [20] for preparing covariate and outcome data.

Sensitivity analyses: further details on E-values
As described in the main text, E-values were reported alongside hazard ratios. The E-value for the estimate quantifies the minimum strength of association that an unmeasured confounder would need with both exposure and outcome to explain away the observed association. The E-value for the 95% confidence interval quantifies the minimum strength of association an unmeasured confounder would need with both exposure and outcome to reduce the interval to overlap the null [27,28]. As the exposure is continuous, in both cases the risk ratio would apply to hypothetical groups with either the specified behaviour composition or the reference (the mean behaviour composition) [28].
BMJ Publishing Group Limited (BMJ) disclaims all liability and responsibility arising from any reliance Supplemental material placed on this supplemental material which has been supplied by the author(s)

Sensitivity analyses: linear isotemporal substitution
For comparability with previous literature, a sensitivity analysis using a linear isotemporal substitution approach was conducted.
Under a linear isotemporal substitution approach, all but one of the movement behaviours are included in the model (so the included variables are not perfectly multicollinear). [In this study, as non-wear time was imputed all subjects had the same wear time. Therefore, a total time variable was not included, meaning the approach may be more properly called 'leave-one-out regression' than true linear isotemporal substitution [8].] Associations are modelled as linear (rather than linear in the log-ratios, as under a Compositional Data Analysis approach). The coefficient of each behaviour can be interpreted in terms of replacing time in the left-out behaviour with time in that behaviour. Linear isotemporal substitution has been widely used in movement behaviour epidemiology [34], but has been criticised for not addressing the fact movement behaviour data only conveys relative information [8].
While there were some differences in shape of the associations observed (due to the different assumptions), results using this approach were broadly similar to the results of the main analysis using Compositional Data Analysis (Supplementary Figure 14).      Figure 1: Participant-wise mean (a) precision and (b) recall for classification of behaviours from accelerometer data calculated in Leave-One-Participant-Out Cross-Validation (with 95% confidence interval for the mean). The x-axis gives the minimum required recorded annotator-labelled time in the behaviour for inclusion in the calculation. For precision, participants with no model-labelled time in the behaviour were also excluded as precision is undefined in this case.    Figure 3: Hazard Ratios for cardiovascular disease for all behaviour pairs estimated using multivariable-adjusted (blue) and minimally adjusted (red) Cox regression models. a a Model based on 4,105 events in 87,498 participants. All relative to the mean behaviour composition: 8·8 hours/day sleep, 9·3 hours/day sedentary behaviour, 5·6 hours/day light physical activity behaviours, 0·35 hours/day (21 minutes/day) moderate-to-vigorous physical activity behaviours. Multivariable-adjusted model used age as the timescale, was stratified by sex and was additionally adjusted for ethnicity, smoking status, alcohol consumption, fresh fruit and vegetable consumption, red and processed meat consumption, oily fish consumption, deprivation and education. Minimally-adjusted model used age as the timescale and was stratified by sex.  Figure 4: Hazard Ratios for incident cardiovascular disease estimated using a multivariable-adjusted Cox regression model before (blue) and after (red) stratification by BMI. a a Model based on 4,105 events in 87,498 participants. All relative to the mean behaviour composition: 8·8 hours/day sleep, 9·3 hours/day sedentary behaviour, 5·6 hours/day light physical activity behaviours, 0·35 hours/day (21 minutes/day) moderate-to-vigorous physical activity behaviours. Models used age as the timescale, were stratified by sex and were additionally adjusted for ethnicity, smoking status, alcohol consumption, fresh fruit and vegetable consumption, red and processed meat consumption, oily fish consumption, deprivation and education.
BMJ Publishing Group Limited (BMJ) disclaims all liability and responsibility arising from any reliance Supplemental material placed on this supplemental material which has been supplied by the author(s)  Figure 8: Hazard Ratios for incident cardiovascular disease for all behaviour pairs estimated using a multivariable-adjusted Cox regression model (blue), after removing the first two years of follow-up (red) and after additionally restricting to a healthy subgroup (green). a a Main analysis based on 4,105 events in 87,498 participants. First sensitivity analysis based on 2,947 events in 86,011 participants. Second sensitivity analysis based on 1,597 events in 63,267 participants. Models used age as the timescale, were stratified by sex and were additionally adjusted for ethnicity, smoking status, alcohol consumption, fresh fruit and vegetable consumption, red and processed meat consumption, oily fish consumption, deprivation and education. All values reported relative to the mean behaviour composition in each case:  Figure 9: Hazard Ratios for cardiovascular disease (blue) and for non-activity-related accidents (red) for all behaviour pairs estimated using a multivariable-adjusted Cox regression model. a a Main model based on 4,105 events in 87,498 participants. Negative control model based on 1,375 events in 84,552 participants (participants with prior accident additionally excluded). All relative to the mean behaviour composition in each case (both 8·8 hours/day sleep, 9·3 hours/day sedentary behaviour, 5·6 hours/day light physical activity behaviours, 0·35 hours/day (21 minutes/day) moderate-to-vigorous physical activity behaviours). Models used age as the timescale, were stratified by sex and were additionally adjusted for ethnicity, smoking status, alcohol consumption, fresh fruit and vegetable consumption, red and processed meat consumption, oily fish consumption, deprivation and education. Model based on 4,105 events in 87,498 participants. All relative to the mean behaviour composition (8·8 hours/day sleep, 9·3 hours/day sedentary behaviour, 5·6 hours/day light physical activity behaviours, 0·35 hours/day (21 minutes/day) moderate-to-vigorous physical activity behaviours) and more time in named behaviour reallocated from all other behaviours proportionally. Model used age as the timescale, was stratified by sex and was additionally adjusted for ethnicity, smoking status, alcohol consumption, fresh fruit and vegetable consumption, red and processed meat consumption, oily fish consumption, deprivation and education.  Figure 13: Hazard Ratios for incident cardiovascular disease for all behaviour pairs estimated using a multivariable-adjusted Cox regression model for all participants (blue) and in a sensitivity analysis excluding individuals with a zero value in any behaviour (red). a a Main model based on 4,105 events in 87,498 participants. Model excluding individuals with zero values based on 4,017 events in 86,696 participants. All relative to the mean behaviour composition in each case (main analysis -8·8 hours/day sleep, 9·3 hours/day sedentary behaviour, 5·6 hours/day light physical activity behaviours, 0·35 hours/day (21 minutes/day) moderateto-vigorous physical activity behaviours; analysis excluding individuals with zero values -8·8 hours/day sleep, 9·3 hours/day sedentary behaviour, 5·6 hours/day light physical activity behaviours, 0·37 hours/day (22 minutes/day) moderate-to-vigorous physical activity behaviours). Models used age as the timescale, were stratified by sex and were additionally adjusted for ethnicity, smoking status, alcohol consumption, fresh fruit and vegetable consumption, red and processed meat consumption, oily fish consumption, deprivation and education.
BMJ Publishing Group Limited (BMJ) disclaims all liability and responsibility arising from any reliance Supplemental material placed on this supplemental material which has been supplied by the author(s)  Figure 14: Hazard Ratios for incident cardiovascular disease estimated using a multivariable-adjusted Compositional Data Analysis Cox regression model (blue) and using a multivariable-adjusted linear isotemporal substitution Cox regression model (red). a a Model based on 4,105 events in 87,498 participants. All relative to the mean behaviour composition: 8·8 hours/day sleep, 9·3 hours/day sedentary behaviour, 5·6 hours/day light physical activity behaviours, 0·35 hours/day (21 minutes/day) moderate-to-vigorous physical activity behaviours. Models used age as the timescale, were stratified by sex and were additionally adjusted for ethnicity, smoking status, alcohol consumption, fresh fruit and vegetable consumption, red and processed meat consumption, oily fish consumption, deprivation and education.
BMJ Publishing Group Limited (BMJ) disclaims all liability and responsibility arising from any reliance Supplemental material placed on this supplemental material which has been supplied by the author(s)