1. Home
  2. TFILTER directive

TFILTER directive

Filters time series by time-series models.

Option

PRINT = string tokens What to print (series); default *

Parameters

OLDSERIES = variates Time series to be filtered
NEWSERIES = variates To save filtered series
FILTER = TSMs Models to filter with respect to
ARIMA = TSMs ARIMA models for time series

Description

Filtering is a means of processing a time series in order to produce a new series. The purpose is usually to reveal some features and remove other features of the original series. Filters in Genstat are one-sided: that is, each value in the new series depends only on present and past values of the original series. However, you can do two-sided filtering by using the SHIFT and REVERSE functions of CALCULATE.

TFILTER was originally called FILTER, but was renamed in Release 14 to emphasize its status as a time-series command. The earlier name (FILTER) was retained to allow previous programs to continue to run, but this may be removed in a future release.

The OLDSERIES and NEWSERIES parameters of TFILTER specify respectively the time series to be filtered, and the series that result from filtering. A new series must not have the same identifier as the series from which it was calculated. Genstat interprets any missing values in the old series as zero. But if you use the ARIMA parameter (see below), Genstat replaces them by interpolated values when it calculates the filtered series; the missing values remain in the old series.

The FILTER parameter specifies the TSMs to be used for filtering. If the TSM is a transfer-function model, the new series yt is calculated from the old series xt by

yt = { ω(B)Bb / δ(B)∇d } xt.

The filter does not use the power transformation nor the reference constant. This lets you apply a single filter conveniently to a set of time series, for which different transformations and different constants might be appropriate. You can always use the CALCULATE directive to apply a transformation to a series before using TFILTER.

If the TSM is an ARIMA model, then the new series at is calculated from the old series yt by

at = { φ(B)∇d / θ(B)} yt.

Note that the TSM does not have to be the model appropriate for yt. Again, Genstat ignores the parameters λ, c and σa2; you can set them to 1,0,0, for example.

The ARIMA parameter specifies a time-series model for the old series. The purpose is to reduce transient errors that arise in the early part of the new series: these arise because Genstat does not know the values of the old series that came before those that have been supplied. If you do not use this parameter, then Genstat takes these earlier values to be zero. This can cause unacceptable transients which can only be partially removed by procedures such as mean-correcting the old series. If you do use the ARIMA parameter, then Genstat uses the specified model to estimate (or back-forecast) the values of the old series earlier than those that have been supplied.

You do not have to have a good ARIMA model for the old series in order to achieve worthwhile reductions in the transients. Thus a model with orders (0,1,1) and parameters (1,0,0,0.7) would estimate the prior values to be constant, at a level that is a backward EWMA of the early values of the series.

For a seasonal monthly time series, an appropriate ARIMA model could have orders (0,1,1,0,1,1,12) and parameters (1,0,0,0.7,0.7). However you must give the supplied model a transformation parameter λ=1. Any other value for λ breaks the assumption of linearity that underlies the calculations for correcting the transients. The constant term in the ARIMA model can be non-zero, and should be if that is appropriate for the old series. Note that the ARIMA model does not define the filter.

If you specify the ARIMA parameter, Genstat uses this model to interpolate any missing values in the old series before it calculates the new series. Suppose for example that the filter is the identity, defined by a transfer-function model with orders (0,0,0,0) and parameters (1,0,0); then the new series will be the old series with any missing values replaced.

Option: PRINT.

Parameters: OLDSERIES, NEWSERIES, FILTER, ARIMA.

Action with RESTRICT

The OLDSERIES variate can be restricted, but this must be to a contiguous set of units.

See also

Directives: TSM, FTSM, TDISPLAY, TFIT, TFORECAST, TKEEP, TRANSFERFUNCTION, TSUMMARIZE, CORRELATE, FOURIER.

Procedures: BJESTIMATE, BJFORECAST, BJIDENTIFY.

Commands for: Time series.

Example

" Examples 2:7.6, 2:7.6.1a. 2:7.6.1b "
" Smoothing a series of Central England Temperatures using an
  exponentially weighted filter: data from Manley, G. (1974),
  Central England temperatures: monthly means 1659-1973,
  Quart.J.Met.Soc., 100, 378-405. To illustrate the end-effect
  problems of filtering a subset of the data is used."
VARIATE   [NVALUES=315] Cetave
OPEN      '%GENDIR%/Examples/GuidePart2/Cetave.dat'; 3
READ      [CHANNEL=3] Cetave
CLOSE     3
VARIATE   [VALUES=36...235] Time
CALCULATE Cetemp = Cetave$[Time]
&         Tmean = MEAN(Cetemp)
&         Mcetemp = Cetemp-Tmean
TSM       [MODELTYPE=transfer] Ewma; ORDERS=!(0,1,0,0);\
          PARAMETERS=!(1,0,0.8,0.2)
TFILTER   Mcetemp; NEWSERIES=Smtemp; FILTER=Ewma
CALCULATE Smtemp = Smtemp+Tmean
FRAME     1; YLOWER=0.2; YUPPER=0.9; XLOWER=0; XUPPER=1
PEN       1,2; METHOD=line; LINE=0,1; SYMBOL=0; COLOUR='green','black';\
          THICKNESS=0.5,2.0
DGRAPH    [TITLE='Smoothed Temperatures'] Cetemp,Smtemp; Time; PEN=1,2
" Filter the temperatures using an ARIMA model to reduce the transients"
TSM       Back; ORDERS=!(0,1,1); PARAMETERS=!(1,0,0,0.7)
TFILTER   Cetemp; NEWSERIES=TCSmtemp; FILTER=Ewma; ARIMA=Back
PEN       3; METHOD=line; LINE=2; SYMB=0; COLOUR='black'; THICKNESS=2
DGRAPH    [TITLE='Smoothed Temperatures: using ARIMA errors']\ 
          Cetemp,Smtemp,TCSmtemp; Time; PEN=1,3,2
" Carry out two-sided filtering by applying the filter to the
  smoothed series in reverse."
CALCULATE Rsmtemp = REVERSE(TCSmtemp)
&         Back[2]$[4] = 0
TFILTER   Rsmtemp; NEWSERIES=Dsmtemp; FILTER=Ewma; ARIMA=Back
CALCULATE Dsmtemp = REVERSE(Dsmtemp)
DGRAPH    [TITLE='Smoothed Temperatures: two-sided filtering']\
          Cetemp,Dsmtemp; Time; PEN=1,2
Updated on March 5, 2019

Was this article helpful?