Time Series Model Package

Example 17.4 Performing Time Series Imputation Using an ARIMA Model

Time series imputation is the process of replacing missing values in a time series with reasonable values that reflect the existing pattern in the available data (such as trend, seasonal variations, or long-term cyclical variations). It is a popular technique that is used across various domains of science. This example shows how you can do the following:

  • Fit an ARIMA model to a time series that contains missing values by using a TSM object.

  • Store the imputed values of the time series in a table.

For the purposes of this example, the following statements introduce two artificial missing values into the airline series (see Example 17.1 for more information about the airline series and the airline model). The modified series is stored in the mycas.airMiss CAS table. These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

data mycas.airmiss;
    set mycas.air;
    airmiss = air;
    if date = '01JUL1955'd then airmiss = .;
    if date = '01AUG1955'd then airmiss = .;
run;

The following statements plot the modified airline series along with the two artificial missing values that were introduced. The results are shown in Output 17.4.1.

proc sort data=mycas.airmiss out=airmiss;
   by date;
run;

proc sgplot data=airmiss;
   series x=date y = airmiss / break lineattrs=(color=blue thickness=3);
   series x=date y = air / lineattrs=(thickness=2 pattern=dot color=blue);
run;

In Output 17.4.1, the solid blue line represents all the nonmissing data values in the modified airline series. The dotted blue line between the years 1955 and 1956 represents the two actual values that were set to missing values.

Output 17.4.1: Airline Passenger Time Series with Artificial Missing Values

Airline Passenger Time Series with Artificial Missing Values


The following statements fit the airline model to the modified airline series and store the imputed time series in the mycas.airImpute CAS table:

proc tsmodel data=mycas.airmiss
   outobj=(airImpute=mycas.airImpute) ;
   id date interval=month;
   var airmiss;
   require tsm;
   submit;

      *** Analysis based on airline model ***;
      declare object airModel(tsm);
      declare object airSpec(arimaspec);
      declare object airImpute(tsmfor('SMOOTH','YES'));

      array diff[2]/nosymbols;
      array ma[1]/nosymbols;

      *** Set up the airline model spec:   ***;
      ** Model: log(air) ~ (0,1,1)(0,1,1)12 noint ***;
      rc = airSpec.Open();
      *** Specify differencing orders ***;
      diff[1] = 1;
      diff[2] = 12;
      rc = airSpec.SetDiff(diff,2);
      *** Specify moving average orders: q = (1)(12)   ***;
      *** Use AddMAPoly twice  for the two factors   ***;
      ma[1] = 1;
      rc = airSpec.AddMAPoly(ma);
      ma[1] = 12;
      rc = airSpec.AddMAPoly(ma);
      *** Specify NOINT             ***;
      rc = airSpec.SetOption('noint',1);
      *** Specify the log transform     ***;
      rc = airSpec.SetTransform('log');
      *** Done setting up the ARIMA model ***;
      rc = airSpec.Close();

      *** Set up and run the TSM object ***;
      rc = airModel.Initialize(airSpec);
      rc = airModel.SetY(Airmiss);
      rc = airModel.Run();

      *** Output the imputed airline time series ***;
      rc = airImpute.Collect(airModel);
  endsubmit;
quit;

The following statements plot the modified airline series along with its imputed version. The results are shown in Output 17.4.2.

data mycas.airimpute;
   merge mycas.airimpute mycas.airmiss;
   by date;
run;

proc sort data=mycas.airimpute out=airimpute;
   by date;
run;

proc sgplot data=airimpute;
   series x=date y = actual / break lineattrs=(thickness=3 color=blue);
   series x=date y = air / lineattrs=(thickness=2 pattern=dot color=blue);
   series x=date y = predict / lineattrs=(thickness=1 color=red);
   where year(date) >= 1954 and year(date) <= 1956;
run;

In Output 17.4.2, the thick blue line represents the modified airline series, and the thin red line represents its imputed version. The time axis range is restricted to the dates between the years 1954 and 1956 in order to facilitate the visualization. Notice how the thin red line (imputed values) closely mimics the dotted blue line (original actual values) over the region between the years 1955 and 1956 where the artificial missing values were introduced.

Output 17.4.2: Imputed Airline Passenger Time Series

Imputed Airline Passenger Time Series


Last updated: June 14, 2018