2018-04-01

Interval Matters: When the Same Data Gives Different Answers

Same data, same range, but bucket it differently and the averages diverge. Which one's right depends on what you're trying to measure.

TimeseriesCalculations

Picture a dashboard tile that says "energy per unit produced". Same raw data feeding it, two engineers reviewing the figure, but the tile is configured at different intervals on their respective dashboards. The two of them see different numbers, and both are right.

Same data · same 7-day range
Energy / Unit Produced
Last 7 days · 12 – 18 May
4.32kWh/unit
Hourly interval
Energy / Unit Produced
Last 7 days · 12 – 18 May
3.95kWh/unit
Daily interval

That's the wrinkle this article digs into. When a calculation involves multiplication or division, the interval you bucket the data into changes the answer, sometimes by a lot.

The setup

A week of hourly data is a lot of rows to keep track of. To keep the arithmetic easy to follow, let's shrink the example down: twenty minutes of data sampled every five minutes, each row pairing an energy reading with a production count for some arbitrary process. The KPI stays the same, energy per unit produced, the of the two.

We can compute that quotient row by row at the native 5-minute interval, then average. Or we can fold the rows into pairs and compute it at 10-minute intervals. Or we can collapse the entire range into a single calculation. The widget below runs all three in parallel; tweak the inputs and watch the headline numbers move independently.

Interval comparator

Edit the raw 5-minute readings and watch the three "averages" diverge. Try setting all values equal to see when they don't.

TimeEnergyProduct
00:00
00:05
00:10
00:15
5-minute interval
9 ÷ 61.50
6 ÷ 16.00
7 ÷ 32.33
2 ÷ 12.00
Avg of quotients
2.96
10-minute interval
15 ÷ 72.14
9 ÷ 42.25
Avg of quotients
2.20
Entire range
24 ÷ 112.18
Single quotient
2.18

With the default values the three answers are 2.96, 2.20 and 2.18. Same data, same twenty minutes, three different "averages".

Why they disagree

Division (and multiplication) doesn't commute with averaging. The mean of a set of quotients is not generally the quotient of the means:

1ni=1naibi    1ni=1nai1ni=1nbi\frac{1}{n}\sum_{i=1}^{n} \frac{a_i}{b_i} \;\neq\; \frac{\frac{1}{n}\sum_{i=1}^{n} a_i}{\frac{1}{n}\sum_{i=1}^{n} b_i}

The two sides only agree when every bᵢ is the same, or when the ratios aᵢ/bᵢ are all equal. Set the four production values in the widget to anything constant and the three headline numbers collapse onto each other.

This is the calculation-side cousin of the folding and interpolation story: folding decides how a window's values reduce to one. The interval decides when in the pipeline that folding happens, before or after the divide, and that ordering changes the answer.

Picking an interval

None of the three numbers above is "wrong"; they each answer a slightly different question. The 5-minute version asks "what was the typical efficiency in any given 5-minute slice?". The entire-range version asks "over the full twenty minutes, how much energy did we burn per unit?". The 10-minute version sits in between.

The two engineers staring at their disagreeing dashboards were both right. They just hadn't realised they were answering different questions.

Picking an interval is therefore a modelling decision rather than a presentation one. It implicitly encodes an assumption about how the inputs relate. If there's a lag between energy use and production being recorded, a 5-minute slice may pair an energy spike with the previous slice's production count and quietly mislead. A wider interval that brackets the lag often makes the metric more honest.