Skip to contents

Filter time series with a periodic arma filter. If whiten is FALSE (default) the function applies the given ARMA filter to eps (eps is often periodic white noise). If whiten is TRUE the function applies the “inverse filter” to \(x\), effectively computing residuals.

Usage

pc.filter(model, x, eps, seasonof1st = 1, from = NA, whiten = FALSE,
          nmean = NULL, nintercept = NULL)

Arguments

x

the time series to be filtered, a vector.

eps

residuals, a vector or NULL.

model

the model parameters, a list with components "phi", "theta", "p", "q", "period", "mean" and "intercept", see Details.

seasonof1st

the season of the first observation (i.e., of x[1]).

from

the index from which to start filtering.

whiten

if TRUE use x as input and apply the inverse filter to produce eps ("whiten" x), if FALSE use eps as input and generate x ("colour" eps).

nmean

a vector of means having the length of the series, see Details.

nintercept

a vector of intercepts having the length of the series, see details.

Details

The model is specified by argument model, which is a list with the following components:

phi

the autoregression parameters,

theta

the moving average parameters,

p

the autoregression orders, a single number or a vector with one element for each season,

q

the moving average orders, a single number or a vector with one element for each season,

period

number of seasons in a cycle,

mean

means of the seasons,

intercept

intercepts of the seasons.

The relation between x and eps is assumed to be the following. Let $$y_t = x_t - mu_t$$ be the mean corrected series, where \(mu_t\) is the mean, see below. The equation relating the mean corrected series, \(y_t=x_t - \mu_t\), and eps is the following: $$ y_t = c_t + \sum_{i=1}^{p_t} \phi _t(i)y _{t-i} + \sum_{i=1}^{q_t} \theta_t(i)\varepsilon_{t-i} + \varepsilon_t $$ where \(c_t\) is the intercept, nintercept. The inverse filter is obtained by writing this as an equation expressing \(\varepsilon_t\) through the remaining quantities.

If whiten = TRUE, pc.filter uses the above formula to compute the filtered values of x for t=from,...,n, i.e. whitening the time series if eps is white noise. If whiten = FALSE, eps is computed, i.e. the inverse filter is applied x from eps, i.e. ``colouring'' x. In both cases the first few values in x and/or eps are used as initial values.

Essentially, the mean is subtracted from the series to obtain the mean-corrected series, say y. Then either y is filtered to obtain eps or the inverse filter is applied to obtain y from eps finally the mean is added back to y and the result returned.

The mean is formed by model$mean and argument nmean. If model$mean is supplied it is recycled periodically to the length of the series x and subtracted from x. If argument nmean is supplied, it is subtracted from x. If both model$mean and nmean are supplied their sum is subtracted from x.

The above gives a vector y, \(y_t=x_t - \mu_t\), which is then filtered. If the mean is zero, \(y_t=x_t\) in the formulas below.

Finally, the mean is added back, \(x_t=y_t+\mu_t\), and the new x is returned.

The above gives a vector y which is used in the filtering. If the mean is zero, \(y_t=x_t\) in the formulae below.

pc.filter can be used to simulate pc-arma series with the default value of whiten=FALSE. In this case eps is the input series and y the output. $$ y_t = c_t + \sum_{i=1}^{p_t} \phi _t(i)y _{t-i} + \sum_{i=1}^{q_t} \theta_t(i)\varepsilon_{t-i} + \varepsilon_t $$ Then model$mean or nmean are added to y to form the output vector x.

Residuals corresponding to a series y can be obtained by setting whiten=TRUE. In this case y is the input series. The elements of the output vector eps are calculated by the formula: $$ \varepsilon_t = - c_t - \sum_{i=1}^{q_t} \theta_t(i)\varepsilon_{t-i} - \sum_{i=1}^{p_t} \phi _t(i)y _{t-i} + y_t $$ There is no need in this case to restore x since eps is returned.

In both cases any necessary initial values are assumed to be already in the vectors. If from is not supplied it is chosen as the smallest i such that for all \(t\ge i\), t-p[t]>0 and t-q[t]>0, i.e. the filter will not require negative indices for x or eps.

pc.filter calls the lower level function pc.filter.xarma to do the computation.

Value

The filtered series: the modified x if whiten=FALSE, the modified eps if whiten=TRUE.

Author

Georgi N. Boshnakov

Level

1

See also

the lower level functions pc.filter.xarma which do the computations