MOVSTDEV

Purpose:

Calculates the moving standard deviation of a series.

Syntax:

MOVSTDEV(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.

0

:

down

1

:

up (default)

dof

-

Optional. An integer, the degrees of freedom normalization mode.

0

:

sample standard deviation, normalize by 1/(N-1) (default)

1

:

population standard deviation, normalize by 1/N

"naflag"

-

Optional. A string, the NA handling method.

"omitnan"

:

ignore NA values (default)

"includenan"

:

include NA values

"edgeflag"

-

Optional. A string, the edge processing flag.

"full"

:

process all segments (default)

"center"

:

center the result within the overlapping N point segments

"discard"

:

only process segments of length N, ignore partial segments

"shrink"

:

shrink the size of both the start and end segments to the actual number of samples in the segments

Returns:

A series or table.

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movstdev(w1, 3)

W3: movstd(w1, 3)

 

W2 == {0, 0.7071, 1, 1, 0.5774, 1, 1, 0.7071, 0}

W3 == {0.7071, 1, 1, 0.5774, 1, 1, 0.7071}

 

W2 computes the sample standard deviation 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 standard deviation where the result at point N is the average of points N-1, N and N+1. The computation begins at sample 2.

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movstdev(w1, 3, 0)

 

W2 == {0, 0.5, 1, 1, 0.5774, 1, 1, 0.5, 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).

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movstdev(w1, 3, 1, 1)

W3: movstd(w1, 3, 1)

 

W2 == {nan, 0.5, 0.8165, 0.8165, 0.4714, 0.8165, 0.8165, 0.5, nan}

W3 == {0.5, 0.8165, 0.8165, 0.4714, 0.8165, 0.8165, 0.5}

 

Same as the first example, except the population variance is computed.

Example:

W1: {4, 3, 2, nan, 2, 3, 4}

W2: movstdev(w1, 3)

W3: movstdev(w1, 3, "includenan")

 

W2 == {0, 0.7071, 1, 1, 0.5774, 1, 1, 0.7071, 0}

W3 == {0, 0.7071, 1, nan, nan, nan, 1, 0.7071, 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.

Example:

W1: {4, 3, 2, nan, 2, 3, 4}

W2: movstdev(w1, 3, 0)

W3: movstdev(w1, 3, 0, "includenan")

 

W2 == {0, 0.5, 1, 0.7071, 0, 0.7071, 1, 0.5, 0}

W3 == {0, 0.5, 1, nan, nan, nan, 1, 0.5, 0}

 

Same as above except the segment dof remains fixed at 1 / (3 - 1).

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movstdev(w1, 3, "center")

W3: movstdev(w1, 3, 0, "center")

 

W2 == {0.7071, 1, 1, 0.5774, 1, 1, 0.7071}

W3 == {0.5, 1, 1, 0.5774, 1, 1, 0.5}

 

W2 and W3 compute a 3 point centered moving average where the result at point N is the average 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.

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movstdev(w1, 3, "discard")

W3: movstdev(w1, 3, 0, "discard")

 

W2 == {3, 2, 1.6667, 2, 3}

W3 == {3, 2, 1.6667, 2, 3}

 

W2 and W3 compute a 3 point moving 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.

Example:

W1: {4, 3, 2, 1, 2, 3, 4}

W2: movstdev(w1, 3, "shrink")

W3: movstdev(w1, 3, 0, "shrink")

 

W2 == {0, 0.7071, 1, 1, 0.5774, 1, 1, 0.7071, 0}

W3 == {0, 0.7071, 1, 1, 0.5774, 1, 1, 0.7071, 0}

 

Same as the first example, where the average 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.

Remarks:

MOVSTDEV computes the non-centered moving standard deviation.

 

For each section of length N, the sample standard deviation value (dof == 0) is defined as:

 

sample standard deviation

 

where the arithmetic mean is defined as:

 

mean

 

The population standard deviation (dof == 1) is defined as:

 

population standard deviation

 

NaN values are ignored by default. Set naflag to "includenan" to process NaN values.

 

For the default, where rampflag == 1 and edgeout == "full", the first N-1 points returned by MOVSTDEV given an N-point window are the standard deviation of the values in consecutively larger segments of size 1, 2, 3, ... , N-1. The last N-1 points are the standard deviation of the values of consecutively smaller segments of sizes N-1, N-2, ..., 2, 1. The output length is L + N - 1 where L is the length of the input series.

 

For edgeflag == "center", the result is centered within the N-point segment and the output length is the same as the input length.

 

For edgeout == "shrink", the rampflag is forced to 1 and the result is the same as rampflag == 1 and edgeout == "full". However the first and last N-1 points differ from "shrink" if rampflag == 0 and edgeout == "full".

 

For edgeout == "discard", only segments that contain exactly N samples are processed. Shorter segments at the start and end edges are discarded. The rampflag is ignored.

 

See MOVSTD to compute the centered moving standard deviation.

 

See XMOVSTDEV to compute the moving standard deviation given a duration.

See Also:

MOVAVG

MOVRMS

MOVSTD

MOVVAR

STD

STDEV

XMOVSTDEV