\[ \newcommand\E{{\mathbb{E}}} \]
Decomposing a time series
Stationarity
Autocorrelation function
Time series regression
Similar to the signal plus noise model,
\[ X_t = T_t + S_t + W_t \]
The r
function stats::decompose
will split a time series \(X_t\) into these three components.
Use the decompose
function on the jj
series.
Match the terms in the equation on the previous slide to each of the components in the chart
Describe the trend.
Does the bottom plot (“error”) look like white noise?
Look at the documentation for the decompose
function. Can you determine how the “trend” component was computed?
Recall the (sinusoidal) signal plus noise model: \[ w_t \sim \text{iid } N(0, \sigma^2_w)\\ x_t = 2\cos\left (\frac{2\pi t}{50} - .6\right) + w_t \]
decompose
function. Does the error portion look like white noise?Hint: The below code gives an error. Compare the “frequency” of the jj
series. Can you figure out how to use the ts
function to specify the correct frequency?
A time series is stationary if
And nonstationary otherwise.
\[ x_t = x_{t-1} + w_t \]
Last, time, we saw that the mean function is \(\E(x_t) = 0\), and the autocovariance function is \(\gamma_x(s, t) = \min\{s,t\}\sigma^2_w\)
No, the autcovariance function depends on \(t\) (there’s a \(t\) in the equation): \[ \gamma_x(s, t) = \min\{s,t\}\sigma^2_w \]
More concretely: consider if we want to know the correlation between the random walk at times \(s = 2, t = 5\), \[ \gamma(2,5) = \min\{2,5\}\sigma^2_w = 2\sigma^2_w \] But \(\gamma(3,5) = 3\sigma^2_w\). So the autocovariance is different depending on which points in time you are considering.
Again, no. The mean function of the random walk with drift is \(\mu_t = \delta t\), which depends on \(t\).
Which of the following time series are stationary?
The autocorrelation function (acf) of a time series is: \[ \rho(s, t) = \frac{\gamma(s,t)}{\sqrt{\gamma(s,s)\gamma(t,t)}} \] i.e. the autocovariance divided by the standard deviation of the process at each time point.
Since for stationary time series the autocovariance depends on \(s\) and \(t\) only through their difference, we can write the covariance as: \[ \gamma(s,t) = \gamma(h) = cov(x_{t+h}, x_t) = \E[(x_{t+h} - \mu)(x_t-\mu)] \] and the correlation as: \[ \rho(s,t) = \rho(h) = \frac{\gamma(h)}{\gamma(0)} \] \(h = s-t\) is called the lag.
\(\gamma_v(s, t) = cov(v_s, v_t) = \begin{cases}\frac{3}{9}\sigma^2_w & \text{ if } s = t\\ \frac{2}{9}\sigma^2_w & \text{ if } \vert s-t \vert = 1 \\\frac{1}{9}\sigma^2_w & \text{ if } \vert s-t \vert =2 \\0 & \text{ if } \vert s - t\vert > 2\end{cases}\)
Since \(v\) is stationary, we can write
\(\gamma_v(h) = \begin{cases}\frac{3}{9}\sigma^2_w & \text{ if } h = 0\\ \frac{2}{9}\sigma^2_w & \text{ if } h = \pm1 \\\frac{1}{9}\sigma^2_w & \text{ if }h = \pm 2 \\0 & \text{ if } h> 2\end{cases}\)
And the autocorrelation is:
\(\rho(h) = \begin{cases}1 & \text{ if } h = 0\\ \frac{2}{3} & \text{ if } h = \pm1 \\\frac{1}{3} & \text{ if }h = \pm 2 \\0 & \text{ if } h> 2\end{cases}\)
In R, we can plot \(\rho(h)\)
# simulate from an ar(1)
w <- rnorm(500)
ar_1 <- stats::filter(w, filter = 0.8, method = "recursive")
# use acf() function
acf(ar_1)
## what is the lag 1 correlation?
acf_output <- acf(ar_1, plot = F)
acf_output$acf[2] ## lag 1 autocorrelation
[1] 0.7846967
When smoothing time series data, it is sometimes advantageous to give decreasing amounts of weights to values farther away from the center. Consider the simple two-sided moving average smoother of the form: \[ v_t = \frac{1}{4}(w_{t-1} + 2w_t + w_{t+1}) \] Where \(w_t\) are white noise. The autocovariance as a function of \(h\) is: \[\gamma_v(s, t) = cov(v_s, v_t) = \begin{cases}\frac{6}{16}\sigma^2_w & \text{ if } h = 0\\ \frac{4}{16}\sigma^2_w & \text{ if } h = \pm 1 \\\frac{1}{16}\sigma^2_w & \text{ if } h = \pm 2 \\0 & \text{ if } h> 2\end{cases}\] 1. Compare to the autocovariance equation for the unweighted 3 point moving average from Lecture 2. Comment on the differences.
Recall the decomposition of the Johnson and Johnson quarterly earnings.