Workshop Activities: Week 7
Week 7 Mini-Studio
This page follows the same sequence as week7.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
- Open week7.R beside this page.
- Work through the sections in order.
- Run the matching block in RStudio.
- Use the prompts here to practise explanation and model choice, not just syntax.
A. Stationarity of the Cement series
This section explores transformations and differencing for the Cement production series.
# Australia Cement production
aus_production |>
autoplot(Cement) +
labs(title = "Cement production in Australia")
NoteWhat this code is doing
- Plots the raw Cement production series from aus_production.
NoteWhat to notice
- The series shows trending behavior and seasonal patterns.
- Variance appears to increase over time.
# Stabilise variance
aus_production |>
autoplot(
log(Cement)
) +
labs(title = "Cement production in Australia")
NoteWhat this code is doing
- Applies a log transformation to stabilize variance.
NoteWhat to notice
- The log transformation reduces the increasing variance.
# Account for seasonality
aus_production |>
autoplot(
log(Cement) |> difference(lag=12)
) +
labs(title = "Cement production in Australia")
NoteWhat this code is doing
- Applies seasonal differencing (lag=12) to the log-transformed series.
NoteWhat to notice
- Seasonal differencing removes the seasonal component.
- The series may still show trends.
# Let's get some help from gg_tsdisplay
aus_production |>
gg_tsdisplay(
log(Cement) |> difference(lag=12)
)
NoteWhat this code is doing
- Uses gg_tsdisplay to examine ACF and PACF of the seasonally differenced series.
NoteWhat to notice
- The ACF suggests further differencing may be needed.
aus_production |>
autoplot(
log(Cement) |> difference(12) |> difference(1)
) +
labs(title = "Cement production in Australia")
NoteWhat this code is doing
- Applies both seasonal and first differencing to the log series.
NoteWhat to notice
- The doubly differenced series appears stationary.
aus_production |>
gg_tsdisplay(
log(Cement) |> difference(12) |> difference(1)
)
NoteWhat this code is doing
- Displays ACF and PACF of the doubly differenced series.
NoteWhat to notice
- The ACF decays quickly, indicating stationarity.
- The series is not white noise.
# Let's verify through more official
aus_production |>
features(log(Cement), feat_stl)
NoteWhat this code is doing
- Computes STL decomposition features for the log series.
NoteWhat to notice
- Checks seasonal strength and other features.
aus_production |>
features(log(Cement),
unitroot_nsdiffs)
NoteWhat this code is doing
- Determines the number of seasonal differences needed.
NoteWhat to notice
- Based on seasonal strength.
aus_production |>
features(log(Cement) |> difference(12),
unitroot_ndiffs)
NoteWhat this code is doing
- Determines the number of first differences needed after seasonal differencing.
NoteWhat to notice
- Uses KPSS test for non-seasonal differences.
B. Stationarity of PBS series (A10 and H02)
This section examines the A10 and H02 series from PBS data.
a10 <- PBS |>
filter(ATC2 == "A10") |>
summarise(Cost = sum(Cost))
a10 |> autoplot(Cost)
NoteWhat this code is doing
- Creates the A10 series by filtering and summarizing PBS data.
- Plots the A10 cost series.
NoteWhat to notice
- Features of the series in terms of stationarity.
# Difference without transformation - what do you see?
a10 |> autoplot(
difference(Cost,12)
)
NoteWhat this code is doing
- Applies seasonal differencing to A10 without transformation.
NoteWhat to notice
- Effect of differencing on the series.
a10 |> autoplot(
difference(log(Cost),12)
)
NoteWhat this code is doing
- Applies seasonal differencing to the log-transformed A10 series.
NoteWhat to notice
- Comparison with previous plot.
a10 |>
features(
difference(log(Cost),12),
unitroot_ndiffs)
NoteWhat this code is doing
- Checks if further differencing is needed for the log-differenced A10.
NoteWhat to notice
- Number of additional differences required.
## h02
h02 <- PBS |>
filter(ATC2 == "H02") |>
summarise(Cost = sum(Cost))
NoteWhat this code is doing
- Creates the H02 series similarly to A10.
NoteWhat to notice
- Initial features of the H02 series.
C. Algerian exports series
This section explores the Algerian exports from global_economy.
# Explore the Algerian exports series
global_economy |>
filter(Country == "Algeria") |>
autoplot(Exports)
NoteWhat this code is doing
- Plots the Exports series for Algeria.
NoteWhat to notice
- Is the series stationary? Is it white noise?
Exam Practice
Important2023 Exam Questions
- Section A: Q2, Q3
- Section B: Q1, Q2, Q3 (a-f)
- Section C: all questions
Use the code patterns from this week to approach these questions. Focus on stationarity tests and transformations.