Chapter 2 software

We list here the MATLAB scripts (programs) used to generate all the figures in Chapter 2, and the MATLAB functions used in the scripts to produce the quantities that are plotted. The scripts and function files can be downloaded from the two zipped files listed at the foot of this page. The text file of the Pig market series is included with the scripts. A third zip file contains a small number of test scripts for some of the functions. Text files of documentation for the functions are included in a fourth zip file.

The auto- and cross-correlations of the illustrative canonical VAR model for the Pig market series shown in Fig. 2.1 are plotted by the script pigsmodelCCF.m which uses the function VARcovfun.m. This script also uses the function PredCoef.m to produce plots for Figs 2.3, 2.4, 2.5 and 2.9 which illustrate properties of autoregressive predictors, and the function VARdet.m to check the stationarity of a model. There is a further function VARcovfunX.m which is identical to VARcovfun.m except in the algorithm used. Descriptions of the methods used in both of these are available  here on the algorithms pages

The two examples of univariate prediction that are illustrated in Fig. 2.2 are produced by the scripts univpredexample1.m and univpredexample2.m which also use PredCoef.m.

The script pigsmodelMSTEP.m uses the same function to produce the plots of multistep prediction properties shown in Fig. 2.6.

Impulse and step responses which are presented in Figs. 2.7 and 2.8 for the same VAR model for the Pig market series, are produced by the script pigsmodelImpStepResp.m which uses the function Psiwt.m.

The plots in Fig.2.10 which display the results of predicting future values and estimating missing values in a series are produced by the script pigFilSmo.m using the function SSfilsmoMV.m. The Pig market series and the same VAR model for this series are used in this illustration. The function hhrv.m is used in SSfilsmoMV.m for calculating Householder transformations.

In the same context, the script pigsProjLinCoef.m  produces the plots in Fig. 2.10 of the prediction coefficients for missing values. These are derived from the series covariance matrix implied by the model, using the function projLinCoefMV.m. This script also produces plots identical to those that are uppermost and lowest in Fig 2.10, providing confirmation by a distinct method described in section 2.13 of the book. These same plots are further confirmed by the third method by the script pigsProjDirect.m  which derives the results from the inverse covariance matrix using the function ProjDirectMV.m.

The calculation of the inverse covariance matrix of a VAR model by the formula (2.6) is illustrated in the script VARinvcovmatexample.m, which uses the function VARinvcovmat.m to produce this matrix for two models, one being the Pig market model. This function itself uses two other functions, covfunform.m and covfunfactor.m. The script also uses the function VARcovfun.m to produce and invert the covariance matrices as a check. The formula (2.6) is derived in the document here on the derivations page.


Chapter 2 functions


Chapter 2 Scripts


Chapter 2 test scripts