G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG13BBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G13BBF filters a time series by a transfer function model.

## 2  Specification

 SUBROUTINE G13BBF ( Y, NY, MR, NMR, PAR, NPAR, CY, WA, IWA, B, NB, IFAIL)
 INTEGER NY, MR(NMR), NMR, NPAR, IWA, NB, IFAIL REAL (KIND=nag_wp) Y(NY), PAR(NPAR), CY, WA(IWA), B(NB)

## 3  Description

From a given series ${y}_{1},{y}_{2},\dots ,{y}_{n}$ a new series ${b}_{1},{b}_{2},\dots ,{b}_{n}$ is calculated using a supplied (filtering) transfer function model according to the equation
 $bt=δ1bt-1+δ2bt-2+⋯+δpbt-p+ω0yt-b-ω1yt-b-1-⋯-ωqyt-b-q.$ (1)
As in the use of G13BAF, large transient errors may arise in the early values of ${b}_{t}$ due to ignorance of ${y}_{t}$ for $t<0$, and two possibilities are allowed.
 (i) The equation (1) is applied from $t=1+b+q,\dots ,n$ so all terms in ${y}_{t}$ on the right-hand side of (1) are known, the unknown set of values ${b}_{t}$ for $t=b+q,\dots ,b+q+1-p$ being taken as zero. (ii) The unknown values of ${y}_{t}$ for $t\le 0$ are estimated by backforecasting exactly as for G13BAF.
Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day

## 5  Parameters

