Calculates the moving variance of a series.
MOVVARIANCE(series, N, rampflag, dof, "naflag", "edgeflag")
series |
- |
A series or array, the input series |
||||||||||||
N |
- |
An integer, the number of points to compute the variance as the series is processed. |
||||||||||||
rampflag |
- |
Optional. An integer, endpoint averaging flag.
|
||||||||||||
dof |
- |
Optional. An integer, the degrees of freedom normalization mode.
|
||||||||||||
"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: movvariance(w1, 3)
W3: movvar(w1, 3)
W2 == {0, 0.5, 1, 1, 0.3333, 1, 1, 0.5, 0}
W3 == {0.5, 1, 1, 0.3333, 1, 1, 0.5}
W2 computes the sample variance of each overlapping moving segment of length 3 but the segment length adjusts from 1 to 3 at the start edge and from 3 to 1 at the end edge. The segment dof adjusts accordingly.
W3 computes the 3-point centered sample variance where the result at point N is the average of points N-1, N and N+1. The computation begins at sample 2.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movvariance(w1, 3, 0)
W2 == {0, 0.25, 1, 1, 0.3333, 1, 1, 0.25, 0}
Same as above where the segment length adjusts from 1 to 3 at the start edge and from 3 to 1 at the end edge but N is fixed at 3 and the segment dof remains fixed at 1 / (3 - 1).
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movvariance(w1, 3, 1, 1)
W3: movvar(w1, 3, 1)
W2 == {nan, 0.25, 0.6667, 0.6667, 0.2222, 0.6667, 0.6667, 0.25, nan}
W3 == {0.25, 0.6667, 0.6667, 0.2222, 0.6667, 0.6667, 0.25}
Same as the first example except the population variance is computed.
W1: {4, 3, 2, nan, 2, 3, 4}
W2: movvariance(w1, 3)
W3: movvariance(w1, 3, "includenan")
W2 == {0, 0.5, 1, 1, 0.3333, 1, 1, 0.5, 0}
W3 == {0, 0.5, 1, nan, nan, nan, 1, 0.5, 0}
W2 excludes all NaN values by removing them from the segment and adjusting the segment size and associated dof down.
W3 retains NaN values and returns NaN if any NaN is present in the segment.
W1: {4, 3, 2, nan, 2, 3, 4}
W2: movvariance(w1, 3, 0)
W3: movvariance(w1, 3, 0, "includenan")
W2 == {0, 0.25, 1, 0.5, 0, 0.5, 1, 0.25, 0}
W3 == {0, 0.25, 1, nan, nan, nan, 1, 0.25, 0}
Same as above except the segment dof remains fixed at 1 / (3 - 1).
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movvariance(w1, 3, "center")
W3: movvariance(w1, 3, 0, "center")
W2 == {0.5, 1, 0.7071, 0, 0.7071, 1, 0.5}
W3 == {0.25, 1, 1, 0.3333, 1, 1, 0.25}
W2 and W3 compute a 3-point centered moving variance where the result at point N is the variance of points N-1, N and N+1.
For W2, the segment length and segment divisor adjust from 1 to 3 at the start edge and from 3 to 1 at the end edge.
For W3, the segment length also adjusts from 1 to 3 at the start edge and from 3 to 1 at the end edge but the segment divisor remains fixed at 3.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movvariance(w1, 3, "discard")
W3: movvariance(w1, 3, 0, "discard")
W2 == {1, 1, 0.3333, 1, 1}
W3 == {1, 1, 0.3333, 1, 1}
W2 and W3 compute a 3-point moving variance for all overlapping segments that contain exactly 3 samples. Shorter segments at the start and end edges are discarded. The rampflag parameter has no effect.
W1: {4, 3, 2, 1, 2, 3, 4}
W2: movvariance(w1, 3, "shrink")
W3: movvariance(w1, 3, 0, "shrink")
W2 == {0, 0.5, 1, 1, 0.3333, 1, 1, 0.5, 0}
W3 == {0, 0.5, 1, 1, 0.3333, 1, 1, 0.5, 0}
Same as the first example, where the variance of each overlapping moving segment of length 3 is computed but the segment length and segment divisor adjust from 1 to 3 at the start edge and from 3 to 1 at the end edge. The rampflag is essentially forced to 1.
MOVVARIANCE computes the non-centered moving variance.
For each section of length N, the
sample variance value (
where the arithmetic mean is defined as:
The population variance
NaN values are ignored by default. Set naflag to "includenan" to process NaN values.
For the default, where
For edgeflag == "center", the result is centered within the N-point segment and the output length is the same as the input length.
For
For
See MOVVAR to compute the centered moving variance.
See XMOVVARIANCE to compute the moving variance given a duration.