CUMVAR

Purpose:

Calculates the cumulative variance of a series.

Syntax:

CUMVAR(series, dof, dim, "naflag")

series

-

A series or array, the input series

dof

-

Optional. An integer, the degrees of freedom normalization mode. For N = length of current segment:

0

:

Normalize by 1/(N-1) (default)

1

:

Normalize by 1/N

dim

-

Optional. An integer or string, the computation dimension.

1

:

calculate column-wise (default)

2

:

calculate row-wise

"naflag"

-

Optional. A string, the NA handling method.

"omitnan"

:

ignore NA values (default)

"includenan"

:

include NA values

Returns:

A series or table.

Example:

cumvar({20, 15, 30, 10, 25})

 

returns {nan, 12.5, 58.3333, 72.9167, 62.5}.

Example:

W1: integ(gnorm(1000, 1))

W2: cumvar(W1)

 

variance(W1) == W2[end]

 

The last point of CUMVAR is the overall variance of the input data.

Example:

W1: {20, 15, nan, nan, 25}

W2: cumvar(w1)

W3: cumvar(w1, "omitnan")

W4: cumvar(w1, "includenan")

 

W2 == {nan, 12.5, 12.5, 12.5, 25}

W3 == {nan, 12.5, 12.5, 12.5, 25}

W4 == {nan, 12.5, nan, nan, nan}

 

Both W2 and W3 omit the NaN values.

 

W4 includes the NaN values such that once an NaN is encountered, the cumulative variance remains at NaN.

Example:

W1: {20, 15, nan, nan, 25}

W2: cumvar(w1, 1)

W3: cumvar(w1, 1, "omitnan")

W4: cumvar(w1, 1, "includenan")

 

W2 == {0, 6.25, 6.25, 6.25, 16.6667}

W3 == {0, 6.25, 6.25, 6.25, 16.6667}

W4 == {0, 6.25, nan, nan, nan}

 

Same as above except dof is set to 1, normalize by 1/N.

Example:

W1: {3 + i, 4 + 2i, 2 + 3i, 2 + 4i, 8 + 5i}

W2: cumvar(w1)

W3: cumvar(w1, 1)

 

W2 == {nan, 1, 2, 2.5833, 8.7}

W3 == {0, 0.5, 1.3333, 1.9375, 6.9600}

 

The variance of a complex series is real.

Remarks:

CUMVAR calculates the cumulative variance of a series.

 

The nth value of the output series is equal to the variance of the first n points of the input series.

 

For dof == 0 (i.e. 1/(N-1) scaling), the first point of the result is nan.

 

For dof == 1 (i.e. 1/N scaling), the first point of the result is 0.

 

See CUMAVG for the cumulative average.

See Also:

CUMAVG

CUMMAX

CUMPROD

CUMSUM

VAR