Electricity Forecasting – the Power of R in a Spreadsheet

Published on 10th June 2015 by duke

So maybe your working within a utility and you need to make a forecast electricity demand so that you can work out the supply stack to meet that demand. Your familiar with at least one of R, Python or Matlab, but you need to take your electricity forecasts into account as part of some other work in Excel.

Electricity forecasting typically uses some sort of time series model to take into the longitudinal nature of the data and also the seasonal, trend and other components. Some great data is available for download from the National Grid.

After reading the data into R and examining the variables, it looks like it might make sense to focus on the TGSD data: “Total Gross System Demand (TGSD) – the total demand on the Transmission System; it includes station load, pump storage pumping and interconnector exports.”

Here is a time series plot of just over two weeks of data:
This time of day and day of week components are clearly evident.

Its a well known fact that temperature plays some part in electricity demand in the UK, albeit not to the same extent as it does for gas demand.

So the variables that we are going to use to try and predict electricity demand are:

– lagged electricity demand
– time of day
– day of week
– temperature

Important to note at this stage that this model is being built for illustrative purposes, its goes without saying that this could be improved upon. For example one could add a new variable to account for public holidays etc, one could also take into account other weather variables, use a seasonal normal temperature, weight the temperature used by the demand in each post code etc.

So the data is loaded into R, some tidying-up is done and its merged with the weather data. Note that the weather data has daily granularity. An ARIMA model is fitted and the excellent ‘forecast’ package is used for an initial forecast.

You can also visit the github repo for the full code.

So, having this model is great – but how do we integrate it with Excel for example ?

The following code shows how to deploy the model the the dukeanalytics servers.

Now, since the model has been deployed, its possible to make predictions using new input from multiple sources. To make forecasts from Excel, firstly download and install the DukeDeploy plugin.
Once you have this installed, download the following Excel file which contains an example forecast.

Its also possible to make forecasts from within Google Sheets This requires installation of the Google Sheets DukeDeploy Add-in (available for free from the Google Add-in Store).

Happy Forecasting! Any questions or queries to team@dukeanalytics.com