hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_tsa_multi_filter_arima (g13ba)

Purpose

nag_tsa_multi_filter_arima (g13ba) filters a time series by an ARIMA model.

Syntax

[b, ifail] = g13ba(y, mr, par, cy, nb, 'ny', ny, 'nmr', nmr, 'npar', npar)
[b, ifail] = nag_tsa_multi_filter_arima(y, mr, par, cy, nb, 'ny', ny, 'nmr', nmr, 'npar', npar)

Description

From a given series y1,y2,,yny1,y2,,yn, a new series b1,b2,,bnb1,b2,,bn is calculated using a supplied (filtering) ARIMA model. This model will be one which has previously been fitted to a series xtxt with residuals atat. The equations defining btbt in terms of ytyt are very similar to those by which atat is obtained from xtxt. The only dissimilarity is that no constant correction is applied after differencing. This is because the series ytyt is generally distinct from the series xtxt with which the model is associated, though ytyt may be related to xtxt. Whilst it is appropriate to apply the ARIMA model to ytyt so as to preserve the same relationship between btbt and atat as exists between ytyt and xtxt, the constant term in the ARIMA model is inappropriate for ytyt. The consequence is that btbt will not necessarily have zero mean.
The equations are precisely:
wt = dsDyt,
wt=dsDyt,
(1)
the appropriate differencing of ytyt; both the seasonal and non-seasonal inverted autoregressive operations are then applied,
ut = wtΦ1wtsΦPwts × P
ut=wt-Φ1wt-s--ΦPwt-s×P
(2)
vt = utφ1ut1φputp
vt=ut-ϕ1ut-1--ϕput-p
(3)
followed by the inverted moving average operations
zt = vt + Θ1zts + + ΘQzts × Q
zt=vt+Θ1zt-s++ΘQzt-s×Q
(4)
bt = zt + θ1bt1 + + θqbtq.
bt=zt+θ1bt-1++θqbt-q.
(5)
Because the filtered series value btbt depends on present and past values yt,yt1,yt,yt-1,, there is a problem arising from ignorance of y0,y1,y0,y-1, which particularly affects calculation of the early values b1,b2,b1,b2,, causing ‘transient errors’. The function allows two possibilities.
(i) The equations (1), (2) and (3) are applied from successively later time points so that all terms on their right-hand sides are known, with vtvt being defined for t = (1 + d + s × D + s × P),,nt=(1+d+s×D+s×P),,n. Equations (4) and (5) are then applied over the same range, taking any values on the right-hand side associated with previous time points to be zero.
This procedure may still however result in unacceptably large transient errors in early values of btbt.
(ii) The unknown values y0,y1,y0,y-1, are estimated by backforecasting. This requires that an ARIMA model distinct from that which has been supplied for filtering, should have been previously fitted to ytyt.
For efficiency, you are asked to supply both this ARIMA model for ytyt and a limited number of backforecasts which are prefixed to the known values of ytyt. Within the function further backforecasts of ytyt, and the series wtwt, utut, vtvt in (1), (2) and (3) are then easily calculated, and a set of linear equations solved for backforecasts of zt,btzt,bt for use in (4) and (5) in the case that q + Q > 0q+Q>0.
Even if the best model for ytyt is not available, a very approximate guess such as
yt = c + et
yt=c+et
or
yt = et
yt=et
can help to reduce the transients substantially.
The backforecasts which need to be prefixed to ytyt are of length Qy = qy + sy × QyQy=qy+sy×Qy, where qyqy and QyQy are the non-seasonal and seasonal moving average orders and sysy the seasonal period for the ARIMA model of ytyt. Thus you need not carry out the backforecasting exercise if Qy = 0Qy=0. Otherwise, the series y1,y2,,yny1,y2,,yn should be reversed to obtain yn,yn1,,y1yn,yn-1,,y1 and nag_tsa_uni_arima_forcecast (g13aj) should be used to forecast QyQy values, 0,,1Qyy^0,,y^1-Qy. The ARIMA model used is that fitted to ytyt (as a forward series) except that, if dy + Dydy+Dy is odd, the constant should be changed in sign (to allow, for example, for the fact that a forward upward trend is a reversed downward trend). The ARIMA model for ytyt supplied to the filtering function must however have the appropriate constant for the forward series.
The series 1Qy,,0,y1,,yny^1-Qy,,y^0,y1,,yn is then supplied to the function, and a corresponding set of values returned for btbt.

