nag_tsa_multi_inp_model_forecast (g13bjc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_tsa_multi_inp_model_forecast (g13bjc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_tsa_multi_inp_model_forecast (g13bjc) produces forecasts of a time series (the output series) which may depend on one or more other (input) series via a previously estimated multi-input model. The future values of any input series must be supplied. Standard errors of the forecasts are produced. If future values of some of the input series have been obtained as forecasts using ARIMA models for those series, this may be allowed for in the calculation of the standard errors.

2  Specification

#include <nag.h>
#include <nagg13.h>
void  nag_tsa_multi_inp_model_forecast (Nag_ArimaOrder *arimav, Integer nseries, Nag_TransfOrder *transfv, double para[], Integer npara, Integer nev, Integer nfv, const double xxy[], Integer tdxxy, double rmsxy[], const Integer mrx[], Integer tdmrx, const double parx[], Integer ldparx, Integer tdparx, double fva[], double fsd[], Nag_G13_Opt *options, NagError *fail)

3  Description

nag_tsa_multi_inp_model_forecast (g13bjc) has two stages. The first stage is essentially the same as a call to the model estimation function nag_tsa_multi_inp_model_estim (g13bec), with zero iterations. In particular, all the arguments remain unchanged in the supplied input series transfer function models and output noise series ARIMA model except that a further iteration takes place for any ω  corresponding to a simple input. The internal nuisance arguments associated with the pre-observation period effects of the input series are estimated where requested, and so are any backforecasts of the output noise series. The output components z t  and n t , and residuals a t  are calculated exactly as described in the Section 3 of nag_tsa_multi_inp_model_estim (g13bec).
In the second stage, the forecasts of the output series y t  are calculated for t = n + 1 , n + 2 , , n + L  where n  is the latest time point of the observations and L  is the maximum lead time of the forecasts.
First the new values, x t  for any input series are used to form the input components z t  for t = n + 1 , n + 2 , , n + L  using the transfer function models:
(a) z t = δ 1 z t-1 + δ 2 z t-2 + + δ p z t-p + ω 0 x t-b - ω 1 x t-b - 1 - - ω q x t - b - q .
The output noise component n t  for t = n + 1 , n + 2 , , n + L  is then forecast by setting a t = 0  for t = n + 1 , n + 2 , , n + L  and using the ARIMA model equations:
(b) e t = ϕ 1 e t-1 + ϕ 2 e t-2 + + ϕ p e t-p + a t - θ 1 a t-1 - θ 2 a t-2 - - θ q a t-q .
(c) w t = Φ 1 w t-s + Φ 2 w t - 2 × s + + Φ P w t-P × s + e t - Θ 1 e t-s - Θ 2 e t - 2 × s - - Θ Q e t-Q × s .
(d) n t = d s D -1 w t + c .
This last step of ‘integration’ reverses the process of differencing. Finally the output forecasts are calculated as
y t = z 1,t + z 2,t + + z m,t + n t .
The forecast error variance of y t+l  (i.e., at lead time l ) is S l 2 , which is the sum of parts which arise from the various input series, and the output noise component. That part due to the output noise is
sn l 2 = V n × ψ 0 2 + ψ 1 2 + + ψ l-1 2
V n  is the estimated residual variance of the output noise ARIMA model, and ψ 0 , ψ 1 , , are the ‘psi-weights’ of this model as defined in Box and Jenkins (1976). They are calculated by applying the equations (b), (c) and (d) above for t = 0 , 1 , , L , but with artificial values for the various series and with the constant c  set to 0. Thus all values of a t , e t , w t  and n t  are taken as zero for t<0 ; a t  is taken to be 1 for t=0  and 0 for t>0 . The resulting values of n t  for t = 0 , 1 , , L  are precisely ψ 0 , ψ 1 , , ψ L  as required.
Further contributions to S l 2  come only from those input series, for which future values are forecasts which have been obtained by applying input series ARIMA models. For such a series the contribution is
sz l 2 = V x × ν 0 2 + ν 1 2 + + ν l-1 2
V x  is the estimated residual variance of the input series ARIMA model. The coefficients ν 0 , ν 1 ,  are calculated by applying the transfer function model equation (a) above for t = 0 , 1 , , L , but again with artificial values of the series. Thus all values of z t  and x t  for t<0  are taken to be zero, and x 0 , x 1 ,  are taken to be the psi-weight sequence ψ 0 , ψ 1 ,  for the input series ARIMA model. The resulting values of z t  for t = 0 , 1 , , L  are precisely ν 0 , ν 1 , , ν L  as required.
In adding such contributions sz l 2  to sn l 2  to make up the total forecast error variance S l 2 , it is assumed that the various input series with which these contributions are associated, are statistically independent of each other.
When using the function in practice an ARIMA model is required for all the input series. In the case of those inputs for which no such ARIMA model is available (or its effects are to be excluded), the corresponding orders and arguments and the estimated residual variance should be set to zero.

4  References

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

5  Arguments

1:     arimavNag_ArimaOrder *
Pointer to structure of type Nag_ArimaOrder with the following members:
pInteger
dIntegerInput
qIntegerInput
bigpIntegerInput
bigdIntegerInput
bigqIntegerInput
sIntegerInput
On entry: these seven members of arimav must specify the orders vector p,d,q,P,D,Q,s , respectively, of the ARIMA model for the output noise component.
p , q , P  and Q  refer, respectively, to the number of autoregressive ϕ , moving average θ , seasonal autoregressive Φ  and seasonal moving average Θ  arguments.
d , D  and s  refer, respectively, to the order of non-seasonal differencing, the order of seasonal differencing and the seasonal period.
Constraints:
  • p, d, q, P, D, Q, s0;
  • p+q+P+Q>0;
  • s1;
  • if s=0, P+D+Q=0;
  • if s>1, P+D+Q>0;
  • d+s×P+Dn;
  • p+d-q+s×P+D-Qn.
2:     nseriesIntegerInput
On entry: the number of input and output series. There may be any number of input series (including none), but only one output series.
Constraint: nseries>1  if there are no arguments in the model (that is p = q = P = Q = 0  and options.cfixed=Nag_TRUE ), nseries1  otherwise.
3:     transfvNag_TransfOrder *
Pointer to structure of type Nag_TransfOrder with the following members:
bInteger *Input
qInteger *Input
pInteger *
rInteger *Input
On entry: before use these member pointers must be allocated memory by calling nag_tsa_transf_orders (g13byc) which allocates nseries-1  elements to each pointer. The memory allocated to these pointers must be given the transfer function model orders b , q  and p  of each of the input series. The order arguments for input series i  are held in the i th element of the allocated memory for each pointer. transfvb[i-1]  holds the value b i , transfvq[i-1]  holds the value q i  and transfvp[i-1]  holds the value p i .
For a simple input, b i = q i = p i = 0 .
transfvr[i-1]  holds the value r i , where r i = 1  for a simple input, and r i = 2  or 3 for a transfer function input.
The choice r i = 3  leads to estimation of the pre-period input effects as nuisance arguments, and r i = 2  suppresses this estimation. This choice may affect the returned forecasts.
When r i = 1 , any nonzero contents of the i th element of the memory of transfvb, transfvq and transfvp are ignored.
Constraint: transfvr[i-1]=1, 2 or 3, for i=1,2,,nseries-1
The memory allocated to the members of transfv must be freed by a call to nag_tsa_trans_free (g13bzc)
4:     para[npara]doubleInput/Output
On entry: estimates of the multi-input model arguments. These are in order firstly the ARIMA model arguments: p  values of ϕ  arguments, q  values of θ  arguments, P  values of Φ  arguments, Q  values of Θ  arguments. These are followed by the transfer function model argument values ω 0 , ω 1 , , ω q 1 , and δ 1 , δ 2 , , δ p 1  for the first of any input series and similarly for each subsequent input series. The final component of para is the value of the constant c .
On exit: the input estimates are unaltered except that any ω  estimates corresponding to a simple input will be undated by a single iteration.
5:     nparaIntegerInput
On entry: the exact number of ϕ , θ , Φ , Θ , ω , δ , c  arguments, so that npara = p + q + P + Q + nseries + p i + q i , the summation being over all the input series. ( c  must be included whether its value was previously estimated or was set fixed.)
6:     nevIntegerInput
On entry: the number of original (undifferenced) values in each of the input and output time-series.
7:     nfvIntegerInput
On entry: the number of forecast values of the output series required.
Constraint: nfv>0 .
8:     xxy[nev+nfv×tdxxy]const doubleInput
Note: the i,jth element of the matrix is stored in xxy[i-1×tdxxy+j-1].
On entry: the columns of xxy must contain in the first nev places, the past values of each of the input and output series, in that order. In the next nfv places, the columns relating to the input series (i.e., columns 0 to nseries-2 ) contain the future values of the input series which are necessary for construction of the forecasts of the output series y .
9:     tdxxyIntegerInput
On entry: the stride separating matrix column elements in the array xxy.
Constraint: tdxxynseries .
10:   rmsxy[nseries]doubleInput/Output
On entry: elements of rmsxy[0]  to rmsxy[nseries-2]  must contain the estimated residual variance of the input series ARIMA models. In the case of those inputs for which no ARIMA model is available or its effects are to be excluded in the calculation of forecast standard errors, the corresponding entry of rmsxy should be set to 0.
On exit: rmsxy[nseries-1]  contains the estimated residual variance of the output noise ARIMA model which is calculated from the supplied series. Otherwise rmsxy is unchanged.
11:   mrx[7×tdmrx]const IntegerInput
On entry: the orders array for each of the input series ARIMA models. Thus, column i-1  contains values of p , d , q , P , D , Q , s  for input series i . In the case of those inputs for which no ARIMA model is available, the corresponding orders should be set to 0.
If there are no input series then NULL may be supplied in place of mrx.
12:   tdmrxIntegerInput
On entry: the stride separating matrix column elements in the array mrx.
Constraint: tdmrx nseries - 1 .
13:   parx[ldparx×tdparx]const doubleInput
Note: the i,jth element of the matrix is stored in parx[i-1×tdparx+j-1].
On entry: values of the arguments ( ϕ , θ , Φ , and Θ ) for each of the input series ARIMA models. Thus column i  contains mrx[i]  values of ϕ , mrx[2×tdmrx+i]  values of θ , mrx[3×tdmrx+i]  values of Φ  and mrx[5×tdmrx+i]  values of Θ  – in that order.
Values in the columns relating to those input series for which no ARIMA model is available are ignored.
If there are no input series then NULL may be supplied in place of parx.
14:   ldparxIntegerInput
On entry: the maximum number of arguments in any of the input series ARIMA models. If there are no input series then ldparx is not referenced.
Constraint: ldparx nce = max1, mrx[i] + mrx[2×tdmrx+i] + mrx[3×tdmrx+i] + mrx[5×tdmrx+i] , for i=0,1,,nseries-1.
15:   tdparxIntegerInput
On entry: the stride separating matrix column elements in the array parx.
Constraint: tdparx nseries - 1 .
16:   fva[nfv]doubleOutput
On exit: the required forecast values for the output series.
17:   fsd[nfv]doubleOutput
On exit: the standard errors for each of the forecast values.
18:   optionsNag_G13_Opt *Input/Output
On entry/exit: a pointer to a structure of type Nag_G13_Opt whose members are optional arguments for nag_tsa_multi_inp_model_forecast (g13bjc). If the optional arguments are not required, then the null pointer, G13_DEFAULT, can be used in the function call tonag_tsa_multi_inp_model_forecast (g13bjc). Details of the optional arguments and their types are given below in Section 11.
19:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ldparx=value  while nce = value. These arguments must satisfy ldparx nce . (See the expression for nce  in Section 5 where ldparx is described).
On entry, tdmrx=value  while nseries - 1 = value. These arguments must satisfy tdmrx nseries - 1 .
On entry, tdparx=value  while nseries - 1 = value. These arguments must satisfy tdparx nseries - 1 .
On entry, tdxxy=value  while nseries=value . These arguments must satisfy tdxxynseries .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_ARIMA_TEST_FAILED
On entry, or during execution, one or more sets of the ARIMA ( ϕ , θ , Φ  or Θ ) arguments do not satisfy the stationarity or invertibility test conditions.
NE_BAD_PARAM
On entry, argument options.cfixed had an illegal value.
NE_CONSTRAINT
General constraint: value.
NE_DELTA_TEST_FAILED
On entry, or during execution, one or more sets of δ  arguments do not satisfy the stationarity or invertibility test conditions.
NE_G13_OPTIONS_NOT_INIT
On entry, the option structure, options, has not been initialized using nag_tsa_options_init (g13bxc).
NE_G13_ORDERS_NOT_INIT
On entry, the orders array structure transfv in function nag_tsa_transf_orders (g13byc) has not been initialized.
NE_INT_ARG_LE
On entry, nfv=value.
Constraint: nfv>0.
NE_INT_ARG_LT
On entry, nseries=value.
Constraint: nseries1.
NE_INT_ARRAY_2
Value value given to transfvr[value]  not valid. Correct range for elements if transfvr is 1 transfvr[i] 3 .
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_INVALID_NSER
On entry, nseries=1  and there are no arguments in the model, i.e., ( p = q = P = Q = 0  and options.cfixed=Nag_TRUE ).
NE_MAT_NOT_POS_DEF
Attempt to invert the second derivative matrix needed in the calculation of the covariance matrix of the parameter estimates has failed. The matrix is not positive definite, possibly due to rounding errors.
NE_NPARA_MR_MT_INCONSIST
On entry, there is inconsistency between npara on the one hand and the elements in the orders structures, arimav and transfv on the other.
NE_NSER_INCONSIST
Value of nseries passed to nag_tsa_transf_orders (g13byc) was value which is not equal to the value value passed in this function.
NE_SOLUTION_FAIL_CONV
Iterative refinement has failed to improve the solution of the equations giving the latest estimates of the arguments. This occurred because the matrix of the set of equations is too ill-conditioned.

7  Accuracy

The computation used is believed to be stable.

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by nag_tsa_multi_inp_model_forecast (g13bjc) is approximately proportional to the product of the length of each series and the square of the number of arguments in the multi-input model.

10  Example

The data in this example relate to 40 observations of an output time series and 5 input time series. This example differs from Section 10 in nag_tsa_multi_inp_model_estim (g13bec) in nag_tsa_multi_inp_model_estim (g13bec) in that there are now 4 simple input series. The output series has one autoregressive ϕ  argument and one seasonal moving average Θ  argument. The seasonal period is 4. The transfer function input (the fifth in the set) is defined by orders b 5 = 1 , q 5 = 0 , p 5 = 1 , r 5 = 3 , so that it allows for pre-observation period effects. The initial values of the specified model are:
ϕ = 0.495 , ​ Θ = 0.238 , ω 1 = -0.367 ω2 = -3.876 ω 3 = 4.516 ω 4 = 2.474 ω 5 = 8.629 δ 1 = 0.688 , ​ c = -82.858 .
A further eight values of the input series are supplied, and it is assumed that the values for the fifth series have themselves been forecast from an ARIMA model with orders 2 0 2 0 1 1 4, in which ϕ 1 = 1.6743 , ϕ 2 = -0.9505 , θ 1 = 1.4605 , θ 2 = -0.4862  and Θ 1 = 0.8993 , and for which the residual mean square is 0.1720.
The following are computed and printed out: the estimated residual variance for the output noise series, the eight forecast values and their standard errors, and the values of the components z t  and the output noise component n t .

10.1  Program Text

Program Text (g13bjce.c)

10.2  Program Data

Program Data (g13bjce.d)

10.3  Program Results

Program Results (g13bjce.r)

11  Optional Arguments

A number of optional input and output arguments to nag_tsa_multi_inp_model_forecast (g13bjc) are available through the structure argument options of type Nag_G13_Opt. An argument may be selected by assigning an appropriate value to the relevant structure member and those arguments not selected will be assigned default values. If no use is to be made of any of the optional arguments you should use the null pointer, G13_DEFAULT, in place of options when calling nag_tsa_multi_inp_model_forecast (g13bjc); the default settings will then be used for all arguments.
Before assigning values to options the structure must be initialized by a call to the function nag_tsa_options_init (g13bxc). Values may then be assigned directly to the structure members in the normal C manner.
Options selected by direct assignment are checked within nag_tsa_multi_inp_model_forecast (g13bjc) for being within the required range, if outside the range, an error message is generated.
When all calls to nag_tsa_multi_inp_model_forecast (g13bjc) have been completed and the results contained in the options structure are no longer required; then nag_tsa_free (g13xzc) should be called to free the NAG allocated memory from options.

11.1  Optional Arguments Checklist and Default Values

For easy reference, the following list shows the input and output members of options which are valid for nag_tsa_multi_inp_model_forecast (g13bjc) together with their default values where relevant.
Boolean list Nag_TRUE
Boolean cfixed Nag_FALSE
double *zt
double *noise

11.2  Description of the Optional Arguments

List – Nag_BooleanDefault =Nag_TRUE
On entry: if options.List=Nag_TRUE  then the argument settings which are used in the call to nag_tsa_multi_inp_model_forecast (g13bjc) will be printed.
cfixed – Nag_BooleanDefault =Nag_FALSE
On entry: options.cfixed must be set to Nag_FALSE if the constant was estimated when the model was fitted, and Nag_TRUE if it was held at a fixed value. This only affects the degrees of freedom used in calculating the estimated residual variance.
zt – double *Default memory = nev+nfv × nseries-1
On exit: this pointer is allocated memory internally with nev+nfv × nseries-1  elements corresponding to nev+nfv  rows by nseries-1  columns. The columns of options.zt hold the values of the input component series z t .
noise – double *Default memory = nev + nfv
On exit: this pointer is allocated memory internally with nev+nfv  elements. It holds the output noise component n t .

nag_tsa_multi_inp_model_forecast (g13bjc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2014