Example 1: Parameter estimation and outlier detection for a time series from biology

This example is based on estimates of the Canadian lynx population. Class ARMAOutlierIdentification is used to fit an \text{ARIMA}(2,2,0) model of the form

(1-B)(1-\phi_1B-\phi_2B^2)Y_t=a_t,\, t=1,2,\ldots,144,
\{a_t\} Gaussian White noise, to the given series. Method Compute determines parameters \phi_1=0.10682 and \phi_2=-0.19666 and identifies a LS outlier at time point t=16.

using System;
using Imsl.Stat;

public class ARMAOutlierIdentificationEx1
{
   public static void Main(String[] args)
   {
        
     double[] series = {
      0.24300e01, 0.25060e01, 0.27670e01, 0.29400e01, 0.31690e01, 0.34500e01,
      0.35940e01, 0.37740e01, 0.36950e01, 0.34110e01, 0.27180e01, 0.19910e01,
      0.22650e01, 0.24460e01, 0.26120e01, 0.33590e01, 0.34290e01, 0.35330e01,
      0.32610e01, 0.26120e01, 0.21790e01, 0.16530e01, 0.18320e01, 0.23280e01,
      0.27370e01, 0.30140e01, 0.33280e01, 0.34040e01, 0.29810e01, 0.25570e01,
      0.25760e01, 0.23520e01, 0.25560e01, 0.28640e01, 0.32140e01, 0.34350e01, 
      0.34580e01, 0.33260e01, 0.28350e01, 0.24760e01, 0.23730e01, 0.23890e01,
      0.27420e01, 0.32100e01, 0.35200e01, 0.38280e01, 0.36280e01, 0.28370e01,
      0.24060e01, 0.26750e01, 0.25540e01, 0.28940e01, 0.32020e01, 0.32240e01,
      0.33520e01, 0.31540e01, 0.28780e01, 0.24760e01, 0.23030e01, 0.23600e01,
      0.26710e01, 0.28670e01, 0.33100e01, 0.34490e01, 0.36460e01, 0.34000e01,
      0.25900e01, 0.18630e01, 0.15810e01, 0.16900e01, 0.17710e01, 0.22740e01,
      0.25760e01, 0.31110e01, 0.36050e01, 0.35430e01, 0.27690e01, 0.20210e01,
      0.21850e01, 0.25880e01, 0.28800e01, 0.31150e01, 0.35400e01, 0.38450e01,
      0.38000e01, 0.35790e01, 0.32640e01, 0.25380e01, 0.25820e01, 0.29070e01,
      0.31420e01, 0.34330e01, 0.35800e01, 0.34900e01, 0.34750e01, 0.35790e01,
      0.28290e01, 0.19090e01, 0.19030e01, 0.20330e01, 0.23600e01, 0.26010e01,
      0.30540e01, 0.33860e01, 0.35530e01, 0.34680e01, 0.31870e01, 0.27230e01,
      0.26860e01, 0.28210e01, 0.30000e01, 0.32010e01, 0.34240e01, 0.35310e01};

      int[] model = { 2, 0, 1, 2 };
      double[] outlierFreeSeries;
      double resStdErr, aic, constant;
      double[] ar;
      int[,] outlierStatistics;
      int numOutliers;
        
      ARMAOutlierIdentification armaOutlier = new ARMAOutlierIdentification(series);
        
      armaOutlier.CriticalValue = 3.5;
      armaOutlier.Compute(model);
        
      outlierFreeSeries = armaOutlier.GetOutlierFreeSeries();
      numOutliers = armaOutlier.NumberOfOutliers;
      outlierStatistics = armaOutlier.GetOutlierStatistics();
      constant = armaOutlier.Constant;
      ar = armaOutlier.GetAR();
      resStdErr = armaOutlier.ResidualStandardError;
      aic = armaOutlier.AIC;

      Console.Out.WriteLine();
      Console.Out.WriteLine();
      Console.Out.WriteLine("   ARMA parameters:");
      Console.Out.WriteLine("constant:{0,9:f6}", constant);
      Console.Out.WriteLine("ar[0]:{0,12:f6}", ar[0]);
      Console.Out.WriteLine("ar[1]:{0,12:f6}", ar[1]);
      Console.Out.WriteLine();
      Console.Out.WriteLine("Number of outliers:{0,3:d}", numOutliers);
      Console.Out.WriteLine("\n   Outlier statistics:");
      Console.Out.WriteLine("Time point      Outlier type");
      for (int i = 0; i < numOutliers; i++)
        Console.Out.WriteLine("{0,10:d}{1,18:d}", outlierStatistics[i,0],
                               outlierStatistics[i,1]);
      Console.Out.WriteLine("\nRSE:{0,11:f6}", resStdErr);
      Console.Out.WriteLine("AIC:{0,11:f6}", aic);
      Console.Out.WriteLine("\n\n   Extract from the series:");
      Console.Out.WriteLine("time   original   outlier free");
      for (int i = 0; i < 36; i++)
          Console.Out.WriteLine("{0,4:d}{1,11:f4}{2,15:f4}", i + 1,
                                   series[i], outlierFreeSeries[i]);
    }
}

Output



   ARMA parameters:
constant: 0.000000
ar[0]:    0.106532
ar[1]:   -0.195856

Number of outliers:  1

   Outlier statistics:
Time point      Outlier type
        16                 2

RSE:   0.319542
AIC: 282.918191


   Extract from the series:
time   original   outlier free
   1     2.4300         2.4300
   2     2.5060         2.5060
   3     2.7670         2.7670
   4     2.9400         2.9400
   5     3.1690         3.1690
   6     3.4500         3.4500
   7     3.5940         3.5940
   8     3.7740         3.7740
   9     3.6950         3.6950
  10     3.4110         3.4110
  11     2.7180         2.7180
  12     1.9910         1.9910
  13     2.2650         2.2650
  14     2.4460         2.4460
  15     2.6120         2.6120
  16     3.3590         2.6997
  17     3.4290         2.7697
  18     3.5330         2.8737
  19     3.2610         2.6017
  20     2.6120         1.9527
  21     2.1790         1.5197
  22     1.6530         0.9937
  23     1.8320         1.1727
  24     2.3280         1.6687
  25     2.7370         2.0777
  26     3.0140         2.3547
  27     3.3280         2.6687
  28     3.4040         2.7447
  29     2.9810         2.3217
  30     2.5570         1.8977
  31     2.5760         1.9167
  32     2.3520         1.6927
  33     2.5560         1.8967
  34     2.8640         2.2047
  35     3.2140         2.5547
  36     3.4350         2.7757

Link to C# source.