References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day

Parameters

Compulsory Input Parameters

1:     y(ny) – double array
ny, the dimension of the array, must satisfy the constraint nymax (1 + Qy,npar)nymax(1+Qy,npar).
The QyQy backforecasts, starting with backforecast at time 1Qy1-Qy to backforecast at time 00, followed by the time series starting at time 11, where Qy = mr(10) + mr(13) × mr(14)Qy=mr10+mr13×mr14. 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:     mr(nmr) – int64int32nag_int array
nmr, the dimension of the array, must satisfy the constraint nmr = 7nmr=7 or 1414.
The orders vector for the filtering model, followed by the orders vector for the ARIMA model for the time series if the latter is known. The orders appear in the standard sequence (p,d,q,P,D,Q,s)(p,d,q,P,D,Q,s) as given in the G13 Chapter Introduction. If the ARIMA model for the time series is supplied, then the function will assume that the first QyQy values of the array y are backforecasts.
Constraints:
the filtering model is restricted in the following ways:
  • mr(1) + mr(3) + mr(4) + mr(6) > 0mr1+mr3+mr4+mr6>0, i.e., filtering by a model which contains only differencing terms is not permitted;
  • mr(k)0mrk0, for k = 1,2,,7k=1,2,,7;
  • if mr(7) = 0mr7=0, mr(4) + mr(5) + mr(6) = 0mr4+mr5+mr6=0;
  • if mr(7)0mr70, mr(4) + mr(5) + mr(6)0mr4+mr5+mr60;
  • mr(7)1mr71.
the ARIMA model for the time series is restricted in the following ways:
  • mr(k)0mrk0, for k = 8,9,,14k=8,9,,14;
  • if mr(14) = 0mr14=0, mr(11) + mr(12) + mr(13) = 0mr11+mr12+mr13=0;
  • if mr(14)0mr140, mr(11) + mr(12) + mr(13)0mr11+mr12+mr130;
  • mr(14)1mr141.
3:     par(npar) – double array
npar, the dimension of the array, must satisfy the constraint
  • if nmr = 7nmr=7, npar = mr(1) + mr(3) + mr(4) + mr(6)npar=mr1+mr3+mr4+mr6;
  • if nmr = 14nmr=14, npar = mr(1) + mr(3) + mr(4) + mr(6) +   mr(8) + mr(10) + mr(11) + mr(13)npar=mr1+mr3+mr4+mr6+ mr8+mr10+mr11+mr13.
Note: the first constraint (i.e., mr(1) + mr(3) + mr(4) + mr(6) > 0mr1+mr3+mr4+mr6>0) on the orders of the filtering model, in parameter mr, ensures that npar > 0npar>0.
The parameters of the filtering model, followed by the parameters of the ARIMA model for the time series, if supplied. Within each model the parameters are in the standard order of non-seasonal AR and MA followed by seasonal AR and MA.
4:     cy – double scalar
If the ARIMA model is known (i.e., nmr = 14nmr=14), cy must specify the constant term of the ARIMA model for the time series. If this model is not known (i.e., nmr = 7nmr=7), then cy is not used.
5:     nb – int64int32nag_int scalar
The dimension of the array b as declared in the (sub)program from which nag_tsa_multi_filter_arima (g13ba) 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 was known.
Constraints:
  • if nmr = 14nmr=14, nbny + max (K3,K1 + K2)nbny+max(K3,K1+K2);
  • if nmr = 7nmr=7, nbnynbny.
Where
  • K1 = mr(1) + mr(4) × mr(7)K1=mr1+mr4×mr7;
  • K2 = mr(2) + mr(5) × mr(7)K2=mr2+mr5×mr7;
  • K3 = mr(3) + mr(6) × mr(7)K3=mr3+mr6×mr7.

Optional Input Parameters

