Moving Average

In statistics, a moving average, also called rolling average, rolling mean or running average, is a type of finite impulse response filter used to analyze a set of data points by creating a series of averages of different subsets of the full data set.

Given a series of numbers, and a fixed subset size, the moving average can be obtained. The average of the first subset of numbers is calculated. The fixed subset is moved forward to the new subset of numbers, and its average is calculated. The process is repeated over the entire data series. The plot line connecting all the (fixed) averages is the moving average. Thus, a moving average is not a single number, but it is a set of numbers, each of which is the average of the corresponding subset of a larger set of data points. A moving average may also use unequal weights for each data value in the subset to emphasize particular values in the subset.

A moving average is commonly used with time series data to smooth out short-term fluctuations and highlight longer-term trends or cycles. The threshold between short-term and long-term depends on the application, and the parameters of the moving average will be set accordingly. For example, it is often used in technical analysis of financial data, like stock prices, returns or trading volumes. It is also used in economics to examine gross domestic product, employment or other macroeconomic time series. Mathematically, a moving average is a type of convolution and so it is also similar to the low-pass filter used in signal processing. When used with non-time series data, a moving average simply acts as a generic smoothing operation without any specific connection to time, although typically some kind of ordering is implied.

An example is given below.

x = c(55,56,48,46,56,46,59,60,53,58,73,69,72,51,72,69,68,69,79,77,53,63,80
   ,65,78,64,72,77,82,77,35,79,71,73,77,76,83,73,78,91,70,88,88,85,77,63,91,94
   ,72,83,88,78,84,78,75,75,86,79,76,87,66,73,62,27,52,47,65,59,77,47,51,47,49
   ,54,58,56,50,54,45,66,39,51,39,27,39,37,43,41,27,29,27,26,29,31,28,38,37,26,31
   ,45,38,33,33,25,24,29,37,35,32,31,28,40,31,37,34,43,38,33,28,35)
 
ma=movingAverage(x,10)
 
layout(matrix(c(1,2,3), 1, 3, byrow = TRUE))
plot(x,main="Simple Moving Average",xlab="Time",ylab="Effect size")
lines(ma$sma)
plot(x,main="Smoothed Moving Average",xlab="Time",ylab="Effect size")
lines(ma$smma,col="blue")
plot(x,main="Exponential Moving Average",xlab="Time",ylab="Effect size")
lines(ma$emo,col="orange")

The resulting plot is given below.

Moving Averages

 

[ Back ]