Lecture 4

Julia Schedler

Recap

  • Decomposing time series
  • Stationarity (theoretically and with data)
  • Some activities

Today

  • Finish up activities from Lecture 3
  • Trend stationarity
  • Visualizing autocovariance (third attempt)
  • “Office hours”

Reminders

  • Syllabus participation policy
  • Assignments: Going forward, must submit rendered pdf of code portion. (if you want to be nice to me, do this for Assignment 2, but starts with Assignment 3)
  • Late quizzes: Going forward: Email me ahead of time, otherwise it’s a 0
  • Exam details: No use of computer, code will be covered but basic, notes sheet is allowed, practice test will be provided

Activity 1: Export Price of Salmon (Example 3.1)

Code
library(astsa)

summary(fit <- lm(salmon~time(salmon), na.action=NULL))
## 
## Call:
## lm(formula = salmon ~ time(salmon), na.action = NULL)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.69187 -0.62453 -0.07024  0.51561  2.34959 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -503.08947   34.44164  -14.61   <2e-16 ***
## time(salmon)    0.25290    0.01713   14.76   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8814 on 164 degrees of freedom
## Multiple R-squared:  0.5706, Adjusted R-squared:  0.568 
## F-statistic: 217.9 on 1 and 164 DF,  p-value: < 2.2e-16
tsplot(salmon, col=4, ylab="USD per KG", main="Salmon Export Price")
abline(fit)

Activity 1: Export Price of Salmon (Example 3.1)

  1. Does this time series appear stationary?

  2. The (mathematical) equation in the book for the trend line above is:

    \[ x_t = \beta_0 + \beta_1z_t + w_t, z_t = 2003\frac{8}{12}, 2001\frac{8}{12}, \dots, 2017\frac{5}{12} \]

    • There is a typo in this equation. Correct the typo. (hint: examine to the first few entries of time(salmon)

    • Why are there fractions of the year? Explain what the fractional values mean and describe how they appear in the data set within R.

  3. Interpret the estimate of the slope.

Activity 1: Export Price of Salmon (Example 3.1)

  1. Does this time series appear stationary?

No, the mean function is clearly increasing.

  1. The (mathematical) equation in the book for the trend line above is:

    \[ x_t = \beta_0 + \beta_1z_t + w_t, z_t = 2003\frac{8}{12}, 2001\frac{8}{12}, \dots, 2017\frac{5}{12} \]

    • There is a typo in this equation. Correct the typo. (hint: examine to the first few entries of time(salmon)

      [1] 2003.667 2003.750 2003.833 2003.917 2004.000 2004.083
      [1] 2003.667 2003.750 2003.833 2003.917 2004.000 2004.083

      The typo is the second year, it should be \(2003\frac{9}{12}\)

    • Why are there fractions of the year? Explain what the fractional values mean and describe how they appear in the data set within R.

      Note that we are dividing by 12, so the fractions represent the months. Based on the values of time(salmon), January corresponds to \(\frac{0}{12}\), so for example September is represented as \(\frac{8}{12}\).

  2. Interpret the estimate of the slope.

Each year, the expected export price of Norwegian salmon increases by 0.2592 USD per kg

Each month, the export price of Norwegian salmon increases by 0.2592/12 USD per kg on average

Activity 2: Trend Stationarity (Example 2.19)

Consider the time series model \[x_t = \beta t + y_t\] Assume \(y_t\) is stationary with mean function \(\mu_y\) and and autocovariance function \(\gamma_y(h)\)

  • Compare this equation to the regression equation in the last example.
  • What are the mean function and autocovariance function of \(x_t\)?

Activity 2 Solutions: Trend Stationarity (Example 2.19)

Consider the time series model \[x_t = \beta t + y_t\] Assume \(y_t\) is stationary with mean function \(\mu_y\) and and autocovariance function \(\gamma_y(h)\)

  • Compare this equation to the regression equation in the last example.

The equations are similar, with \(x_t\) being the same, \(\beta_1 = \beta\), \(\beta_0 = 0\), and \(w_t = y_t\), and \(z_t = t\). - What are the mean function and autocovariance function of \(x_t\)?

For the Mean

\[ \E(x_t) = \E(\beta t + y_t) = \E(\beta t) + \E(y_t) = \beta t + \mu_y \] For the Autocovariance \[ \begin{align} \gamma_x(h) = cov(x_{t+h}, x_t) &= \E[(x_{t+h} - \mu_{x,t+h})(x_t - \mu_{x,t})] \\ &= \E[\left( [\beta (t+h) + y_{t+h}] - [\beta (t+h) + \mu_y] \right)\left( [\beta (t) + y_{t}] - [\beta (t) + \mu_y] \right)] \\ &= \E[(y_{t+h} - \mu_y)(y_t - \mu_y)] \\ &= \gamma_y(h) \end{align} \]

Trend stationarity model

A time series which is nonstationary in the mean but is stationary in the autocovariance is sometimes called Trend stationarity.

  • I’m actually not sure if it just refers to linear trends?? I’ll ask people at my conference

Visualizing the autocovariance for trend stationarity

Simulate many time series from the trend stationarity model

Simulate many time series from the trend stationarity model

Simulate many time series from the trend stationarity model

Code
tsplot(all_series, spaghetti = TRUE, main = "100 Simuated Trend Stationary Time Series", type = "b")
rect(xleft = 1.5, xright = 2.5, ybottom = -2, ytop = 4, border = "blue", lwd = 2)
rect(xleft = 7.5, xright = 8.5, ybottom = -.5, ytop = 5, border = "magenta", lwd = 2)

Marginal and Joint Distributions t=8 and s=2

Marginal and Joint Distributions

Simulations

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 1

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 2

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 3

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 4

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 5

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 6

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 7

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 8

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 9

All Simulated Time Series

Marginal and Joint Distributions t=8 and s = 10

Visualizing the correlations

Are these all the correlations?

No, just pairwise with \(x_8\). We could do all possible pairs:

Distribution of all the correlations:

3D plots

3D version of histogram (includes \(s-t\) plane)

Simulated auto correlation function \(\hat{\gamma}_x(h)\) (with a blanket)

Theoretical \(\hat{\gamma}_x(h)\) (using the derived formula (with a blanket)

Detrending

Detrending

If a process is trend stationary (nonstationary in the mean, but stationary in the variance), can we just subtract off the trend and get back a stationary time series?

Yes, and that’s called detrending

Activity 3: Detrending a commodity (Example 3.7)

  • Given the code to generate the plot with the trend line, how would you view the equation of the trend line?
  • Visualize the de-trended series
  • Compute the acf of the salmon series and the detrended series. What do you notice?

Activity 3 Solution: Detrending a commodity (Example 3.7)

  • Given the code to generate the plot with the trend line, how would you view the equation of the trend line?
  • Visualize the de-trended series

Call:
lm(formula = salmon ~ time(salmon), na.action = NULL)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.69187 -0.62453 -0.07024  0.51561  2.34959 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -503.08947   34.44164  -14.61   <2e-16 ***
time(salmon)    0.25290    0.01713   14.76   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.8814 on 164 degrees of freedom
Multiple R-squared:  0.5706,    Adjusted R-squared:  0.568 
F-statistic: 217.9 on 1 and 164 DF,  p-value: < 2.2e-16

Detrending a commodity (Example 3.7)

  • Compute the acf of the salmon series and the de-trended series

Next time

  • Cross-correlation and regression with multiple time series (\(x_t\) on x-axis instead of \(t\) on x-axis like with the salmon) (Activities at the end of Ch 2)
  • Activities and examples From Chapter 3
  • Smoothing (Section 3.3)