SEASONAL_FIT Function
Estimates the optimum seasonality parameters for a time series using an autoregressive model, AR(p), to represent the time series.
Usage
result = SEASONAL_FIT(z, maxlag, s_initial)
Input Parameters
z—Array of length n_obs containing the time series, where n_obs is the number of observations in the time series. No missing values in the series are allowed.
maxlag—The maximum lag allowed when fitting an AR(p) model.
s_initial—A scalar, 1D, or 2D array of dimension n_s_initial by n_differences containing the seasonal differences to test. n_s_initial is the number of rows of the array containing the seasonal differences and n_differences is the number of differences to perform. n_differences must be greater than or equal to one. All values of s_initial must be greater than or equal to one. If s_initial is a 1D array, n_differences is assumed to be 1. A scalar s_initial value implies n_s_initial = n_differences = 1.
Returned Value
result—Array of length n_obs, or n_obsN_lost if the Exclude_first keyword is set, containing the optimum seasonally adjusted, autoregressive series. The first N_lost observations in this series are set to NaN, missing values. The seasonal adjustment is done by selecting optimum values for d1, ..., dm, s1, ..., sm (m = n_differences) and p in the AR model:
where:
*{Zt} is the original time series
*B is the backward shift operator defined by , k 0
*at is Gaussian white noise with E(at) = 0
*VAR(at) = σ 2, , 0   p   maxlag , with s > 0, d 0, and μ is a centering parameter for the differenced series.
Note that , the identity operator, i.e. .
Input Keywords
Double—If present and nonzero, double precision is used.
D_initial—A scalar, 1D array, or 2D array of dimension N_d_initial by n_differences containing the candidate values for d, from which the optimum is being selected. All candidate values in D_initial must be non-negative and N_d_initial 1. Default: N_d_initial = 1, D_initial an array of length n_differences filled with ones.
Exclude_first—If Exclude_first is specified, the first N_lost values are excluded from the returned value due to differencing. The differenced series, the returned value, is of length n_obsN_lost. By default, the first N_lost observations are set to NaN (Not a Number).
Center—If supplied, controls the method used to center the differenced series. If Center = 0 then the series is not centered. If Center = 1, the mean of the series is used to center the data, and if Center = 2, the median is used. Default: Center = 1.
Output Keywords
N_lost—The number of observations lost due to differencing the time series. This is also equal to the number of NaN values that appear in the first N_lost locations of the returned seasonally adjusted series when Set_first_to_nan is set or the number of values excluded if Exclude_first is set.
Best_periods—Array of length m = n_differences containing the optimum values for the seasonal adjustment parameters s1, s2, ..., sm selected from the list of candidates contained in s_initial.
Best_orders—Array of length m = n_differences containing the optimum values for the seasonal adjustment parameters d1, d2, ..., dm selected from the list of candidates contained in D_initial.
Ar_order—The optimum value for the autoregressive lag.
Aic—Akaike’s Information Criterion (AIC) for the optimum seasonally adjusted model.
Discussion
Many time series contain seasonal trends and cycles that can be modeled by first differencing the series. For example, if the correlation is strong from one period to the next, the series might be differenced by a lag of 1. Instead of fitting a model to the series Zt, the model is fitted to the transformed series: Wt = ZtZt–1. Higher order lags or differences are warranted if the series has a cycle every 4 or 13 weeks.
SEASONAL_FIT does not center the original series. If Center = 1 or Center = 2, then the differenced series, Wt, is centered before determination of minimum AIC and optimum lag. For every combination of rows in s_initial and D_initial, the series Zt is converted to the seasonally adjusted series using the following computation:
where , represent specific rows of arrays s_initial and D_initial respectively, and m = n_differences.
This transformation of the series Zt to Wt(s, d) is accomplished using DIFFERENCE. After this transformation:
Wt(s, d)
is (optionally) centered and a call is made to AUTO_UNI_AR to automatically determine the optimum lag for an AR(p) representation for Wt(s, d). This procedure is repeated for every possible combination of rows of s_initial and D_initial. The series with the minimum AIC is identified as the optimum representation and returned.
Example
Consider the Airline Data (Box, Jenkins and Reinsel 1994, p. 547) consisting of the monthly total number of international airline passengers from January 1949 through December 1960. SEASONAL_FIT is used to compute the optimum seasonality representation of the adjusted series:
where:
s = (1,1)
or:
s = (1,12)
and:
d = (1,1)
As differenced series with minimum AIC:
is identified.
maxlag = 10
nobs = 144
s_init = TRANSPOSE([[1, 1], [1, 12]])
z = statdata (4)
 
difference = SEASONAL_FIT(z, maxlag, s_init, $
                          N_Lost=nlost,      $
                          Best_Periods=s,    $
                          Best_Orders=d,     $
                          Aic=aic,           $
                          Ar_Order=npar)
 
PRINT, nlost, Format='("nlost = ", I2)'
PRINT, s(0), s(1), Format='("s = (",  I1, ", ", I2, ")")'
PRINT, d(0), d(1), Format='("d = (",  I1, ", ", I2, ")")'
PRINT, npar, Format='("Order of optimum AR process:", I2)'
PRINT, aic, Format='("aic = ", F7.3)'
PRINT, ''
PRINT, "   i         z[i]        difference[i]"
FOR i=0L, nobs-1 DO $
   PRINT, i, z(i), difference(i), Format='(I4, F15.4, F15.4)'
