Example 3: Specified ARIMA model

This example is the same as example 2 but now method 3 with the optimum model parameters p = 3, q = 2, s = 1, d = 0 from Example 2 is chosen for outlier detection and forecasting.

import java.util.*;
import com.imsl.stat.*;

public class AutoARIMAEx3 {
  public static void main(String args[]) throws Exception {
	 int nOutliers;
	 double aic, RSE, constant;
	 int[] optimumModel;
	 int[][] outlierStatistics;
	 double[] outlierForecast, ar, ma;
     double[] psiWeights, probabilityLimits;

	 double[] x = {
         12.8, 12.2, 11.9, 10.9, 10.6, 11.3, 11.1, 10.4, 10.0, 9.7, 9.7, 9.7,
         11.1, 10.5, 10.3, 9.8, 9.8, 10.4, 10.4, 10.0, 9.7, 9.3, 9.6, 9.7,
         10.8, 10.7, 10.3, 9.7, 9.5, 10.0, 10.0, 9.3, 9.0, 8.8, 8.9, 9.2,
         10.4, 10.0, 9.6, 9.0, 8.5, 9.2, 9.0, 8.6, 8.3, 7.9, 8.0, 8.2,
         9.3, 8.9, 8.9, 7.7, 7.6, 8.4, 8.5, 7.8, 7.6, 7.3, 7.2, 7.3,
         8.5, 8.2, 7.9, 7.4, 7.1, 7.9, 7.7, 7.2, 7.0, 6.7, 6.8, 6.9,
         7.8, 7.6, 7.4, 6.6, 6.8, 7.2, 7.2, 7.0, 6.6, 6.3, 6.8, 6.7,
         8.1, 7.9, 7.6, 7.1, 7.2, 8.2, 8.1, 8.1, 8.2, 8.7, 9.0, 9.3,
         10.5, 10.1, 9.9, 9.4, 9.2, 9.8, 9.9, 9.5, 9.0, 9.0, 9.4, 9.6,
         11.0, 10.8, 10.4, 9.8, 9.7, 10.6, 10.5, 10.0, 9.8, 9.5, 9.7, 9.6,
         10.9, 10.3, 10.4, 9.3, 9.3, 9.8, 9.8, 9.3, 8.9, 9.1, 9.1, 9.1,
         10.2, 9.9, 9.4};
    
	 double[] exactForecast = {8.7, 8.6, 9.3, 9.1, 8.8, 8.5};

	 int[] times = {
         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
         13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
         25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
         37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
         49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
         61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
         73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
         85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
         97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
         109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
         121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
         133, 134, 135};

	 AutoARIMA autoArima = new AutoARIMA(times, x);
	 autoArima.setCriticalValue(3.8);
	 autoArima.compute(3, 2, 1, 0);
	 autoArima.forecast(6);

	 nOutliers = autoArima.getNumberOfOutliers();
	 aic = autoArima.getAIC();
	 optimumModel = autoArima.getOptimumModelOrder();
	 outlierStatistics = autoArima.getOutlierStatistics();
	 RSE = autoArima.getResidualStandardError();
	 outlierForecast = autoArima.getForecast();
     psiWeights = autoArima.getPsiWeights();
     probabilityLimits = autoArima.getDeviations();
     constant = autoArima.getConstant();
     ar = autoArima.getAR();
     ma = autoArima.getMA();

	 System.out.printf("%nMethod 3: Specified ARIMA model%n");
     System.out.printf("%nOptimum Model: p=%d, q=%d, s=%d, d=%d%n",
		                 optimumModel[0], optimumModel[1],
						 optimumModel[2], optimumModel[3]);
	 System.out.printf("%nNumber of outliers:%3d%n%n", nOutliers);
     System.out.printf("Outlier statistics:%n");
     System.out.printf(" Time%4sType%n", " ");
     for (int i=0; i<nOutliers; i++)
       System.out.printf("%5d%8d%n", outlierStatistics[i][0],
		                   outlierStatistics[i][1]);
	 System.out.printf(Locale.ENGLISH, "%nAIC:%12.6f%n", aic);
     System.out.printf(Locale.ENGLISH, "RSE%13.6f%n%n", RSE);
     System.out.printf("%5sParameters%n", " ");
     System.out.printf(Locale.ENGLISH, " constant:%10.6f%n", constant);
     for (int i=0; i<ar.length; i++)
       System.out.printf(Locale.ENGLISH, " ar[%d]:%13.6f%n", i, ar[i]);
     for (int i=0; i<ma.length; i++)
       System.out.printf(Locale.ENGLISH, " ma[%d]:%13.6f%n", i, ma[i]);
     System.out.printf("%n%n%6s* * * Forecast Table * * *%n", " ");
     System.out.printf("%2sExact%3sforecast%5slimits%8spsi%n",
				  " ", " ", " ", " ");
     for (int i = 0; i < outlierForecast.length; i++)
	   System.out.printf(Locale.ENGLISH, "%7.4f%11.4f%11.4f%11.4f%n",
			exactForecast[i], outlierForecast[i],
			probabilityLimits[i], psiWeights[i]);
  }
}

Output


Method 3: Specified ARIMA model

Optimum Model: p=3, q=2, s=1, d=0

Number of outliers:  1

Outlier statistics:
 Time    Type
  109       0

AIC:  408.108176
RSE     0.412456

     Parameters
 constant:  0.554459
 ar[0]:     1.940615
 ar[1]:    -1.898025
 ar[2]:     0.897791
 ma[0]:     1.115803
 ma[1]:    -0.911902


      * * * Forecast Table * * *
  Exact   forecast     limits        psi
 8.7000     9.1085     0.8084     0.8248
 8.6000     9.1715     1.0479     0.6145
 9.3000     9.5039     1.1597     0.5248
 9.1000     9.7677     1.2349     0.5926
 8.8000     9.7051     1.3245     0.7056
 8.5000     9.3817     1.4421     0.7157
Link to Java source.