Page 1 of 1

What algorithm is used for the "Moving Average"

Posted: Sun Nov 01, 2009 11:23 pm
by John
I need to know what mathematical algorithm is used for the moving average calculations.

Normally, a moving average will require that the "end regions" of the graph not be included in the graph of the moving average, since, for example, a centered 11-day moving average can't provide data for the first 5 days and therefore can't be graphed. The same is true of the last 5 days in this example. I believe this problem is inherent in all moving average calculation varieties (though I'm open to being educated).

I bring it up because graphing the end-point regions of a moving average generates quite a bit of controversy in the climate sciences where I work because the end regions normally excluded in a moving average have to be filled in based on some sort of (often unscientific) assumption--even a simple "continue the trend" assumption.

Regardless of which moving average method (and extensions to graph end-points) is used, could you provide me with the algorithm and in the future include it in the help/pdf user manual, David? I've tried searching the forum & couldn't find anything. I just need to explain to those I'm presenting my graphs to how the calculations were made. Ideally, I'd prefer an option to exclude the extend-to-endpoint algorithms altogether.

Many thanks.
John

Posted: Mon Nov 02, 2009 9:57 am
by DPlotAdmin
John,
The output is an average of the previous N points, where N is the interval chosen. This is identical to the Moving Average function of Excel's Analysis ToolPak, with the exception that Excel gives "#N/A" for the first N-1 points, while the DPlot plugin gives the average of the previous i points for the i'th point.

It would be easy enough to add a couple of options here:

1) Trailing points or centered (not sure what should happen in the latter case if N is even; probably shouldn't allow it.)

2) At the tails, either return an average or... don't.

Posted: Mon Nov 02, 2009 2:01 pm
by John
I'll check out the Excel documentation (I'm assuming I'll find the formula there). And on centered moving averages, they do require an odd number of points.

Really appreciate the help. The climate community gets a little "paranoid" about what's going on behind the curtain when one is trying to draw temperature trend lines onto current data (not to mention future projections)--especially warming vs cooling ones. :wink:

--John

Posted: Mon Nov 02, 2009 10:03 pm
by DPlotAdmin
I think you'll like this one better:

http://www.dplot.com/plugins/generate/movavg.dll

Overwrite the existing <dplot folder>\plugins\generate\movavg.dll with this one. This will be included in the next release.

Posted: Mon Nov 02, 2009 10:36 pm
by John
Love it. Now that's what you call customer service! :D

Posted: Tue Nov 03, 2009 1:11 pm
by DPlotAdmin
Thanks - glad you noticed :D

For anybody else following this thread who hasn't downloaded the updated plugin, here's a look at the new input:

Image

"Prior moving average" is what the plugin has always produced. "Include tails", if checked, acts the same way that the previous plugin did by default: for interval N and point i for i < N, with a "prior moving average" points 1 through (N-1) use (Y1+Y2+...+Yi)/i. If "Include tails" is unchecked, you only get output starting with point number N (1-based). Same sort of deal for "central moving average".