Output
nlost = 13
s = (1, 12)
d = (1,  1)
Order of optimum AR process: 1
aic = 829.780
 
   i         z[i]        difference[i]
   0       112.0000            NaN
   1       118.0000            NaN
   2       132.0000            NaN
   3       129.0000            NaN
   4       121.0000            NaN
   5       135.0000            NaN
   6       148.0000            NaN
   7       148.0000            NaN
   8       136.0000            NaN
   9       119.0000            NaN
  10       104.0000            NaN
  11       118.0000            NaN
  12       115.0000            NaN
  13       126.0000         5.0000
  14       141.0000         1.0000
  15       135.0000        -3.0000
  16       125.0000        -2.0000
  17       149.0000        10.0000
  18       170.0000         8.0000
  19       170.0000         0.0000
  20       158.0000         0.0000
  21       133.0000        -8.0000
  22       114.0000        -4.0000
  23       140.0000        12.0000
  24       145.0000         8.0000
  25       150.0000        -6.0000
  26       178.0000        13.0000
  27       163.0000        -9.0000
  28       172.0000        19.0000
  29       178.0000       -18.0000
  30       199.0000         0.0000
  31       199.0000         0.0000
  32       184.0000        -3.0000
  33       162.0000         3.0000
  34       146.0000         3.0000
  35       166.0000        -6.0000
  36       171.0000         0.0000
  37       180.0000         4.0000
  38       193.0000       -15.0000
  39       181.0000         3.0000
  40       183.0000        -7.0000
  41       218.0000        29.0000
  42       230.0000        -9.0000
  43       242.0000        12.0000
  44       209.0000       -18.0000
  45       191.0000         4.0000
  46       172.0000        -3.0000
  47       194.0000         2.0000
  48       196.0000        -3.0000
  49       196.0000        -9.0000
  50       236.0000        27.0000
  51       235.0000        11.0000
  52       229.0000        -8.0000
  53       243.0000       -21.0000
  54       264.0000         9.0000
  55       272.0000        -4.0000
  56       237.0000        -2.0000
  57       211.0000        -8.0000
  58       180.0000       -12.0000
  59       201.0000        -1.0000
  60       204.0000         1.0000
  61       188.0000       -16.0000
  62       235.0000         7.0000
  63       227.0000        -7.0000
  64       234.0000        13.0000
  65       264.0000        16.0000
  66       302.0000        17.0000
  67       293.0000       -17.0000
  68       259.0000         1.0000
  69       229.0000        -4.0000
  70       203.0000         5.0000
  71       229.0000         5.0000
  72       242.0000        10.0000
  73       233.0000         7.0000
  74       267.0000       -13.0000
  75       269.0000        10.0000
  76       270.0000        -6.0000
  77       315.0000        15.0000
  78       364.0000        11.0000
  79       347.0000        -8.0000
  80       312.0000        -1.0000
  81       274.0000        -8.0000
  82       237.0000       -11.0000
  83       278.0000        15.0000
  84       284.0000        -7.0000
  85       277.0000         2.0000
  86       317.0000         6.0000
  87       313.0000        -6.0000
  88       318.0000         4.0000
  89       374.0000        11.0000
  90       413.0000       -10.0000
  91       405.0000         9.0000
  92       355.0000       -15.0000
  93       306.0000       -11.0000
  94       271.0000         2.0000
  95       306.0000        -6.0000
  96       315.0000         3.0000
  97       301.0000        -7.0000
  98       356.0000        15.0000
  99       348.0000        -4.0000
 100       355.0000         2.0000
 101       422.0000        11.0000
 102       465.0000         4.0000
 103       467.0000        10.0000
 104       404.0000       -13.0000
 105       347.0000        -8.0000
 106       305.0000        -7.0000
 107       336.0000        -4.0000
 108       340.0000        -5.0000
 109       318.0000        -8.0000
 110       362.0000       -11.0000
 111       348.0000        -6.0000
 112       363.0000         8.0000
 113       435.0000         5.0000
 114       491.0000        13.0000
 115       505.0000        12.0000
 116       404.0000       -38.0000
 117       359.0000        12.0000
 118       310.0000        -7.0000
 119       337.0000        -4.0000
 120       360.0000        19.0000
 121       342.0000         4.0000
 122       406.0000        20.0000
 123       396.0000         4.0000
 124       420.0000         9.0000
 125       472.0000       -20.0000
 126       548.0000        20.0000
 127       559.0000        -3.0000
 128       463.0000         5.0000
 129       407.0000       -11.0000
 130       362.0000         4.0000
 131       405.0000        16.0000
 132       417.0000       -11.0000
 133       391.0000        -8.0000
 134       419.0000       -36.0000
 135       461.0000        52.0000
 136       472.0000       -13.0000
 137       535.0000        11.0000
 138       622.0000        11.0000
 139       606.0000       -27.0000
 140       508.0000        -2.0000
 141       461.0000         9.0000
 142       390.0000       -26.0000
 143       432.0000        -1.0000