library(fpp3)
<- vic_elec |>
vic_daily mutate(
Day = factor(wday(Date, label = TRUE), ordered = FALSE),
Weekend = Day %in% c("Sat", "Sun"),
Working_Day = !Weekend & !Holiday
|>
) index_by(Date = as_date(Time)) |>
summarise(
Demand = sum(Demand),
Temperature = max(Temperature),
Day = first(Day),
Working_Day = first(Working_Day)
)
Activities: Week 11
Daily electricity demand forecasting
We will fit a regression model to daily electricity demand for Victoria. First, we will aggregate the half-hourly data to daily data with daily total demands, maximum temperatures, day of week, and working days.
Plot the Demand against temperature. Why is there a nonlinear relationship? What are the two clusters of observations?
|> vic_daily ggplot(aes(x = Temperature, y = Demand)) + geom_point()
Try colouring the graph with
Day
andWorking_Day
. What do you learn?Fit a regression model for Demand with temperature, temperature squared, and working day as predictor variables.
<- vic_daily |> fit model( lm = TSLM(Demand ~ Temperature + I(Temperature^2) + Working_Day) )report(fit)
Write down the equation for this model.
Produce a residual plot using
gg_tsresiduals()
. Is the model adequate? How might you fix it?Update your model to capture the problems you’ve identified. Check that the CV statistic has improved. Write down the equation for the updated model.
Produce a residual plot for the updated model. Is it adequate now?
What ARIMA model might work for the residuals?
augment(fit) |> gg_tsdisplay(.innov, plot_type = "partial")
If you fitted an ARIMA model to the residuals of the regression model, write down the full model equations.
Ignoring the serial correlation issues for now, produce forecasts for the next 2 weeks assuming the maximum temperature will be equal to 25 each day. You will need to set up a
new_data
tsibble with the predictors for the next two weeks.<- new_data(vic_daily, 14) |> nd mutate( Day = factor(wday(Date, label = TRUE), ordered = FALSE), Weekend = Day %in% c("Sat", "Sun"), Holiday = Date == as.Date("2025-01-01"), Working_Day = !Weekend & !Holiday, Temperature = 25 )|> fit forecast(new_data = nd) |> autoplot(vic_daily |> dplyr::filter(Date >= "2014-11-01"))
What happens if you include a heat-wave scenario in your
nd
object? What about a cool spell?