Dealing with trend and heteroscedasticity
Here, we will coerce nonstationary data to stationarity by calculating the return or growth rate as follows.
Often time series are generated as $$X_t = (1 + p_t) X_{t-1}$$ meaning that the value of the time series observed at time \(t\) equals the value observed at time \(t-1\) and a small percent change \(p_t\) at time \(t\).
A simple deterministic example is putting money into a bank with a fixed interest \(p\). In this case, \(X_t\) is the value of the account at time period \(t\) with an initial deposit of \(X_0\).
Typically, \(p_t\) is referred to as the return or growth rate of a time series, and this process is often stable.
For reasons that are outside the scope of this course, it can be shown that the growth rate \(p_t\) can be approximated by $$Y_t = \log X_t - \log X_{t-1} \approx p_t.$$
In R, \(p_t\) is often calculated as diff(log(x))
and plotting it can be done in one line plot(diff(log(x)))
.
This exercise is part of the course
ARIMA Models in R
Exercise instructions
- As before, the packages astsa and xts are preloaded.
- Generate a multifigure plot to (1) plot the quarterly US GNP (
gnp
) data and notice it is not stationary, and (2) plot the approximate growth rate of the US GNP usingdiff()
andlog()
. - Use a multifigure plot to (1) plot the daily DJIA closings (
djia$Close
) and notice that it is not stationary. The data are anxts
object. Then (2) plot the approximate DJIA returns usingdiff()
andlog()
. How does this compare to the growth rate of the GNP?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# astsa and xts are preloaded
# Plot GNP series (gnp) and its growth rate
par(mfrow = c(2,1))
plot(gnp)
# Plot DJIA closings (djia$Close) and its returns
par(mfrow = c(2,1))
plot(djia$Close)