# Moving Average Method

Suppose I have data for 6 months: $$2,5,1,9,3,4$$. If I calculate 3 months moving average, then from this data, I get two average $$2.667(=\frac{2+5+1}{3})$$ and $$5.333(=\frac{9+3+4}{3})$$.

But if I have data for only 5 months, $$2,5,1,9,3$$, and I want to calculate moving average, how can I calculate it?

• Missing values can be ignored, or you can decide that the average is not defined if any value is missing. Your choice. – Nick Cox Feb 26 '19 at 14:22
• @NickCox Suppose I have data for 7 days. No value is missing. Can I calculate moving average in this situation? – user149054 Feb 26 '19 at 14:30
• Why not? Length of window is your choice. Odd numbers of values are convenient window lengths, because then the average of $y_{t-k}, \dots, y_{t+k}$ can be regarded as defined for position $t$. – Nick Cox Feb 26 '19 at 14:32
• Chatfield's book on time series should serve. Many older texts and reviews remain valid e.g. sciencedirect.com/science/article/abs/pii/S0065268708604872 – Nick Cox Feb 26 '19 at 14:44
• Your examples are not a "moving average": they are block averages. The moving average for your six-number sequence is $8/3, 15/3, 13/3, 16/3.$ The moving average for the truncated five-number sequence omits the last. So: which form of average are you trying to ask about? – whuber Feb 26 '19 at 14:49

We generally do moving average in the following way: It means we have to keep on adding 3 months data and move our data point one by one, it means for this data 2,5,1,9,3,4:

Moving avg1=(2+5+1)/3

Moving avg2=(5+1+9)/3

Moving avg3=(1+9+3)/3

For even moving averages you have to iterate one more times for odd moving average you have to do single iteration.