1:     Y(NY) – REAL (KIND=nag_wp) arrayInput
On entry: the ${Q}_{y}^{\prime }$ backforecasts starting with backforecast at time $1-{Q}_{y}^{\prime }$ to backforecast at time $0$ followed by the time series starting at time $1$, where ${Q}_{y}^{\prime }={\mathbf{MR}}\left(6\right)+{\mathbf{MR}}\left(9\right)×{\mathbf{MR}}\left(10\right)$. If there are no backforecasts either because the ARIMA model for the time series is not known or because it is known but has no moving average terms, then the time series starts at the beginning of Y.
2:     NY – INTEGERInput
On entry: the total number of backforecasts and time series data points in array Y.
Constraint: ${\mathbf{NY}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1+{Q}_{y}^{\prime },{\mathbf{NPAR}}\right)$.
3:     MR(NMR) – INTEGER arrayInput
On entry: the orders vector for the filtering transfer function model followed by the orders vector for the ARIMA model for the time series if the latter is known. The transfer function model orders appear in the standard form $\left(b,q,p\right)$ as given in the G13 Chapter Introduction. Note that if the ARIMA model for the time series is supplied then the routine will assume that the first ${Q}_{y}^{\prime }$ values of the array Y are backforecasts.
Constraints:
the filtering model is restricted in the following way:
• ${\mathbf{MR}}\left(1\right)\text{, ​}{\mathbf{MR}}\left(2\right)\text{, ​}{\mathbf{MR}}\left(3\right)\ge 0$.
the ARIMA model for the time series is restricted in the following ways:
• ${\mathbf{MR}}\left(\mathit{k}\right)\ge 0$, for $\mathit{k}=4,5,\dots ,10$;
• if ${\mathbf{MR}}\left(10\right)=0$, ${\mathbf{MR}}\left(7\right)+{\mathbf{MR}}\left(8\right)+{\mathbf{MR}}\left(9\right)=0$;
• if ${\mathbf{MR}}\left(10\right)\ne 0$, ${\mathbf{MR}}\left(7\right)+{\mathbf{MR}}\left(8\right)+{\mathbf{MR}}\left(9\right)\ne 0$;
• ${\mathbf{MR}}\left(10\right)\ne 1$.
4:     NMR – INTEGERInput
On entry: the number of values supplied in the array MR. It takes the value $3$ if no ARIMA model for the time series is supplied but otherwise it takes the value $10$. Thus NMR acts as an indicator as to whether backforecasting can be carried out.
Constraint: ${\mathbf{NMR}}=3$ or $10$.
5:     PAR(NPAR) – REAL (KIND=nag_wp) arrayInput
On entry: the parameters of the filtering transfer function model followed by the parameters of the ARIMA model for the time series. In the transfer function model the parameters are in the standard order of MA-like followed by AR-like operator parameters. In the ARIMA model the parameters are in the standard order of non-seasonal AR and MA followed by seasonal AR and MA.
6:     NPAR – INTEGERInput
On entry: the total number of parameters held in array PAR.
Constraints:
• if ${\mathbf{NMR}}=3$, ${\mathbf{NPAR}}={\mathbf{MR}}\left(2\right)+{\mathbf{MR}}\left(3\right)+1$;
• if ${\mathbf{NMR}}=10$, ${\mathbf{NPAR}}={\mathbf{MR}}\left(2\right)+{\mathbf{MR}}\left(3\right)+1+{\mathbf{MR}}\left(4\right)+{\mathbf{MR}}\left(6\right)+{\mathbf{MR}}\left(7\right)+{\mathbf{MR}}\left(9\right)$.
7:     CY – REAL (KIND=nag_wp)Input
On entry: if the ARIMA model is known (i.e., ${\mathbf{NMR}}=10$), CY must specify the constant term of the ARIMA model for the time series. If this model is not known (i.e., ${\mathbf{NMR}}=3$) then CY is not used.
8:     WA(IWA) – REAL (KIND=nag_wp) arrayWorkspace
9:     IWA – INTEGERInput
On entry: the dimension of the array WA as declared in the (sub)program from which G13BBF is called.
Constraints:
let $K={\mathbf{MR}}\left(3\right)+{\mathbf{MR}}\left(4\right)+{\mathbf{MR}}\left(5\right)+\left({\mathbf{MR}}\left(7\right)+{\mathbf{MR}}\left(8\right)\right)×{\mathbf{MR}}\left(10\right)$,
then
• if ${\mathbf{NMR}}=3$, ${\mathbf{IWA}}\ge {\mathbf{MR}}\left(1\right)+{\mathbf{NPAR}}$;
• if ${\mathbf{NMR}}=10$, ${\mathbf{IWA}}\ge {\mathbf{MR}}\left(1\right)+{\mathbf{NPAR}}+K×\left(K+2\right)$.
10:   B(NB) – REAL (KIND=nag_wp) arrayOutput
On exit: the filtered output series. If the ARIMA model for the time series was known, and hence ${Q}_{y}^{\prime }$ backforecasts were supplied in Y, then B contains ${Q}_{y}^{\prime }$ ‘filtered’ backforecasts followed by the filtered series. Otherwise, the filtered series begins at the start of B just as the original series began at the start of Y. In either case, if the value of the series at time $t$ is held in ${\mathbf{Y}}\left(t\right)$, then the filtered value at time $t$ is held in ${\mathbf{B}}\left(t\right)$.
11:   NB – INTEGERInput
On entry: the dimension of the array B as declared in the (sub)program from which G13BBF is called.
In addition to holding the returned filtered series, B is also used as an intermediate work array if the ARIMA model for the time series is known.
Constraints:
• if ${\mathbf{NMR}}=3$, ${\mathbf{NB}}\ge {\mathbf{NY}}$;
• if ${\mathbf{NMR}}=10$, ${\mathbf{NB}}\ge {\mathbf{NY}}+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{MR}}\left(1\right)+{\mathbf{MR}}\left(2\right),{\mathbf{MR}}\left(3\right)\right)$.
12:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{NMR}}\ne 3$ and ${\mathbf{NMR}}\ne 10$, or ${\mathbf{MR}}\left(\mathit{i}\right)<0$, for $\mathit{i}=1,2,\dots ,{\mathbf{NMR}}$, or ${\mathbf{NMR}}=10$ and ${\mathbf{MR}}\left(10\right)=1$, or ${\mathbf{NMR}}=10$ and ${\mathbf{MR}}\left(10\right)=0$ and ${\mathbf{MR}}\left(7\right)+{\mathbf{MR}}\left(8\right)+{\mathbf{MR}}\left(9\right)\ne 0$, or ${\mathbf{NMR}}=10$ and ${\mathbf{MR}}\left(10\right)\ne 0$, and ${\mathbf{MR}}\left(7\right)+{\mathbf{MR}}\left(8\right)+{\mathbf{MR}}\left(9\right)=0$, or NPAR is inconsistent with the contents of MR, or WA is too small, or B is too small.
${\mathbf{IFAIL}}=2$
A supplied model has parameter values which have failed the validity test.
${\mathbf{IFAIL}}=3$
The supplied time series is too short to carry out the requested filtering successfully.
${\mathbf{IFAIL}}=4$
This only occurs when an ARIMA model for the time series has been supplied. The matrix which is used to solve for the starting values for MA filtering is singular.
${\mathbf{IFAIL}}=-999$
Internal memory allocation failed.

## 7  Accuracy

Accuracy and stability are high except when the AR-like parameters are close to the invertibility boundary. All calculations are performed in basic precision except for one inner product type calculation which on machines of low precision is performed in additional precision.

If an ARIMA model is supplied, a local workspace array of fixed length is allocated internally by G13BBF. The total size of this array amounts to $K$ integer elements, where $K$ is the expression defined in the description of the parameter WA.
The time taken by G13BBF is roughly proportional to the product of the length of the series and number of parameters in the filtering model with appreciable increase if an ARIMA model is supplied for the time series.

## 9  Example

This example reads a time series of length $296$. It reads one univariate ARIMA $\left(1,1,0,0,1,1,12\right)$ model for the series and the $\left(0,13,12\right)$ filtering transfer function model. $12$ initial backforecasts are required and these are calculated by a call to G13AJF . The backforecasts are inserted at the start of the series and G13BBF is called to perform the filtering.

### 9.1  Program Text

Program Text (g13bbfe.f90)

### 9.2  Program Data

Program Data (g13bbfe.d)

### 9.3  Program Results

Program Results (g13bbfe.r)