Week 11: Dynamic regression
Tutorial exercises
- Complete Exercises 1-7 from Section 7.10 of the book.
- Tutorial learning objectives.
What you will learn this week
- How to combine regression models with ARIMA models to form dynamic regression models
- Dynamic harmonic regression to handle complex seasonality
- Lagged predictors
Pre-class seminar
Read Chapter 10 of the textbook and watch all embedded videos
Slides for seminar
Seminar activities
Review the model for US gasoline data from last week to now be a dynamic harmonic regression model.
Turn the half hourly electricity data into daily data using the following code. Try and understand what each line does.
<- vic_elec |> vic_elec_daily index_by(Date = date(Time)) |> # index by date to turn into daily summarise( # summarise() below Demand = sum(Demand)/1e3, # Total daily and scaling Mega to Gigawatts Temperature = max(Temperature), # take highest temperature for the day Holiday = any(Holiday) # Hol for any half hour is Hol for day |> # create new variable Day_Type ) mutate(Day_Type = case_when( # Separate weekdays, weekends and holidays ~ "Holiday", # If Holiday=TRUE call it a Holiday Holiday wday(Date) %in% 2:6 ~ "Weekday", # wday() returns 1:7 starting from a Sunday TRUE ~ "Weekend" # Call everything else a weekend ))
Explore the seasonal patterns.
- Fit an ETS, ARIMA and a dynamic harmonic regression model using the following code:
<- vic_elec_daily |> elec_fit model( ets = ETS(Demand), arima = ARIMA(log(Demand)), dhr = ARIMA(log(Demand) ~ Temperature + I(Temperature^2) + == "Weekday") + (Day_Type fourier(period = "year", K = 4)) )
Explore the model fits and residuals.
- Generate forecast for 14-days-ahead using the following code.
<- new_data(vic_elec_daily, 14) |> vic_elec_future mutate( Temperature = c(rep(32, 7), rep(25, 7)), Holiday = c(TRUE, rep(FALSE, 13)), Day_Type = case_when( ~ "Holiday", Holiday wday(Date) %in% 2:6 ~ "Weekday", TRUE ~ "Weekend" ) )
Exam 2024
- Section A: Q4
- Section B: Q3 (i-j)
- Section E: all questions
Exam 2023
- Section A: Q6
- Section B: Q3 (i-j)
- Section D: all questions
- Section E: all questions