1:     ny – int64int32nag_int scalar
Default: The dimension of the array y.
The total number of backforecasts and time series data points in array y.
Constraint: nymax (1 + Qy,npar)nymax(1+Qy,npar).
2:     nmr – int64int32nag_int scalar
Default: The dimension of the array mr.
The number of values specified in the array mr. It takes the value 77 if no ARIMA model for the time series is supplied but otherwise it takes the value 1414. Thus nmr acts as an indicator as to whether backforecasting can be carried out.
Constraint: nmr = 7nmr=7 or 1414.
3:     npar – int64int32nag_int scalar
Default: The dimension of the array par.
The total number of parameters held in array par.
Constraints:
  • if nmr = 7nmr=7, npar = mr(1) + mr(3) + mr(4) + mr(6)npar=mr1+mr3+mr4+mr6;
  • if nmr = 14nmr=14, npar = mr(1) + mr(3) + mr(4) + mr(6) +   mr(8) + mr(10) + mr(11) + mr(13)npar=mr1+mr3+mr4+mr6+ mr8+mr10+mr11+mr13.
Note: the first constraint (i.e., mr(1) + mr(3) + mr(4) + mr(6) > 0mr1+mr3+mr4+mr6>0) on the orders of the filtering model, in parameter mr, ensures that npar > 0npar>0.

Input Parameters Omitted from the MATLAB Interface

wa nwa

Output Parameters

1:     b(nb) – double array
The filtered output series. If the ARIMA model for the time series was known, and hence QyQy backforecasts were supplied in y, then b contains QyQy ‘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 tt is held in y(t)yt, then the filtered value at time tt is held in b(t)bt.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,nmr7nmr7 and nmr14nmr14.
  ifail = 2ifail=2
On entry,the orders vector mr does not satisfy the constraints given in Section [Parameters].
  ifail = 3ifail=3
On entry,npar is inconsistent with the contents of mr (see Section [Parameters]).
  ifail = 4ifail=4
On entry,ny is too small to successfully carry out the requested filtering, (see Section [Parameters]).
  ifail = 5ifail=5
On entry,the work array wa is too small.
  ifail = 6ifail=6
On entry,the array b is too small.
  ifail = 7ifail=7
The orders vector for the filtering model is invalid.
  ifail = 8ifail=8
The orders vector for the ARIMA model is invalid. (Only occurs if nmr = 14nmr=14.)
  ifail = 9ifail=9
The initial values of the filtered series are indeterminate for the given models.
  ifail = 999ifail=-999
Internal memory allocation failed.

Accuracy

Accuracy and stability are high except when the MA parameters are close to the invertibility boundary.

Further Comments

If an ARIMA model is supplied, a local workspace array of fixed length is allocated internally by nag_tsa_multi_filter_arima (g13ba). The total size of this array amounts to KK integer elements, where KK is the expression defined in the description of the parameter wa.
The time taken by nag_tsa_multi_filter_arima (g13ba) is approximately proportional to
ny × (mr(1) + mr(3) + mr(4) + mr(6)),
ny×(mr1+mr3+mr4+mr6),
with an appreciable fixed increase if an ARIMA model is supplied for the time series.

Example

