Calculates the centered moving average of a series or table.
MOVMEAN(series, N, "naflag", "edgeflag")
series |
- |
A series or table. |
||||||
N |
- |
An integer, the segment size. The number of points to average as the series is traversed. |
||||||
"naflag" |
- |
Optional. A string, the NA handling method.
|
||||||
"edgeflag" |
- |
Optional. A string, the edge processing flag.
|
A series or table.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movmean(w1, 3)
W3: movavg(w1, 3)
W4: movavg(w1, 3, "center")
W2 == {3.5, 3, 2, 1.6667, 2, 3, 3.5}
W3 == {4, 3.5, 3, 2, 1.6667, 2, 3, 3.5, 4}
W4 == {3.5, 3, 2, 1.6667, 2, 3, 3.5}
W2 and W4 compute a standard 3-point centered moving average. The value at any point N is the average of points N-1, N and N+1.
W3 also calculates the average of each overlapping segment of up to length 3, but it employs variable edge handling to fully include the start and end points. The segment length and segment divisor smoothly adjust from 1 to 3 at the start edge and from 3 to 1 at the end edge.
W1: {4, 3, 2, nan, 2, 3, 4}
W2: movmean(w1, 3)
W3: movmean(w1, 3, "omitnan")
W2 == {3.5, 3, nan, nan, nan, 3, 3.5}
W3 == {3.5, 3, 2.5, 2, 2.5, 3, 3.5}
W2 preserves NaNs and returns NaN when any value in the segment is NaN.
W3 excludes NaNs, reducing the segment length and divisor accordingly.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movmean(w1, 3)
W3: movmean(w1, 3, "discard")
W2 == {3.5, 3, 2, 1.6667, 2, 3, 3.5}
W3 == {3, 2, 1.6667, 2, 3}
W2 computes a 3-point centered moving average identical to the first example.
W3 computes a 3-point moving for all overlapping segments that contain exactly 3 samples. Shorter segments at the start and end edges are discarded.
MOVMEAN computes a centered moving average
by centering the result within the
NaN values are included by default. Set naflag to "omitnan" to ignore NaN values.
For
See MOVAVG for more details on the naflag and edgeflag flags.
See LINAVG to for an alternate computation of the moving average with zero phase shift.