Averages for Time Series

Chapter 1: Lesson 3

Learning Outcomes

Decompose time series into trends, seasonal variation, and residuals
  • Define smoothing
  • Compute the centered moving average for a time series
  • Estimate the trend component using moving averages
Plot time series data to visualize trends, seasonal patterns, and potential outliers
  • Plot the estimated trend of a time series using a moving average
  • Make box plots to examine seasonality
  • Interpret the trend and seasonal pattern observed in a time series

Preparation

  • Read Sections 1.5.1-1.5.3

Learning Journal Exchange (10 min)

  • Review another student’s journal
  • What would you add to your learning journal after reading your partner’s?
  • What would you recommend your partner add to their learning journal?
  • Sign the Learning Journal review sheet for your peer

Packages

pacman::p_load(
  tidyverse,  # ggplot, mutate(), cleaning...
  tsibble,    # as_tsibble()
  fable,      # model(...), forecast(), tidy(), glance()...
  feasts,     # ACF(), PACF()
  ggtime,     # autoplot() for tsibbles
  rio,        # import()
  pander,     # pander() markdown tables
  patchwork   # + and / for ggplots
)

Vocabulary and Nomenclature Matching Activity (10 min)

TipCheck Your Understanding

Working with a partner, match the definitions on the left with the terms on the right.

Nomenclature Matching

1. Discrete observations of a time series, taken at times \(1, 2, \ldots, n\). A. \(n\)
2. Number of observations of a time series B. \(k\)
3. Lead time C. \(m_t\)
4. The trend as observed at time \(t\) D. \(\hat m_t\)
5. The seasonal effect, as observed at time \(t\) E. \(s_t\)
6. The error term (a sequence of correlated random variables with mean zero), as observed at time \(t\) F. \(\hat s_t = x_t - \hat m_t\)
7. Centered moving average for observations made monthly G. \(\hat s_t = \dfrac{x_t}{\hat m_t}\)
8. Estimate of monthly additive effect H. \(\{x_t\}\)
9. Estimate of monthly multiplicative effect I. \(z_t\)
10. Forecast made at time \(t\) for a future value \(k\) time units in the future J. \(\bar s_t\)
11. Additive decomposition model K. \(x_t = m_t + s_t + z_t\)
12. Additive decomposition model after taking the logarithm L. \(x_t = m_t \cdot s_t + z_t\)
13. Multiplicative decomposition model M. \(\log(x_t) = m_t + s_t + z_t\)
14. Seasonally adjusted mean for the month corresponding to time \(t\) N. \(x_t - \bar s_t\)
15. Seasonal adjusted series (additive seasonal effect) O. \(\frac{x_t}{\bar s_t}\)
16. Seasonal adjusted series (multiplicative seasonal effect) P. \(\hat x_{t+k \mid t}\)

Team Activity: Moving Averages (45 min)

Derivation

Data representing some value have been collected each month for a few years. This plot represents the first 12 observations in this time series.

TipCheck Your Understanding
  • Suppose you wanted to compute the mean of the observations from the first year (\(t = 1\) to \(t=12\).) What is the formula you would use to compute this mean? Write this expression without a summation symbol.
  • To what value of \(t\) should this mean be assigned? (If you were to plot this mean on a time plot, where should it go?)

TipCheck Your Understanding
  • Suppose you want to compute the mean of one year’s worth of observations, beginning at month \(t=2\). Write the formula you would use to compute this mean without using a summation symbol.
  • To what value of \(t\) should this mean be assigned? (If you were to plot this mean on a time plot, where should it go?)

TipCheck Your Understanding
  • Note that neither of the two means above are appropriately located on an integer value of \(t\).
  • Give a formula that combines the two means above to give one mean that is centered on an integer value of \(t\). Do not include a summation symbol in your formula. (Hint: try averaging the two means.)
  • Upon what value of \(t\) is your new mean centered?

We will now adjust this moving average, so it is centered on any given value of \(t\), not just \(t=7\).

TipCheck Your Understanding
  • Consider the values \(x_{t-6}\), \(x_{t-5}\), \(x_{t-4}\), \(x_{t-3}\), \(x_{t-2}\), \(x_{t-1}\), \(x_{t}\), \(x_{t+1}\), \(x_{t+2}\), \(x_{t+3}\), \(x_{t+4}\), and \(x_{t+5}\).
    • Give an expression for the mean of the values.
    • Where will this mean be centered?
  • Consider the values \(x_{t-5}\), \(x_{t-4}\), \(x_{t-3}\), \(x_{t-2}\), \(x_{t-1}\), \(x_{t}\), \(x_{t+1}\), \(x_{t+2}\), \(x_{t+3}\), \(x_{t+4}\), \(x_{t+5}\), and \(x_{t+6}\).
    • Give an expression for the mean of the values.
    • Where will this mean be centered?
  • We now combine these two means by averaging them.
    • Give an expression for the mean of these two means.
    • Where will this combined mean be centered?

Estimating the Seasonal Effect: Side-by-Side Box Plots by Month (10 min)

To better visualize the effect of seasonal variation, we can make box plots by month.

ggplot(chocolate_month_ts, aes(x = factor(month), y = value)) +
    geom_boxplot() +
  labs(
    x = "Month Number",
    y = "Searches",
    title = "Boxplots of Google Searches for 'Chocolate' by Month"
  ) +
  theme(plot.title = element_text(hjust = 0.5))

TipCheck Your Understanding
  • What do you observe?
  • Which months tend to have the most searches? Which months tend to have the fewest seraches?
    • Can you provide an explanation for this?

Summary (10 min)

TipCheck Your Understanding
  • What does the centered moving average tell us?
  • Why is a centered moving average helpful when there are seasonal effects?
  • For the chocolate search data, answer the following questions:
    • How many values of \(t\) were not assigned a value of the centered moving average?
    • Interpret that number in years.
    • Does this number depend on the length of the time series?

Homework Preview (5 min)

  • Review upcoming homework assignment
  • Clarify questions

Homework

NoteDownload Assignment

Solutions

Matching

Team Activity