Monday 13 April 2015

Calculate Running Average

Calculate Running Average


A running average can be either of two measurements. A cumulative running average includes all values, and is updated whenever a new value is added to the data set. Running average may also refer to moving average, or the average of a subset of the most recent measurements.


You might calculate the cumulative running average of the age of everyone in a club. Every time a new member joins, the cumulative average changes. A moving average could be the average high temperature over the last two weeks: each day, the set of data used to calculate the average "moves" one day.


Instructions


Calculating a Cumulative Running Average


1. Sum all data values. For example, the sum of the seven numbers 34, 35, 23, 26, 40, 27 and 39 is 224.


2. Divide the sum of all values by the number of values in the data set to obtain the average value. In the example, the average is 224 / 7 = 32. Store or otherwise remember the sum and the number of values.


3. Add any newly recorded values to the previous sum of numbers. For a new value = 38 added to the previous data set, the new sum is 262. There are now eight values, so the new average = 262 / 8 = 32.75. Continue adding new values to the previous sum, and continue to increment the count of variables each time.


Calculate a Moving Window Running Average


4. Select a window size. For example, from a set of seven numbers (34, 35, 23, 26, 40, 27, 39) a reasonable window size could be 5. Sum the 5 most recently recorded numbers: 23 + 26 + 40 + 27 + 39 = 155.


5. Divide the sum by 5, the number of values in the window. Using the example, 155 / 5 = 31.


6. Add any new values to the end of the list of numbers, such as a new value of 38. Sum the 5 values most recently recorded, in this case 26 + 40 + 27 + 39 + 38 = 170.


7. Divide the sum by 5, because the number of values in the window has not changed. In our example, 170 / 5 = 34.


8. Repeat, each time discarding the oldest value from the window and adding in the newest value. Always divide by the same number, the window "length."

Tags: number values, Running Average, Calculate Running, Calculate Running Average, cumulative running average, each time