function nag_tsa_multi_filter_arima_example
y = [49.98070870808541;
     52.67136711304528;
     53.8;
     53.6;
     53.5;
     53.5;
     53.4;
     53.1;
     52.7;
     52.4;
     52.2;
     52;
     52;
     52.4;
     53;
     54;
     54.9;
     56;
     56.8;
     56.8;
     56.4;
     55.7;
     55;
     54.3;
     53.2;
     52.3;
     51.6;
     51.2;
     50.8;
     50.5;
     50;
     49.2;
     48.4;
     47.9;
     47.6;
     47.5;
     47.5;
     47.6;
     48.1;
     49;
     50;
     51.1;
     51.8;
     51.9;
     51.7;
     51.2;
     50;
     48.3;
     47;
     45.8;
     45.6;
     46;
     46.9;
     47.8;
     48.2;
     48.3;
     47.9;
     47.2;
     47.2;
     48.1;
     49.4;
     50.6;
     51.5;
     51.6;
     51.2;
     50.5;
     50.1;
     49.8;
     49.6;
     49.4;
     49.3;
     49.2;
     49.3;
     49.7;
     50.3;
     51.3;
     52.8;
     54.4;
     56;
     56.9;
     57.5;
     57.3;
     56.6;
     56;
     55.4;
     55.4;
     56.4;
     57.2;
     58;
     58.4;
     58.4;
     58.1;
     57.7;
     57;
     56;
     54.7;
     53.2;
     52.1;
     51.6;
     51;
     50.5;
     50.4;
     51;
     51.8;
     52.4;
     53;
     53.4;
     53.6;
     53.7;
     53.8;
     53.8;
     53.8;
     53.3;
     53;
     52.9;
     53.4;
     54.6;
     56.4;
     58;
     59.4;
     60.2;
     60;
     59.4;
     58.4;
     57.6;
     56.9;
     56.4;
     56;
     55.7;
     55.3;
     55;
     54.4;
     53.7;
     52.8;
     51.6;
     50.6;
     49.4;
     48.8;
     48.5;
     48.7;
     49.2;
     49.8;
     50.4;
     50.7;
     50.9;
     50.7;
     50.5;
     50.4;
     50.2;
     50.4;
     51.2;
     52.3;
     53.2;
     53.9;
     54.1;
     54;
     53.6;
     53.2;
     53;
     52.8;
     52.3;
     51.9;
     51.6;
     51.6;
     51.4;
     51.2;
     50.7;
     50;
     49.4;
     49.3;
     49.7;
     50.6;
     51.8;
     53;
     54;
     55.3;
     55.9;
     55.9;
     54.6;
     53.5;
     52.4;
     52.1;
     52.3;
     53;
     53.8;
     54.6;
     55.4;
     55.9;
     55.9;
     55.2;
     54.4;
     53.7;
     53.6;
     53.6;
     53.2;
     52.5;
     52;
     51.4;
     51;
     50.9;
     52.4;
     53.5;
     55.6;
     58;
     59.5;
     60;
     60.4;
     60.5;
     60.2;
     59.7;
     59;
     57.6;
     56.4;
     55.2;
     54.5;
     54.1;
     54.1;
     54.4;
     55.5;
     56.2;
     57;
     57.3;
     57.4;
     57;
     56.4;
     55.9;
     55.5;
     55.3;
     55.2;
     55.4;
     56;
     56.5;
     57.1;
     57.3;
     56.8;
     55.6;
     55;
     54.1;
     54.3;
     55.3;
     56.4;
     57.2;
     57.8;
     58.3;
     58.6;
     58.8;
     58.8;
     58.6;
     58;
     57.4;
     57;
     56.4;
     56.3;
     56.4;
     56.4;
     56;
     55.2;
     54;
     53;
     52;
     51.6;
     51.6;
     51.1;
     50.4;
     50;
     50;
     52;
     54;
     55.1;
     54.5;
     52.8;
     51.4;
     50.8;
     51.2;
     52;
     52.8;
     53.8;
     54.5;
     54.9;
     54.9;
     54.8;
     54.4;
     53.7;
     53.3;
     52.8;
     52.6;
     52.6;
     53;
     54.3;
     56;
     57;
     58;
     58.6;
     58.5;
     58.3;
     57.8;
     57.3;
     57];
mr = [int64(3);0;0;0;0;0;0;4;0;2;0;0;0;0];
par = [1.97;
     -1.37;
     0.34;
     2.42;
     -2.38;
     1.16;
     -0.23;
     0.31;
     -0.47];
cy = 0;
nb = int64(301);
[b, ifail] = nag_tsa_multi_filter_arima(y, mr, par, cy, nb);
 ifail
 

ifail =

                    0


