So, I am keeping an average value using the incremental averaging approach. I have some "saves" of this average value, along with its samples count. Is there a way to calculate the avg for a timeframe between two of those "saves"?
E.g. let's say I have two "saves", on the first day of the month for Jan and Feb each.
for Jan: SamplesCount = $50$, AverageValue = $10$
for Feb: SamplesCount = $125$, AverageValue = $25$
What I want to know is the values for the Jan-Feb timeframe. The SamplesCount is simple, it would be $125-50=75$. But is there a way to get AverageValue for Jan-Feb?
Yes, there is a way to calculate the average value for the Jan-Feb timeframe. The formula for incremental averaging is:
$average_{new} = \frac{average_{prev} * samples_{prev} + value}{samples_{prev} + 1}$
where $average_{new}$ is the updated average, $average_{prev}$ is the previous average, $samples_{prev}$ is the previous number of samples, and $value$ is the new value.
So, to find the average value for Jan-Feb, you can use the formula to find the average of Jan and Feb separately, then calculate the average of these two results using the formula again with the samples count of both months.
$average_{Jan-Feb} = \frac{\frac{average_{Jan} * samples_{Jan} + average_{Feb} * samples_{Feb}}{samples_{Jan} + samples_{Feb}}}{samples_{Jan} + samples_{Feb}}$
Plugging in the values:
$average_{Jan-Feb} = \frac{\frac{10 * 50 + 25 * 125}{50 + 125}}{50 + 125} = \frac{10 * 50 + 25 * 125}{175} = \frac{500 + 3125}{175} = \frac{3625}{175} = \frac{145}{7}$