# Capturing daily patterns in step counts

Consider Fitbit data where step counts can be recorded on a continuous basis. Computing average daily step counts and other simple measures is easy, but what if you wanted to capture time patterns including long sedentary periods, periods of high intensity, etc.? Suppose for the moment that one is interested in a 24h paradigm. Here are some initial thoughts and I’d appreciate thoughts from others.

• Measure hourly step counts, probably doing something differently during sleep. Summarize a person with 24 counts plus the mean, quintiles, and Gini’s mean difference. Do a redundancy analysis to determine the minimal set of these measurements for which there are no redundancies, i.e., no remaining measure can be extremely well predicted from other measures. Use the set of non-redundant measures as a multivariate summary to play against other variables.
• Instead of computing hourly summaries, fit a flexible smooth nonlinear model to daily patterns. Suppose this model has 8 parameters. Use those parameters as the multivariate summary after fitting the model separately by patient.
2 Likes

Ah, something in my wheelhouse! From a Fitbit, ActiGraph, or other physical activity monitor you can usually get activity data at the minute-to-minute or even second-to-second level, either as step counts, activity counts, “MIMS units”, or “ENMOs”, so there’s essentially no limit to how finely-grained you can observe activity.

There are some biostats research groups that are approaching the problem more or less in line with your option #2: considering physical activity as a 24-hour function, modeling each day with a basis expansion. There’s a really nice in-depth review on these kinds of strategies in Erjia Cui’s dissertation defense here from this spring.

Some papers use functional principal component analysis on either the activity data or the log+1 transform of it, then get fPCA scores and use those in a regression model, possibly alongside other covariates.

It’s also possible to use the functions themselves as covariates in a regression model. The ‘refund’ package in R supports this kind of analysis, using a generalization of semiparametric mixed models. That allows lots of useful features, like random functional intercepts for multi-day observations on the same person, generalizing to nonlinear effects of the 24-hour function, and including other possibly nonlinear scalar covariates.

Depending on the study goals, you could also treat the 24hr activity pattern as the outcome, and look at the change in activity pattern as a function of age, or being on a certain medication, for example.

There are some interesting complicating factors with any approach:

• Should the 24hr day start at midnight for everyone, or should the daily observations be aligned somehow to account for, e.g. someone who gets out of bed at 5am vs. at 10am?
• Often physical activity monitors give you informative missingness, i.e. you know when the person isn’t wearing the device. How much missingness should you tolerate? Do you impute the missing data, or use an analysis method that allows the 24hr activity function be sparsely observed?
• If you have access to raw accelerometer data, it’s possible to recognize specific types of physical activity (driving, biking, walking, sleeping, etc.) with activity recognition algorithms, e.g. as done in this paper. How should the analysis change if you are interested in differential effects of different kinds of activity? For example, activity counts on a wrist-worn accelerometer would be pretty low when riding a bike, but if you knew that activity time was from a bike ride, it’d be nice to be able to account for it in your analysis. Sleeping is another good example: 5hrs of sleep + 3hrs of sedentary time with similarly-low activity counts is probably less healthy than 8hrs of sleep.

I think this topic is a very timely one, since there are many new large-scale studies like NHANES and UK Biobank that are incorporating physical activity data alongside outcomes like cognitive function, blood pressure, mortality, and pretty much anything else you might care about from a health perspective.

5 Likes

Regarding the start of 24-hour period, I would imagine using midnight is close to an arbitrary decision, and rather, the key is activity within a 24-hour period where presumably the bulk of activity is during normal wakefulness. I suggest the relevant 24-hour period would align with when an individual “starts the wakeful period” and the time of day on a 24-hour clock could be used as a covariate/predictor potentially to capture any circadian rhythm influence on the activity (i.e. someone who wakes at 0300 vs 1400). This would also allow for schedule variation within a person. This may introduce some issues when someone changes their wakeful period, though. Maybe I am overthinking this point.

2 Likes

Speaking of the UK Biobank, the Cambridge MRC Epidemiology unit is extensively involved in these physical activity measurements and even apart from the UK Biobank has quite a lot of expertise in collecting, processing and analyzing objectively-measured physical activity. They also organize a biannual course/seminar on the collection and analysis of physical activity measurements in (epidemiological) studies (last one appears to have been in 2022, so next one should be 2024. Attended it myself a few years ago.)

Through their website they also provide scripts/software for processing data from some commonly used measurement devices such as the ActiGraph that @JDruns mentioned (only available as STATA or Python scripts). They have more expertise and processing routines that are not publicly available. For example, they helped us out processing ActiHeart measurements in a cohort as well, and from the seminar I recall they have done some studies with Fitbits too. You could consider contacting them for more information; we always had a good collaboration with them.

Accounting for overall 24-h patterns in physical activity is also relevant for the interpretation of your analyses (depends on how you end up analyzing your data though, but as soon as you start looking at the effect of spending x hours/minutes on an outcome it becomes relevant). As a day is (obviously) limited to 24 hours, performing more or less of one form of physical activity comes at the expense of other activities. E.g. if decide to you walk 1 hour extra during a day, that hour can not be spend doing another activity such as sitting/sleeping/other activity. When assessing the association of time spend doing a certain activity on some outcomes it can therefore become relevant to account for the changes in other activities (cause the question becomes, is change in outcome cause by more of activity x or by the simultaneous reduction in activity y).
Some papers that cover some methodology on this topic:

1 Like

Wow I’m amazed at the helpful replies. Thank you three!

I’ve always liked the Birthdays example from Gelman et al’s Bayesian Data Analysis text (Bayesian workflow book - Birthdays). I think the process could be adapted to most time series data where you are looking to decompose the series into trends of different time scales.

1 Like

I’ve been meaning to see whether applying dynamic time warping (DTW) to a similar problem, with follow up cluster analysis might be of use. In your example, could it help answer a simple question from a patient who was trying to lose weight, as to whether they need to do active things for longer, or whether they need to increase the intensity of activity what they are doing. If anyone has any experience applying DTW to this sort of problem I’d love to hear it.

Would you mind writing a brief description of what DTW involves and what it assumes?

Used in econometrics, DTW allows comparison of time series data that is hypothesised to follow the same pattern or shape, but one that may differ between groups in how quickly the shape varies according to the x or y axis. By applying different constraints, analysis can assess how much patterns of data may be similar to each other, given the allowed variability in their magnitude or tempo.

The aim is to pair data points in two or more patterns of data that are at the same point in the ‘shape’ of the data, but may differ by x and y. Comparing two functions of similar data patterns, Dtw assumes a local ‘dissimilarity function’ between these paired points. Minimising the Euclidean distance between paired points is often described.

Your question has made me realise how little I understand about the assumptions of this technique. I have found someone describe that it is assuming one vector is a non-linear time-stretched series of the other, which in this context, may mean that it is not appropriate for quantifying the difference in time series data between participants. I have worked with SITAR in relation to child growth, Tim Cole’s ‘Superimposition by translation and rotation’, which follows the assumptions of random effects multilevel mixed modelling. Children do tend to grow in similar shapes, just with varying parameters, so this allows neat data reduction into ‘size, tempo and velocity’ of growth. However, patterns of activity vary between individuals far too much to fit a model like SITAR. I was reading around trying to find some way to objectively compare time series data that varied more between individuals than growth, and thought DTW could be suitable to extract some objective parameters. However, as your question infers, perhaps the fact that it is fundamentally assuming a similar pattern or shape of trajectory between individuals makes this inappropriate.

I appreciate that good introduction to DTW Neil. There is a possibility that it is a reinvention of self-modeling nonlinear regression.