package com.imsl.test.example.stat; import com.imsl.math.*; import com.imsl.stat.*; /** *

Fits a vector autoregression to a time series. *

*

* This example fits a \(\text{VAR}(1)\) to a \(2\)-dimensional vector time series. Then, * forecasts for up to \(4\) steps ahead are requested, illustrating the default * forecasting behavior.

* * * @see Code * @see Output */ public class VectorAutoregressionEx1 { public static void main(String args[]) { double data1[] = { 0, 0, -0.148105526820657, 0.0507420782620461, -1.13674727366735, 0.862892721126079, 1.54366183541037, -1.13804802266371, -0.0923211737957721, 1.65649055346038, 0.521764564424907, -2.11208211206815, 0.843683397890515, 2.56656798707681, -2.70330819114831, -2.83452914666041, 4.93683704766295, 3.95965377457266, -4.78314880243807, -2.23136673998374, 6.24911547448071, 0.40543051970714, -6.76582567372196, 0.816818897274206, 6.21142944093012, -4.247694573354, -5.29817270483491, 5.08246614505046, 4.19557583927549, -5.35697380907112, -3.21572784971078, 7.89716072829777, 0.485717553966479, -8.25930665413043, 2.69490292018773, 10.9017252520684, -5.41090143363388, -10.400477539227, 8.29423327234419, 9.10321370415527 }; TimeSeries ts = new TimeSeries(); // Set the data for the two-dimensional time series ts.setSeriesValues(data1, 2); // Set up the vector autoregression model. Use default AR lag = 1. VectorAutoregression VAR1 = new VectorAutoregression(ts); // Get estimates of coefficient matrix A1 double[][] coefs = VAR1.getEstimates(); // Print estimates PrintMatrix pm = new PrintMatrix("Estimated Coefficient Matrix A1"); pm.print(coefs); // Get h =1, 2, 3, 4 step ahead forecasts for all time points past // the default presample value (nT = 6) double[][] forecasts = VAR1.getForecasts(); // Print forecasts pm = new PrintMatrix("VAR Forecasts"); PrintMatrixFormat pmf = new PrintMatrixFormat(); String[] colLabels = {"(h=1,k=1)", "(h=1,k=2)", "(2,1)", "(2,2)", "(3,1)", "(3,2)", "(4,1)", "(4,2)"}; pmf.setColumnLabels(colLabels); pmf.setNoRowLabels(); pm.print(pmf, forecasts); } }