MOVAVG function

Moving Average

Moving Average

This function returns the moving average of the elements of the input array or the input time series. The result is an object of the same class of the input, and its elements are the moving average of length L of the input values. If the input is a time series, the DIRECTION of the moving average, i.e backward, forward or centered, can be provided. MAVE is an alias for MOVAVG

MOVAVG(x = NULL, L = NULL, DIRECTION = NULL, ignoreNA=FALSE, avoidCompliance = FALSE, ...) MAVE(x = NULL, L = NULL, DIRECTION = NULL, ignoreNA=FALSE, avoidCompliance = FALSE, ...)

Arguments

  • x: Input numerical array or time series that must satisfy the compliance control check defined in is.bimets.

  • L: Length of the mean. Must be a positive integer.

  • DIRECTION: if x is a time series, given y as output and x as input:

    AHEAD : the output observation value in index n will be

    y[n] = mean(x[n],x[n+1],...,x[n+L-1]).

    CENTER : the output observation value in index n will be

    y[n] = mean(x[n-trunc(L/2)],...,x[n],x[n+1],...,x[n+trunc(L/2)]).

    NULL o BACK : (default) the output observation value in index n will be

    y[n] = mean(x[n+1-L],...,x[n-1],x[n]).

  • ignoreNA: Ignore missing values.

  • avoidCompliance: If TRUE, compliance control check of input time series will be skipped. See is.bimets

  • ...: Backward compatibility.

Returns

This function returns an object of the same class of the input, i.e. an array or a BIMETS time series.

See Also

TSDELTA

TSLAG

TSPROJECT

TSEXTEND

TSLEAD

CUMSUM

INDEXNUM

VERIFY_MAGNITUDE

GETRANGE

Examples

#input data inputArray<-c(1,2,3,4,NA,1,2,3,4,5) #array lag 3 out_movavg<-MOVAVG(inputArray,3) print(out_movavg) #ts lag 4 centered with missings ts1<-TSERIES(inputArray,START=c(2000,1),FREQ='A') out_movavg<-MAVE(ts1,4,'CENTER') TABIT(out_movavg) #ts daily ts1<-TSERIES(inputArray,START=c(2000,1),FREQ='D') out_movavg<-MAVE(ts1,3) TABIT(ts1,out_movavg)
  • Maintainer: Andrea Luciani
  • License: GPL-3
  • Last published: 2024-11-25