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.
using System;
using Imsl.Stat;
public class AutoARIMAEx1
{
public static void Main(String[] args)
{
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.CriticalValue = 3.8;
autoArima.Compute(5);
autoArima.Forecast(6);
nOutliers = autoArima.NumberOfOutliers;
aic = autoArima.AIC;
optimumModel = autoArima.GetOptimumModelOrder();
outlierStatistics = autoArima.GetOutlierStatistics();
RSE = autoArima.ResidualStandardError;
outlierForecast = autoArima.GetForecast();
psiWeights = autoArima.GetPsiWeights();
probabilityLimits = autoArima.GetDeviations();
constant = autoArima.Constant;
ar = autoArima.GetAR();
ma = autoArima.GetMA();
Console.Out.WriteLine("\nMethod 1: Automatic AR model selection"
+ ", no differencing");
Console.Out.WriteLine(
"\nOptimum Model: p={0,1:d}, q={1,1:d}, s={2,1:d}, d={3,1:d}",
optimumModel[0], optimumModel[1], optimumModel[2], optimumModel[3]);
Console.Out.WriteLine("\nNumber of outliers:{0,3:d}", nOutliers);
Console.Out.WriteLine();
Console.Out.WriteLine("Outlier statistics:");
Console.Out.WriteLine(" Time Type");
for (int i = 0; i < nOutliers; i++)
Console.Out.WriteLine("{0,5:d}{1,8:d}", outlierStatistics[i, 0],
outlierStatistics[i, 1]);
Console.Out.WriteLine("\nAIC:{0,12:f6}", aic);
Console.Out.WriteLine("RSE:{0,12:f6}", RSE);
Console.Out.WriteLine();
Console.Out.WriteLine(" Parameters");
Console.Out.WriteLine(" constant:{0,12:f6}", constant);
for (int i = 0; i < ar.Length; i++)
Console.Out.WriteLine(" ar[{0,1:d}]:{1,15:f6}", i, ar[i]);
for (int i = 0; i < ma.Length; i++)
Console.Out.WriteLine(" ma[{0,1:d}]:{1,15:f6}", i, ma[i]);
Console.Out.WriteLine();
Console.Out.WriteLine();
Console.Out.WriteLine(" * * * Forecast Table * * *");
Console.Out.WriteLine(" Exact forecast limits psi");
for (int i = 0; i < outlierForecast.Length; i++)
Console.Out.WriteLine("{0,7:f4}{1,11:f4}{2,11:f4}{3,11:f4}",
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.104666
RSE: 0.359632
Parameters
constant: 0.097542
ar[0]: 0.891871
ar[1]: -0.123831
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 C# source.