This example uses time series LNU03327709 from the US Department of Labor, Bureau of Labor Statistics. It contains the unadjusted special unemployment rate, taken monthly from January 1994 through September 2005. The values 01/2004 - 03/2005 are used by class autoARIMA
for outlier detection and parameter estimation. In this example, method 1, without seasonal adjustment, is chosen to find an appropriate AR(p) model. A forecast is done for the following six months and compared with the actual values 04/2005 - 09/2005.
import java.util.*;
import com.imsl.stat.*;
public class AutoARIMAEx1 {
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(5);
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 1: Automatic AR model selection"+
", no differencing%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:%12.6f%n%n", RSE);
System.out.printf("%6sParameters%n", " ");
System.out.printf(Locale.ENGLISH, " constant:%12.6f%n", constant);
for (int i=0; i<ar.length; i++)
System.out.printf(Locale.ENGLISH, " ar[%d]:%15.6f%n", i, ar[i]);
for (int i=0; i<ma.length; i++)
System.out.printf(Locale.ENGLISH, " ma[%d]:%15.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]);
}
}
Method 1: Automatic AR model selection, no differencing
Optimum Model: p=5, q=0, s=1, d=0
Number of outliers: 7
Outlier statistics:
Time Type
8 2
13 0
37 3
85 0
97 0
109 0
121 0
AIC: 371.104679
RSE: 0.359632
Parameters
constant: 0.097541
ar[0]: 0.891872
ar[1]: -0.123830
ar[2]: -0.138262
ar[3]: 0.135621
ar[4]: 0.224111
* * * Forecast Table * * *
Exact forecast limits psi
8.7000 9.1076 0.7049 0.8919
8.6000 9.0993 0.9445 0.6716
9.3000 9.4032 1.0565 0.3503
9.1000 9.5806 1.0849 0.2416
8.8000 9.5506 1.0982 0.4243
8.5000 9.3932 1.1382 0.5910
Link to Java source.