# What is the lag associated with Moving Average smoothing?

In a tutorial I came across this:

"Recall that the forecast value is: $$\hat{y}_{t+1} = \frac{y_t + y_{t-1} + ... + y_{t-m+1}}{m}$$

It's worth pondering that formula for a minute. While easy to understand, one of its properties may not be obvious. What's the lag associated with this technique? Think it through. The answer is $$\frac{(m+1)}{2}$$ For example, say you're averaging the past 5 values to make the next prediction. Then local changes will yield a lag of $$\frac{5+1}{2} = 3$$ periods. Clearly, the lag increases as you increase the window size for averaging."

Before going through this, I thought I have the correct intuition of a moving average model. If I choose a window of m, then the prediction y(t+1) is based on m previous values and thus the lag is m. How does this tutorial come up with this formula for lag? As an example, how does a window size of m in a moving average smoothing model, correspond to a lag of 3?

Wikipedia has good commentary on the interpretation of a moving average (MA) model, to quote:

The moving-average model is essentially a finite impulse response filter applied to white noise, with some additional interpretation placed on it. The role of the random shocks in the MA model differs from their role in the autoregressive (AR) model in two ways. First, they are propagated to future values of the time series directly: for example, $${\varepsilon _{t-1}}$$ appears directly on the right side of the equation for $${X_{t}}$$. In contrast, in an AR model $${\varepsilon _{t-1}}$$ does not appear on the right side of the $${ X_{t}}$$ equation, but it does appear on the right side of the $${X_{t-1}}$$ equation, and $${ X_{t-1}}$$ appears on the right side of the $${X_{t}}$$ equation, giving only an indirect effect of $${\varepsilon _{t-1}}$$ on $${X_{t}}$$. Second, in the MA model a shock affects $${X}$$ values only for the current period and q periods into the future; in contrast, in the AR model a shock affects $${X}$$ values infinitely far into the future, because $${\varepsilon_{t}}$$ affects $${X_{t}}$$, which affects $${X_{t+1}}$$, which affects $${X_{t+2}}$$, and so on forever (see Vector autoregression#Impulse response).

In essence, it is about the observed mechanics of how a random shock is propagated across time. Relatedly, drop a stone in a pool of water and observed the movement and change in the generated shock wave as a function of time. If you alter the medium (for example, use molasses), it changes (truncates) the wave propagation.

[EDIT] Per a comment below, my understanding is that a MA smoothing formula is a mechanically applied naive rendition of a possible more general MA time series model. It is often used to display a smoother graph of random data for which, with a longer time series, perhaps a more precise MA time series model may actually be indicated. MA smoothing is a simple convenient tool and should not be viewed as mathematically precise with a deeper meaning, in my opinion. See Wikipedia comments, which is in agreement with my general sentiments.

• Thanks for the comment but this does not answer my question of how a window of 5 corresponds to a lag of 3. Also, I believe you and this Wikipedia section, are talking about Moving Average (MA) model. I am referring to the Moving Average Smoothing model which has no connection to the MA model. – Shahzeb Naveed Dec 3 '20 at 4:57
• Thanks for the comment, I have added some commentary (with an edit) on MA smoothing relative to its application and relationship to a MA time series model. – AJKOER Dec 3 '20 at 5:22

Hi: When the quote calculates the the value of three, it's calculating the average lag.

So, the first value ( $$y_t$$ ) has a lag of 1, the second 2, the third 3, the fourth 4 and the fifth 5. So, the sum of those is m(m+1)/2. Then you divide by m to get the average lag and get (m+1)/2.

Brown ( below ) has a nice explanation of this sort of thing in his text. I recommend it for this topic.

https://www.amazon.com/Smoothing-Forecasting-Prediction-Discrete-1963-05-03/dp/B01FGN92SG/ref=sr_1_1?dchild=1&keywords=brown+forecasting%2C+prediction&qid=1607080240&sr=8-1

The lag of a moving average is actually the X-axis coordinate of the centre of gravity of the weight function: (image by John Ehlers):

In your tutorial, the "forecast value" is an arithmetic mean: or in in plain English: sum all observations, and divide the sum by the number of observations, resulting in a "Simple Moving Average" (SMA). Another way to come to the same result, is to multiply all observations by $$1/n$$, and sum those products.

In discrete time series analysis, you have a window that moves from the start (left) to the end (right) of your graph, step by step, so you look at the ($$n$$) observations in the window, multiply them all with $$1/n$$, sum them, and this gives you the result (the value of the moving average), after that, you move 1 step to the right, and you repeat the process for the next value of the moving average: engineers call this process "convolution", and the $$n$$ times $$1/n$$ are the "coefficients", or "weights" you multiply the segment of your time series that falls in the window with (in the current step).

Now, your "forecast value", is a Simple Moving Average. So the weight function will have a rectangular shape, and the (X-axis coordinate of the) centre of gravity is not $$(m+1)/2$$, but it is $$(n-1)/2$$, with n the window length.

There are different types of moving averages, who use different shapes of these weight functions to try to reduce this lag: e.g. the weights of a Linear Weighted Moving Average will not have a rectangular, but a triangular shape: the centre of gravity's x-axis coordinate of a right triangle will be at $$1/3$$rd its length, so this averaging technique will follow the original time series quicker if it turns.

There even is a group of moving averages that try to cancel out the lag entirely, by using weights/coefficients that are negative at the back (left) of the window (ZLEMA, HMA, ...). These are good attempts, but there is 1 thing you need to keep in mind: this theoretical lag is only correct on consistently rising/falling prices, and if you define $$m$$, (or $$n$$) in terms of lag, there actually is very little difference between all these coefficients/weighting schemes.

So to answer your question: "As an example, how does a window size of m in a moving average smoothing model, correspond to a lag of 3?" -> it depends: for a SMA (or EMA) it will be 7: ($$(n-1)/2$$), for a LWMA it will be 10: ($$(n-1)/3$$), ... It all depends on the shape of your coefficients / weight function, and its centre of gravity.

And btw: a moving average as a forecast would require highly, highly persistent input data to be statistically significant. But that's another discussion entirely..

Good luck.