function g13ba_example
y = [49.98070870808541;
     52.67136711304528;
     53.8;
     53.6;
     53.5;
     53.5;
     53.4;
     53.1;
     52.7;
     52.4;
     52.2;
     52;
     52;
     52.4;
     53;
     54;
     54.9;
     56;
     56.8;
     56.8;
     56.4;
     55.7;
     55;
     54.3;
     53.2;
     52.3;
     51.6;
     51.2;
     50.8;
     50.5;
     50;
     49.2;
     48.4;
     47.9;
     47.6;
     47.5;
     47.5;
     47.6;
     48.1;
     49;
     50;
     51.1;
     51.8;
     51.9;
     51.7;
     51.2;
     50;
     48.3;
     47;
     45.8;
     45.6;
     46;
     46.9;
     47.8;
     48.2;
     48.3;
     47.9;
     47.2;
     47.2;
     48.1;
     49.4;
     50.6;
     51.5;
     51.6;
     51.2;
     50.5;
     50.1;
     49.8;
     49.6;
     49.4;
     49.3;
     49.2;
     49.3;
     49.7;
     50.3;
     51.3;
     52.8;
     54.4;
     56;
     56.9;
     57.5;
     57.3;
     56.6;
     56;
     55.4;
     55.4;
     56.4;
     57.2;
     58;
     58.4;
     58.4;
     58.1;
     57.7;
     57;
     56;
     54.7;
     53.2;
     52.1;
     51.6;
     51;
     50.5;
     50.4;
     51;
     51.8;
     52.4;
     53;
     53.4;
     53.6;
     53.7;
     53.8;
     53.8;
     53.8;
     53.3;
     53;
     52.9;
     53.4;
     54.6;
     56.4;
     58;
     59.4;
     60.2;
     60;
     59.4;
     58.4;
     57.6;
     56.9;
     56.4;
     56;
     55.7;
     55.3;
     55;
     54.4;
     53.7;
     52.8;
     51.6;
     50.6;
     49.4;
     48.8;
     48.5;
     48.7;
     49.2;
     49.8;
     50.4;
     50.7;
     50.9;
     50.7;
     50.5;
     50.4;
     50.2;
     50.4;
     51.2;
     52.3;
     53.2;
     53.9;
     54.1;
     54;
     53.6;
     53.2;
     53;
     52.8;
     52.3;
     51.9;
     51.6;
     51.6;
     51.4;
     51.2;
     50.7;
     50;
     49.4;
     49.3;
     49.7;
     50.6;
     51.8;
     53;
     54;
     55.3;
     55.9;
     55.9;
     54.6;
     53.5;
     52.4;
     52.1;
     52.3;
     53;
     53.8;
     54.6;
     55.4;
     55.9;
     55.9;
     55.2;
     54.4;
     53.7;
     53.6;
     53.6;
     53.2;
     52.5;
     52;
     51.4;
     51;
     50.9;
     52.4;
     53.5;
     55.6;
     58;
     59.5;
     60;
     60.4;
     60.5;
     60.2;
     59.7;
     59;
     57.6;
     56.4;
     55.2;
     54.5;
     54.1;
     54.1;
     54.4;
     55.5;
     56.2;
     57;
     57.3;
     57.4;
     57;
     56.4;
     55.9;
     55.5;
     55.3;
     55.2;
     55.4;
     56;
     56.5;
     57.1;
     57.3;
     56.8;
     55.6;
     55;
     54.1;
     54.3;
     55.3;
     56.4;
     57.2;
     57.8;
     58.3;
     58.6;
     58.8;
     58.8;
     58.6;
     58;
     57.4;
     57;
     56.4;
     56.3;
     56.4;
     56.4;
     56;
     55.2;
     54;
     53;
     52;
     51.6;
     51.6;
     51.1;
     50.4;
     50;
     50;
     52;
     54;
     55.1;
     54.5;
     52.8;
     51.4;
     50.8;
     51.2;
     52;
     52.8;
     53.8;
     54.5;
     54.9;
     54.9;
     54.8;
     54.4;
     53.7;
     53.3;
     52.8;
     52.6;
     52.6;
     53;
     54.3;
     56;
     57;
     58;
     58.6;
     58.5;
     58.3;
     57.8;
     57.3;
     57];
mr = [int64(3);0;0;0;0;0;0;4;0;2;0;0;0;0];
par = [1.97;
     -1.37;
     0.34;
     2.42;
     -2.38;
     1.16;
     -0.23;
     0.31;
     -0.47];
cy = 0;
nb = int64(301);
[b, ifail] = g13ba(y, mr, par, cy, nb);
 ifail
 

ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013