filter                 package:stats                 R Documentation

_L_i_n_e_a_r _F_i_l_t_e_r_i_n_g _o_n _a _T_i_m_e _S_e_r_i_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Applies linear filtering to a univariate time series or to each
     series separately of a multivariate time series.

_U_s_a_g_e:

     filter(x, filter, method = c("convolution", "recursive"),
            sides = 2, circular = FALSE, init)

_A_r_g_u_m_e_n_t_s:

       x: a univariate or multivariate time series.

  filter: a vector of filter coefficients in reverse time order (as for
          AR or MA coefficients).

  method: Either '"convolution"' or '"recursive"' (and can be
          abbreviated). If '"convolution"' a moving average is used: if
          '"recursive"' an autoregression is used.

   sides: for convolution filters only. If 'sides=1' the filter
          coefficients are for past values only; if 'sides=2' they are
          centred around lag 0. In this case the length of the filter
          should be odd, but if it is even, more of the filter is
          forward in time than backward.

circular: for convolution filters only.  If 'TRUE', wrap the filter
          around the ends of the series, otherwise assume external
          values are missing ('NA').

    init: for recursive filters only. Specifies the initial values of
          the time series just prior to the start value, in reverse
          time order. The default is a set of zeros.

_D_e_t_a_i_l_s:

     Missing values are allowed in 'x' but not in 'filter' (where they
     would lead to missing values everywhere in the output).

     Note that there is an implied coefficient 1 at lag 0 in the
     recursive filter, which gives

           'y[i] = x[i] + f[1]*y[i-1] + ... + f[p]*y[i-p]'

     No check is made to see if recursive filter is invertible: the
     output may diverge if it is not.

     The convolution filter is

             'y[i] = f[1]*x[i+o] + ... + f[p]*x[i+o-p-1]'


     where 'o' is the offset: see 'sides' for how it is determined.

_V_a_l_u_e:

     A time series object.

_N_o_t_e:

     'convolve(, type="filter")' uses the FFT for computations and so
     _may_ be faster for long filters on univariate series, but it does
     not return a time series (and so the  time alignment is unclear),
     nor does it handle missing values.  'filter' is faster for a
     filter of length 100 on a series of length 1000, for example.

_S_e_e _A_l_s_o:

     'convolve', 'arima.sim'

_E_x_a_m_p_l_e_s:

     x <- 1:100
     filter(x, rep(1, 3))
     filter(x, rep(1, 3), sides = 1)
     filter(x, rep(1, 3), sides = 1, circular = TRUE)
     data(presidents)
     filter(presidents, rep(1,3))

