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?

  • $\begingroup$ Missing values can be ignored, or you can decide that the average is not defined if any value is missing. Your choice. $\endgroup$ – Nick Cox Feb 26 '19 at 14:22
  • $\begingroup$ @NickCox Suppose I have data for 7 days. No value is missing. Can I calculate moving average in this situation? $\endgroup$ – user149054 Feb 26 '19 at 14:30
  • $\begingroup$ 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$. $\endgroup$ – Nick Cox Feb 26 '19 at 14:32
  • 1
    $\begingroup$ Chatfield's book on time series should serve. Many older texts and reviews remain valid e.g. sciencedirect.com/science/article/abs/pii/S0065268708604872 $\endgroup$ – Nick Cox Feb 26 '19 at 14:44
  • 2
    $\begingroup$ 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? $\endgroup$ – whuber Feb 26 '19 at 14:49

We generally do moving average in the following way:

enter image description here

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.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.