Scripting > Math Functions

Centered Moving Average Smoothing

centeredMovingAverage(integer numberToAverageOver,
      boolean onlyValidValues,
      boolean useReduced)

Derive a new time series from the centered moving average of numberToAverageOver values in the current time series. numberToAverageOver must be an odd integer greater than 2.

If onlyValidValues is set to true, then if any points in the averaging interval are missing, the point in the new time series is set to missing.  If onlyValidValues is set to false and missing values are contained in the averaging interval, a smoothed point is still computed using the remaining valid values in the interval.  If there are no valid values in the averaging interval, the point is set to missing.

If useReduced is set to true, then centered moving average points can still be computed at the beginning and end of the time series, even if there are less than numberToAverageOver values in the averaging interval.  If useReduced is set to false, then the first and last numberToAverageOver/2 points of the resultant time series are set to missing.

Parameters:

numberToAverageOver – An integer containing the number of values to average over for computing the centered moving average. Must be odd and greater than 2.

onlyValidValues – Either Constants.TRUE, or Constants.FALSE, specifying whether all values in the averaging interval must be valid for the computed point in the new time series to be valid.

useReduced – Either Constants.TRUE, or Constants.FALSE, specifying whether  to allow points at the beginning and end of the resultant time series to be computed from a reduced ( less than numberToAverageOver ) set of points.

Example:

avgData = tsData.centeredMovingAverage (5,

Constants.TRUE,

Constants.TRUE)

Returns: A new TimeSeriesMath object

Generated Exceptions: Throws a HecMathException if the numberToAverageOver is less than 3 or not odd.