Workshop Activities: Week 5

Week 5 Mini-Studio

This page follows the same sequence as week5-code.R. It is designed as a stable seminar companion: read the code, run the matching block in R or RStudio, then answer the short prompts here in words. That keeps the focus on the class code, which is the style you are most likely to meet in the exam.

TipHow to use this page
  1. Open week5-code.R beside this page.
  2. Work through the sections in order.
  3. Run the matching block in RStudio.
  4. Use the prompts here to practise explanation and model choice, not just syntax.

A. Build the holidays series

This opening block creates the tourism series used in the first activity.

holidays <- tourism |>
  filter(State %in% c("Victoria", "Queensland")) |> 
  filter(Purpose == "Holiday") |>
  as_tibble() |>
  summarise(Trips = sum(Trips), .by = c("State", "Quarter")) |>
  as_tsibble(index = Quarter, key = State)

holidays |> autoplot()
NoteWhat this code is doing
  • Filters the tourism data to holiday trips in Victoria and Queensland.
  • Aggregates trips by state and quarter.
  • Converts to a tsibble for time series analysis.
  • Plots the series to visualize the data.
NoteWhat to notice
  • Compare the overall level and seasonal patterns between Victoria and Queensland.
  • Look for any trends or changes in variability over time.

B. Fit ETS models to the holidays series

This block fits ETS models to both series and explores the results.

fit <- holidays |>
  model(ets = ETS(Trips))

fit
fit |> glance()
fit |> tidy()
fit |>
  filter(State == "Queensland") |>
  report()

fit |>
  filter(State == "Victoria") |>
  report()
NoteWhat this code is doing
  • Fits automatic ETS models to each state’s series.
  • Uses glance() for model summaries, tidy() for parameters, and report() for detailed model info.
NoteWhat to notice
  • Note the different models selected for each state.
  • Compare the parameter estimates and model fits.
  • Pay attention to any warnings or automatic selections.

C. Plot components and generate forecasts

This section visualizes model components and produces forecasts.

fit |> components() |> autoplot()
fit |> forecast(h = 8) |> autoplot(holidays)
NoteWhat this code is doing
  • Plots the estimated components (trend, seasonal, error) of the fitted models.
  • Generates 8-step-ahead forecasts and plots them with the original data.
NoteWhat to notice
  • Examine how the components differ between states.
  • Assess the forecast patterns and uncertainty intervals.

D. Analyze Algeria exports data

This activity shifts to exports data for Algeria.

algeria_exports <- global_economy |>
  filter(Country == "Algeria") |>
  select(Year, Exports)

algeria_exports |> autoplot()
NoteWhat this code is doing
  • Extracts exports data for Algeria from global_economy.
  • Plots the series to assess its characteristics.
NoteWhat to notice
  • Determine if the series resembles white noise or has structure.
  • Consider what ETS model might be appropriate.

E. Fit ETS models to Algeria exports

Fit both additive and multiplicative error models.

fit_algeria <- algeria_exports |>
  model(
    additive = ETS(Exports ~ error("A")),
    multiplicative = ETS(Exports ~ error("M"))
  )

fit_algeria |> glance()
fit_algeria |> report()
NoteWhat this code is doing
  • Fits ETS models with additive and multiplicative errors.
  • Compares model summaries and reports.
NoteWhat to notice
  • See which model is selected automatically.
  • Compare the fitted parameters and performance.

F. Check components and residuals for Algeria

Analyze the model internals and residuals.

fit_algeria |> components() |> autoplot()
fit_algeria |> gg_tsresiduals()
NoteWhat this code is doing
  • Plots components and residual diagnostics for both models.
NoteWhat to notice
  • Look for patterns in residuals that indicate model adequacy.
  • Compare component plots between additive and multiplicative models.

G. Forecast Algeria exports

Generate and plot forecasts.

fit_algeria |> forecast(h = 5) |> autoplot(algeria_exports)
NoteWhat this code is doing
  • Produces 5-year-ahead forecasts and visualizes them.
NoteWhat to notice
  • Assess the forecast behavior and differences between models.

H. Analyze Australia population data

This final activity uses population data.

aus_pop <- global_economy |>
  filter(Country == "Australia") |>
  mutate(Population = Population / 1e6) |>
  select(Year, Population)

aus_pop |> autoplot()
NoteWhat this code is doing
  • Extracts and scales Australia’s population data to millions.
  • Plots the series.
NoteWhat to notice
  • Identify the trend pattern in the population growth.

I. Fit trend models to Australia population

Fit linear and damped trend models.

fit_aus <- aus_pop |>
  model(
    linear = ETS(Population ~ trend("A")),
    damped = ETS(Population ~ trend("Ad"))
  )

fit_aus |> report()
NoteWhat this code is doing
  • Fits ETS models with linear and damped trends.
  • Reports the estimated parameters.
NoteWhat to notice
  • Compare the trend parameters and model fits.

J. Generate long-term forecasts

Forecast 30 years ahead.

fit_aus |> forecast(h = 30) |> autoplot(aus_pop)
NoteWhat this code is doing
  • Generates 30-year forecasts and plots them.
NoteWhat to notice
  • Observe the differences in long-term projections between linear and damped trends.

K. Evaluate forecast accuracy

Fit models up to 2010 and forecast the rest.

train <- aus_pop |> filter(Year <= 2010)
fit_train <- train |>
  model(
    linear = ETS(Population ~ trend("A")),
    damped = ETS(Population ~ trend("Ad"))
  )

fit_train |> forecast(h = 11) |> autoplot(aus_pop) +
  labs(title = "Forecasts from models fitted to 2010 data")
NoteWhat this code is doing
  • Fits models to pre-2011 data and forecasts to present.
  • Plots forecasts against actual data for accuracy assessment.
NoteWhat to notice
  • Evaluate how well each model predicts the actual population growth.