Two Clocks, One Night: Can Mathematics Help Explain Sleep in ADHD?

A Python-Based Exploration of Circadian Rhythms and Stimulant Medication Timing

Abstract

This independent Python project explores how the timing of a hypothetical stimulant dose changes modelled medication levels during the evening. It combines a repeating 24-hour curve with exponential decay and compares three administration-time scenarios. A second graph illustrates how the daily curve would shift under an explicitly assumed relationship between evening medication level and circadian timing. The simulation's aim is to establish a clear mathematical framework that could later be tested using wearable activity and sleep data.

Introduction

Sleep difficulties are common in people with ADHD, but stimulant medication does not affect everyone's sleep in the same way. A meta-analysis found that stimulants were associated with longer times to fall asleep and shorter sleep duration in young people [2]. A later study of 159 adolescents found smaller and less consistent associations [3]. These findings make the relationship between medication and sleep worth investigating.

This project was inspired by Enhanced Machine Learning Approach to ADHD Classification Using Actigraphy Data(Feretzakis et al., 2025), a paper I co-authored [1]. That study analysed wearable activity data from 45 participants. It found that features including changes between daytime and nighttime activity helped distinguish participants with ADHD from those without it. The earlier research used activity patterns to study ADHD classification. My independent project explores a related but different question: how could medication timing be represented alongside a daily rhythm? Actigraphy records movement and sleep-wake patterns, but it does not directly measure the body's internal circadian clock. This simulation uses no participant data from the previous study.

Methodology

I built the model in Python using NumPy and Matplotlib. It combines two mathematical functions.

Circadian curve

C(t) = 0.5 + 0.5 cos(2π(t − 3)/24)

This produces a smooth cycle that repeats every 24 hours. The peak at 03:00 is a chosen example, not a measured circadian phase.

Medication decay

For a hypothetical dose at time d:

M(t) = 0 before administration

M(t) = 2^(-(t − d)/5) from administration onwards

The starting level is defined as 1 and the modelled level halves every five hours. This describes an idealised decline, not the absorption and elimination pattern of a particular medication. I compared three hypothetical administration times: 08:00, 12:00 and 16:00. The comparison point is 22:00.

To create Figure 2, I applied one additional rule: Assumed phase delay (hours) = 4 × M(22)

The factor of 4 was chosen to demonstrate how the curve could be shifted!


Results

Figure 1 compares how the simulated medication level changes over time. The later the administration time, the more of the modelled level remains at 22:00.

Figure 1. Relative medication level after hypothetical administration at 08:00, 12:00 and 16:00. The dotted line marks 22:00.

Table 1

Figure 2 shows what the circadian curve looks like when the assumed delays are applied. The black dashed line is the unchanged baseline. The coloured lines shift later by the amounts in Table 1.

Figure 2. Illustrative phase shifts generated by assuming delay (hours) = 4 × relative medication level at 22:00. These delays were chosen by the model and have not been observed or clinically validated.


Possible Real-World Application

A future version could combine this framework with wearable activity data, sleep diaries and recorded medication timing. Researchers could compare simulated evening exposure with sleep-wake patterns observed over several weeks. That would help test whether the model captures any real variation in sleep rather than simply illustrating equations. With enough reliable data, this approach could contribute to a digital sleep twin, a computational representation of an individual's sleep-wake pattern. For now, the practical value is a small model whose inputs and assumptions are easy to examine, modify and test.

Limitations

This is a deliberately simplified proof of concept. The daily curve and five-hour half-life are illustrative inputs, while the relationship used to shift the curve is a modelling assumption. The simulation does not yet represent medication absorption, differences between formulations or variation between individuals. The next step is to test how much the results change when the half-life or assumed phase-shift factor changes. A later study could compare model outputs with actigraphy and sleep diaries. Because sleep onset and circadian phase are not identical, claims about changes in the internal biological clock would require appropriate biological measurements. These steps would turn the current demonstration into a model that can be evaluated against evidence.

Conclusion

This project demonstrates how two simple equations can be used to explore medication timing and a daily rhythm in the same Python simulation.

The decay curves show how a later starting time changes the relative level at 22:00. The second figure shows what happens when an explicitly hypothetical delay is applied to the rhythm. The contribution of this independent project is a transparent starting point for future testing with real sleep and activity measurements, building on my earlier interest in actigraphy-based ADHD research.

References

1. Feretzakis G, et al. Enhanced Machine Learning Approach to ADHD Classification Using Actigraphy Data. Stud Health Technol Inform. 2025;328:136-140. doi:10.3233/SHTI250688.

2. Kidwell KM, Van Dyk TR, Lundahl A, Nelson TD. Stimulant Medications and Sleep for Youth With ADHD: A Meta-analysis. Pediatrics. 2015;136(6):1144-1153. doi:10.1542/peds.2015-1708.

3. Wiggs KK, Breaux R, Langberg JM, Peugh JL, Becker SP. Examining daily stimulant medication use and sleep in adolescents with ADHD. Eur Child Adolesc Psychiatry. 2024;33:821-832. doi:10.1007/s00787-023-02204-w.