Produce a residual plot. Is the model adequate? Are there any outliers or influential observations?
jan14_vic_elec%>%autoplot()+geom_smooth()
## Plot variable not specified, automatically selected `.vars = Demand`
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Use the model to forecast the electricity demand that you would expect for the next day if the maximum temperature was 15∘C and compare it with the forecast if the with maximum temperature was 35∘C. Do you believe these forecasts? The following R code will get you started:
## Warning: Computation failed in `stat_interval()`.
## Caused by error in `trans$transform()`:
## ! `transform_date()` works with objects of class <Date> only
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning: Computation failed in `stat_interval()`.
## Caused by error in `trans$transform()`:
## ! `transform_date()` works with objects of class <Date> only
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## # A tsibble: 1 x 6 [1D]
## # Key: .model [1]
## .model Date Demand .mean Temperature `95%`
## <chr> <date> <dist> <dbl> <dbl> <hilo>
## 1 tslm 2014-02-01 N(151398, 6.8e+08) 1.51e5 15 [100179.4, 202617.3]95
# forecast next day with maximum temperature = 35 degrees Celsiusjan14_vic_elec %>%model(tslm =TSLM(Demand ~ Temperature)) %>%forecast(new_data(jan14_vic_elec, 1) %>%mutate(Temperature =35) ) %>%autoplot()
## Warning: Computation failed in `stat_interval()`.
## Caused by error in `trans$transform()`:
## ! `transform_date()` works with objects of class <Date> only
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
## Warning in min(x, na.rm = na.rm): no non-missing arguments to min; returning
## Inf
## Warning in max(x, na.rm = na.rm): no non-missing arguments to max; returning
## -Inf
Give prediction intervals for your forecasts.
vic_elec %>%filter(yearmonth(Time) ==yearmonth("2014 Feb")) %>%index_by(Date =as_date(Time)) %>%summarise(Demand =sum(Demand), Temperature =max(Temperature) # select maximum temperature ) %>%slice(1)
## # A tsibble: 1 x 3 [1D]
## Date Demand Temperature
## <date> <dbl> <dbl>
## 1 2014-02-01 241283. 29.2
# forecast demand for maximum temperature = 15 degrees Celsius --> 151,398 (mean)# forecast demand for maximum temperature = 35 degrees Celsius --> 274,484 (mean)# actual demand for Feb 1, 2014 --> 241,283 with maximum temperature of 29.2 degrees Celsius
Plot Demand vs Temperature for all of the available data in vic_elec aggregated to daily total demand and maximum temperature. What does this say about your model?
vic_elec %>%select(Date, Demand, Temperature) %>%index_by(Date) %>%summarise(Demand =sum(Demand), Temperature =max(Temperature) # select maximum temperature ) %>%mutate(Demand =scale(Demand), Temperature =scale(Temperature) ) %>%pivot_longer(c(Demand, Temperature), names_to ='Series') %>%autoplot(value) +labs(x =NULL, y ='Value', title ='Victoria 2014 Electricity Daily Demand vs. Maximum Temperature (scaled)')
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `piecewise = (function (object, ...) ...`.
## Caused by warning:
## ! prediction from a rank-deficient fit may be misleading