Forecasting electricity demand
You can also model daily electricity demand as a function of temperature. As you may have seen on your electric bill, more electricity is used on hot days due to air conditioning and on cold days due to heating.
In this exercise, you will fit a quadratic regression model with an ARMA error. One year of daily data are stored as elecdaily
including total daily demand, an indicator variable for workdays (a workday is represented with 1, and a non-workday is represented with 0), and daily maximum temperatures. Because there is weekly seasonality, the frequency
has been set to 7.
Let's take a look at the first three rows:
> elecdaily[1:3, ]
Demand Temperature Workday
[1,] 174.8963 26.0 0
[2,] 188.5909 23.0 1
[3,] 188.9169 22.2 1
elecdaily
has been pre-loaded into your workspace.
This exercise is part of the course
Forecasting in R
Exercise instructions
- Produce time plots of only the daily demand and maximum temperatures with facetting.
- Set up a matrix of regressors to include
MaxTemp
for the maximum temperatures,MaxTempSq
which represents the squared value of the maximum temperature, andWorkday
, in that order. Clearly, the second argument ofcbind()
will require a simple mathematical operator. - Fit a dynamic regression model of the demand column with ARIMA errors and call this
fit
. - If the next day is a working day (indicator is 1) with maximum temperature forecast to be 20°C, what is the forecast demand? Fill out the appropriate values in
cbind()
for thexreg
argument inforecast()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Time plots of demand and temperatures
autoplot(elecdaily[, c(___, ___)], facets = ___)
# Matrix of regressors
xreg <- cbind(MaxTemp = elecdaily[, "Temperature"],
MaxTempSq = ___,
Workday = ___)
# Fit model
fit <- auto.arima(___, xreg = xreg)
# Forecast fit one day ahead
forecast(___, xreg = cbind(___, ___, ___))