Apple average data issues

Apple’s Health system - including the Health and Fitness apps on the iPhone and the Workout app on the Apple Watch - calculates incorrect average values for a range of data types. To grasp the magnitude of this error requires a brief primer on averages, and how they are calculated on a computer.

The average, or mean value of any mathematical function is always calculated as the average value of the function over a specified interval. Mathematically, the function is integrated over the specified integral using calculus, and then divided by the length of the interval.

Integration calculates the area under the curve of a mathematical function.

Integrations calculates the area under the curve for an interval

When you have a series of measurements of a mathematical function - power, cadence, or heart rate for example - these measurements are sample readings at a specific point in time. Even though the function is only measured at specific points, you can still imagine connecting a line or curve through these points. Someone doesn’t stop pedaling, or their heart doesn’t stop beating simply because you haven’t measured at a specific point in time.

Numerical integration, or quadrature, is the process for estimating the value of the integral of the function using only the measured data points. The simplest approach to numerical integration is to imagine slicing the curve to integrate into small slices, and then summing these slices to estimate the total area under the curve. Riemann sums use square slices to perform this calculation.

Riemann sums estimate the integral of a curve by summing up rectangle slices

The Trapezoidal rule is a more complex approach to numerical integration that use trapezoidal slices instead of the rectangles of Riemann sums.

The Trapezoidal rule estimates the integral of a curve by summing up trapezoid-shaped slices

Simpson’s Rule provides an even more complex approach to quadrature and creates a parabolic curve between each set of three adjacent points, and then calculates the area under each curve.

Simpson’s rule integrates the area under a curve by creating smaller curves, and summing up the area under each three-point curve

Simpson’s rule has a substantial limitation - you cannot use it when the intervals between measurement samples are non-uniform. But this is precisely the situation encountered . The Non-Uniform Simpson’s rule extends Simpson’s rule to allow for the possibility of non-uniform sample time intervals.

If there is an odd number of measurement samples, an additional correction term needs to be added to account for the odd number of samples.

The average value is calculated by dividing any of these numerical integration estimates by the length of the interval. For a time based measurement, this is simply the total measurement time.

Apple’s Health system calculates a simple average, without considering the time interval of each sample. This provides the average value of the measurements, but fails to provide the correct average value if the time interval of each sample is non-uniform. Consider the error if you had three power measurements: 200 watts, 250 watts, and 300 watts. The simple average is 250 watts. But, if the 300 watt sample was taken over a three second time interval, while the 200 and 250 watt sample were observed over one second intervals, the true average value is 270 watts. The Apple’s Health system simple average value has a nearly 10% error in this hypothetical example.

Apple’s Health system calculates average values as a simple average of the measurement sample values 

Previous
Previous

Apple’s erroneous average power data

Next
Next

Cycling strength workouts