TS_SMOOTH

The TS_SMOOTH function computes central, backward, or forward moving averages of an n-element time-series. Autoregressive forecasting and backcasting are used to extrapolate the time-series and compute a moving average for each point.

Note: Central moving averages require Nvalues/2 forecasts and Nvalues/2 backcasts. Backward moving averages require Nvalues-1 backcasts. Forward moving averages require Nvalues-1 forecasts.

This routine is written in the IDL language. Its source code can be found in the file ts_smooth.pro in the lib subdirectory of the IDL distribution.

Examples

; Define an n-element vector of time-series samples:

X = [6.63, 6.59, 6.46, 6.49, 6.45, 6.41, 6.38, 6.26, 6.09, 5.99,$

     5.92, 5.93, 5.83, 5.82, 5.95, 5.91, 5.81, 5.64, 5.51, 5.31,$

     5.36, 5.17, 5.07, 4.97, 5.00, 5.01, 4.85, 4.79, 4.73, 4.76]



; Compute the 11-point central-moving-averages of the time-series:

PRINT, TS_SMOOTH(X, 11)

IDL prints:

6.65761 6.60592 6.54673 6.47646 6.40480 6.33364

6.27000 6.20091 6.14273 6.09364 6.04455 5.99000

5.92273 5.85455 5.78364 5.72636 5.65818 5.58000

5.50182 5.42727 5.34182 5.24545 5.15273 5.07000

5.00182 4.94261 4.87205 4.81116 4.75828 4.71280

Syntax

Result = TS_SMOOTH( X, Nvalues [, /BACKWARD] [, /DOUBLE] [, /FORWARD] [, ORDER=value] )

Return Value

The result is an n-element vector of the same data type as the input vector.

Arguments

X

An n-element single- or double-precision floating-point vector containing time-series samples. Note that n must be greater than or equal to 11.

Nvalues

A scalar of type integer or long integer that specifies the number of time-series values used to compute each moving-average. If central-moving averages are computed (the default), this parameter must be an odd integer greater than or equal to three.

Keywords

BACKWARD

Set this keyword to compute backward-moving averages. If BACKWARD is set, the Nvalues argument must be an integer greater than one.

DOUBLE

Set this keyword to force the computation to be done in double-precision arithmetic.

FORWARD

Set this keyword to compute forward-moving averages. If FORWARD is set, the Nvalues argument must be an integer greater than one.

ORDER

An integer or long-integer scalar that specifies the order of the autoregressive model used to compute the forecasts and backcasts of the time-series. By default, a time-series with a length between 11 and 219 elements will use an autoregressive model with an order of 10. A time-series with a length greater than 219 will use an autoregressive model with an order equal to 5% of its length. The ORDER keyword is used to override this default.

Version History

5.0

Introduced

See Also

SMOOTH, TS_DIFF, TS_FCAST