Example 2: Parameter estimation and outlier detection for an artificial time series

This example is an artificial realization of an \text{ARMA}(1,1) process via formula Y_t-0.8Y_{t-1}=10.0+a_t+0.5a_{t-1},\, t=1,\ldots,300,\,\{a_t\} Gaussian white noise, E[Y_t]=50.0. An additive outlier with \omega_1=4.5 was added at time point t=150, a temporary change outlier with \omega_2=3.0 was added at time point t=200.

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

public class ARMAOutlierIdentificationEx2
{
  public static void main(String args[]) throws Exception {

    double resStdErr, aic;
    int[][] outlierStatistics;
    int numOutliers;
    double[] omegaWeights;
    int[] model = new int[4];
	double[] outlierFreeSeries;
    double constant;
    double[] ar, ma;

    double[] series ={
      50.0000000,50.2728081,50.6242599,51.0373917,51.9317627,50.3494759,
      51.6597252,52.7004929,53.5499802,53.1673279,50.2373505,49.3373871,
      49.5516472,48.6692696,47.6606636,46.8774185,45.7315445,45.6469727,
      45.9882355,45.5216560,46.0479660,48.1958656,48.6387749,49.9055367,
      49.8077278,47.7858467,47.9386749,49.7691956,48.5425873,49.1239853,
      49.8518791,50.3320694,50.9146347,51.8772049,51.8745689,52.3394470,
      52.7273712,51.4310036,50.6727448,50.8370399,51.2843437,51.8162918,
      51.6933670,49.7038231,49.0189247,49.455703,50.2718010,49.9605980,
      51.3775749,50.2285385,48.2692299,47.6495590,49.2938499,49.1924858,
      49.6449242,50.0446815,51.9972496,54.2576981,52.9835434,50.4193535,
      50.3617897,51.8276901,53.1239929,54.0682144,54.9238319,55.6877632,
      54.8896332,54.0701065,52.2754097,52.2522354,53.1248703,51.1287193,
      50.5003815,49.6504173,47.2453079,45.4555626,45.8449707,45.9765129,
      45.7682228,45.2343674,46.6496811,47.0894432,49.3368340,50.8058052,
      49.9132500,49.5893288,48.2470627,46.9779968,45.6760864,45.7070389,
      46.6158409,47.5303612,47.5630417,47.0389214,46.0352287,45.8161545,
      45.7974396,46.0015373,45.3796463,45.3461685,47.6444016,49.3327446,
      49.3810692,50.2027817,51.4567032,52.3986320,52.5819206,52.7721825,
      52.6919098,53.3274345,55.1345940,56.8962631,55.7791634,55.0616989,
      52.3551178,51.3264084,51.0968323,51.1980476,52.8001442,52.0545082,
      50.8742943,51.5150337,51.2242050,50.5033989,48.7760124,47.4179192,
      49.7319527,51.3320541,52.3918304,52.4140434,51.0845947,49.6485748,
      50.6893463,52.9840813,53.3246994,52.4568024,51.9196091,53.6683121,
      53.4555359,51.7755814,49.2915611,49.8755112,49.4546776,48.6171913,
      49.9643021,49.3766441,49.2551308,50.1021881,51.0769119,55.8328133,
      52.0212708,53.4930801,53.2147255,52.2356453,51.9648819,52.1816330,
      51.9898071,52.5623627,51.0717278,52.2431946,53.6943054,54.3752098,
      54.1492615,53.8523254,52.1093712,52.3982697,51.2405128,50.3018112,
      51.3819618,49.5479546,47.5024452,47.4447708,47.8939056,48.4070015,
      48.2440681,48.7389755,49.7309227,49.1998024,49.5798340,51.1196213,
      50.6288414,50.3971405,51.6084099,52.4564743,51.6443901,52.4080658,
      52.4643364,52.6257210,53.1604691,51.9309731,51.4137230,52.1233368,
      52.9867249,53.3180733,51.9647636,50.7947655,52.3815842,50.8353729,
      49.4136009,52.8355217,52.2234840,51.1392517,48.5245132,46.8700218,
      46.1607285,45.2324257,47.4157829,48.9989090,49.6230736,50.4352913,
      51.1652985,50.2588654,50.7820129,51.0448799,51.2880516,49.6898804,
      49.0288200,49.9338837,48.2214432,46.2103348,46.9550171,47.5595894,
      47.7176018,48.4502945,50.9816895,51.6950073,51.6973495,52.1941261,
      51.8988075,52.5617599,52.0218391,49.5236053,47.9684906,48.2445183,
      48.8275146,49.7176971,51.5649338,52.5627213,52.0182419,50.9688835,
      51.5846901,50.9486771,48.8685837,48.5600624,48.4760094,48.5348396,
      50.4187813,51.2542381,50.1872864,50.4407692,50.6222687,50.4972000,
      51.0036087,51.3367500,51.7368202,53.0463791,53.6261253,52.0728683,
      48.9740753,49.3280830,49.2733917,49.8519020,50.8562126,49.5594254,
      49.6109200,48.3785629,48.0026474,49.4874268,50.1596375,51.8059540,
      53.0288620,51.3321075,49.3114815,48.7999306,47.7201881,46.3433914,
      46.5303612,47.6294632,48.6012459,47.8567657,48.0604057,47.1352806,
      49.5724792,50.5566483,49.4182968,50.5578079,50.6883736,50.6333389,
      51.9766159,51.0595245,49.3751640,46.9667702,47.1658173,47.4411278,
      47.5360374,48.9914742,50.4747620,50.2728043,51.9117165,53.7627792};

      model[0] = 1;
      model[1] = 1;
      model[2] = 1;
      model[3] = 0;

	  ARMAOutlierIdentification armaOutlier =
	                  new ARMAOutlierIdentification(series);

	  armaOutlier.setRelativeError(1.0e-5);
      armaOutlier.compute(model);

      outlierFreeSeries = armaOutlier.getOutlierFreeSeries();
      numOutliers = armaOutlier.getNumberOfOutliers();
      outlierStatistics = armaOutlier.getOutlierStatistics();
	  omegaWeights = armaOutlier.getOmegaWeights();
      constant = armaOutlier.getConstant();
      ar = armaOutlier.getAR();
	  ma = armaOutlier.getMA();
      resStdErr = armaOutlier.getResidualStandardError();
      aic = armaOutlier.getAIC();

	  System.out.printf("%n%n   ARMA parameters:%n");
	  System.out.printf(Locale.ENGLISH, "constant:%11.6f%n", constant);
	  System.out.printf(Locale.ENGLISH, "ar[0]:%14.6f%n", ar[0]);
	  System.out.printf(Locale.ENGLISH, "ma[0]:%14.6f%n%n", ma[0]);
	  System.out.printf("Number of outliers:%3d%n%n", numOutliers);
	  System.out.printf("   Outlier statistics:%n");
	  System.out.printf("Time point%6sOutlier type%n", " ");
	  for (int i = 0; i < numOutliers; i++)
		  System.out.printf("%10d%18d%n", outlierStatistics[i][0],
							  outlierStatistics[i][1]);
	  System.out.printf("%n   Omega statistics:%n");
	  System.out.printf("Time point%6sOmega%n", " ");
      for (int i=0; i<numOutliers; i++)
		 System.out.printf(Locale.ENGLISH, "%10d%11.6f%n",
			 outlierStatistics[i][0], omegaWeights[i]);
	  System.out.printf(Locale.ENGLISH, "%nRSE:%9.6f%n", resStdErr);
      System.out.printf(Locale.ENGLISH, "AIC:%12.6f", aic);
    }
}

Output



   ARMA parameters:
constant:  10.834213
ar[0]:      0.785117
ma[0]:     -0.496530

Number of outliers:  2

   Outlier statistics:
Time point      Outlier type
       150                 1
       200                 3

   Omega statistics:
Time point      Omega
       150   4.477885
       200   3.381440

RSE: 1.007223
AIC: 1417.044550
Link to Java source.