               Nonstationary Time Series and Differencing


 We go back to an example from the first day of class: the time series
of the values of monthly fresh fruit imports into Canada, in millions of
dollars. From the first plot (upper-left), the series has a linear 
trend, so the series is nonstationary (we are ignoring the seasonal 
variation that is also present for now).

   par(mfrow=c(3,2))
   tsplot(fruitimp.ts) 

 The next plot is the autocorrelation function (acf) of this series.
The function is not decaying quickly as the lag increases. This is
another piece of evidence that the series is nonstationary.

   acf(fruitimp.ts)

 We now take first differences of the series using the "diff" command in
Splus, assuming the original series is saved in fruitimp.ts:

  fruitimp.ts.diff <- diff(fruitimp.ts, lag = 1, differences = 1) 

 The option "lag" specifies the lag of the differences to be computed.
By setting lag = 1, we are telling Splus to find the difference between
successive elements (x_t - x_(t-1)). There may be cases where we don't
want to find the difference between successive elements. For example, we
may want to find the difference between the same month in adjacent
years, i.e. (Jan 2004 - Jan 2003). 

 The option "differences" specifies the number of differences to be
done, i.e. do we want to do first differences, 2nd differences, etc.

 The plot of this series is 

  tsplot(fruitimp.ts.diff) 

and we see the linear trend is no longer present. However, the acf plot

 acf(fruitimp.ts.diff)

still shows some peaks at the 12 and 24 month points, i.e. the seasonal
effect. Let's try a difference to account for this:

  fruitimp.ts.diff.seas <- diff(fruitimp.ts.diff,lag = 12,differences=1)     
  tsplot(fruitimp.ts.diff.seas)
  acf(fruitimp.ts.diff.seas)

  How have the plots changed?

