CUMAVG

Purpose:

Calculates the cumulative average of a series.

Syntax:

CUMAVG(series, dim, "naflag")

series

-

A series or array, the input series

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.

"includenan"

:

include NA values (default)

"omitnan"

:

ignore NA values

Returns:

A series or table.

Example:

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

 

returns {20, 17.5, 21.6667, 18.75, 20}.

Example:

W1: gnorm(1000, 1)

W2: gline(length(w1), deltax(w1), 1/1000, 0)

W3: W1 + W2

W4: cumavg(W3)

 

W3 contains the sum of 1000 random samples and a linear trend.

 

W4 shows the linear trend developing as more samples of the data are averaged.

Example:

W1: integ(gnorm(1000, 1))

W2: cumavg(W1)

 

mean(W1) == W2[end]

 

The last point of CUMAVG is the overall average of the input data.

Example:

W1: {{1, 2, 3},

     {4, 5, 6},

     {7, 8, 9}}

 

W2: cumavg(w1)

W3: cumavg(w1, 1)

W4: cumavg(w1, 2)

 

W2 == {{1.0, 2.0, 3.0},

       {2.5, 3.5, 4.5},

       {4.0, 5.0, 6.0}}

 

W3 == {{1.0, 2.0, 3.0},

       {2.5, 3.5, 4.5},

       {4.0, 5.0, 6.0}}

 

W4 == {{1.0, 1.5, 2.0},

       {4.0, 4.5, 5.0},

       {7.0, 7.5, 8.0}}

 

Both W2 and W3 compute the cumulative average along the columns.

 

W4 computes the cumulative average along the rows.

Example:

W1: {{1,   2, 3},

     {nan, 5, 6},

     {7,   8, 9}}

 

W2: cumavg(w1)

W3: cumavg(w1, 1)

W4: cumavg(w1, 2)

 

W2 == {{1.0, 2.0, 3.0},

       {nan, 3.5, 4.5},

       {nan, 5.0, 6.0}}

 

W3 == {{1.0, 2.0, 3.0},

       {nan, 3.5, 4.5},

       {nan, 5.0, 6.0}}

 

W4 == {{1.0, 1.5, 2.0},

       {nan, nan, nan},

       {7.0, 7.5, 8.0}}

 

The NaN value is included in the computations by default.

Example:

W1: {{1,   2, 3},

     {nan, 5, 6},

     {7,   8, 9}}

 

W2: cumavg(w1, "omitnan")

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

W4: cumavg(w1, 2, "omitnan")

 

W2 == {{1.0,   2.0, 3.0},

       {0.5,   3.5, 4.5},

       {2.667, 5.0, 6.0}}

 

W3 == {{1.0,   2.0, 3.0},

       {0.5,   3.5, 4.5},

       {2.667, 5.0, 6.0}}

 

W4 == {{1.0, 1.5, 2.0},

       {0.0, 2.5, 3.667},

       {7.0, 7.5, 8.0}}

 

Same as above except the NaN value is omitted from the computations.

Remarks:

The nth value of the output series is equal to the mean of the first n points of the input series:

 

 

See CUMSUM to compute the cumulative sum.

See Also:

CUMMAX

CUMMIN

CUMPROD

CUMSUM

CUMTRAPZ

INTEG

MEAN

MOVAVG

PARTSUM

SUM