0

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?

Kiramm
  • 101
  • 3
  • 1
    You could use $\dfrac{125 \times 25-50 \times 10}{125-50}$ or $25+\dfrac{50}{125-50}\times (25-10)$ – Henry Feb 01 '23 at 09:26

1 Answers1

0

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}$

  • Hmm, just by looking at numbers: we get 10AVG at the beginning of Jan, then for a month (Jan-Feb) we have 145/7=20.7AVG and at the beginning of Feb we should get AVG somewhere between 10 and 20.7, but the actual value is 25. Am I getting something wrong? – Kiramm Feb 01 '23 at 09:39
  • you are not correctly interpreting the result of the incremental average formula. The formula only gives the average at a specific point in time, not the average over a time period. To get the AVG over a time period, you would need to sum up the values and divide by the number of samples in that period.

    In your example, to find the average between Jan and Feb, you would sum up all the values between those two months and divide by the number of samples in that period.

    – Marco Di Giacomo Feb 01 '23 at 09:43
  • 1
    So, to find the AV for the Jan-Feb time frame, you would need to know the values of the samples, not just the count and average value at the beginning of Jan and Feb. – Marco Di Giacomo Feb 01 '23 at 09:43