Version: | 0.3 |
Title: | Temporal Hierarchical Forecasting |
Description: | Methods and tools for generating forecasts at different temporal frequencies using a hierarchical time series approach. |
Depends: | R (≥ 3.0.2), forecast (≥ 7.2) |
Imports: | hts, ggplot2 |
LazyData: | yes |
ByteCompile: | TRUE |
BugReports: | https://github.com/robjhyndman/thief/issues |
License: | GPL-3 |
URL: | http://pkg.robjhyndman.com/thief, https://github.com/robjhyndman/thief |
RoxygenNote: | 6.0.1.9000 |
NeedsCompilation: | no |
Packaged: | 2018-01-24 04:50:27 UTC; hyndman |
Author: | Rob Hyndman [aut, cre, cph], Nikolaos Kourentzes [aut, cph] |
Maintainer: | Rob Hyndman <Rob.Hyndman@monash.edu> |
Repository: | CRAN |
Date/Publication: | 2018-01-24 05:06:33 UTC |
Accident and Emergency demand in the UK
Description
Weekly demand of Accident & Emergency departments in the UK, from 7 November 2010 to 7 June 2015.
Usage
AEdemand
Format
An object of class ts
.
Examples
library(ggplot2)
autoplot(AEdemand, xlab="Year", ylab="Demand ('000)") +
ggtitle("Accident & Emergency Demand in the UK")
## Not run:
# Demonstration of the adjustment of all temporal aggregates
# using Total Emergency Admissions
total <- AEdemand[,12]
totalagg <- tsaggregates(total)
plot(totalagg, main="Total Emergency Admissions")
# Base forecasts
base <- list()
for(i in 1:5)
base[[i]] <- forecast(auto.arima(totalagg[[i]]))
base[[6]] <- forecast(auto.arima(totalagg[[6]]), h=2)
# Reconciled forecasts
reconciled <- reconcilethief(base)
main <- paste(names(totalagg)," (k=",
52/unlist(lapply(reconciled,frequency)),")",sep="")
par(mfrow=c(2,3))
for(i in 6:1)
{
ylim <- range(base[[i]]$mean, base[[i]]$x, reconciled[[i]]$mean)
plot(base[[i]], main=main[i], fcol='white',
plot.conf=FALSE, ylim=ylim, xlim=c(2010.5,2017.5))
polygon(c(2015.45, 2020, 2020, 2015.45),
c(0, 0, 1e5, 1e5), col='grey', border=FALSE)
lines(base[[i]]$mean, col='red', lty=2)
lines(reconciled[[i]]$mean, col='blue')
}
## End(Not run)
Plot time series aggregates
Description
Plots all temporal aggregations of a time series
Usage
## S3 method for class 'tsaggregates'
plot(x, series = "all", ...)
## S3 method for class 'tsaggregates'
autoplot(object, series = "all", ...)
Arguments
x |
|
series |
The indexes of the series to plot. By default, all series are plotted. |
... |
Other arguments passed to |
object |
|
Author(s)
Rob J Hyndman
Examples
deathagg <- tsaggregates(USAccDeaths)
plot(deathagg, series=c(1,2,4,6))
library(ggplot2)
autoplot(deathagg)
Reconcile temporal hierarchical forecasts
Description
Takes forecasts of time series at all levels of temporal aggregation and combines them using the temporal hierarchical approach of Athanasopoulos et al (2016).
Usage
reconcilethief(forecasts, comb = c("struc", "mse", "ols", "bu", "shr", "sam"),
mse = NULL, residuals = NULL, returnall = TRUE, aggregatelist = NULL)
Arguments
forecasts |
List of forecasts. Each element must be a time series of forecasts, or a forecast object. The number of forecasts should be equal to k times the seasonal period for each series, where k is the same across all series. |
comb |
Combination method of temporal hierarchies, taking one of the following values:
|
mse |
A vector of one-step MSE values corresponding to each of the forecast series. |
residuals |
List of residuals corresponding to each of the forecast models.
Each element must be a time series of residuals. If |
returnall |
If |
aggregatelist |
(optional) User-selected list of forecast aggregates to consider |
Value
List of reconciled forecasts in the same format as forecast
.
If returnall==FALSE
, only the most disaggregated series is returned.
Author(s)
Rob J Hyndman
See Also
Examples
# Construct aggregates
aggts <- tsaggregates(USAccDeaths)
# Compute forecasts
fc <- list()
for(i in seq_along(aggts))
fc[[i]] <- forecast(auto.arima(aggts[[i]]), h=2*frequency(aggts[[i]]))
# Reconcile forecasts
reconciled <- reconcilethief(fc)
# Plot forecasts before and after reconcilation
par(mfrow=c(2,3))
for(i in seq_along(fc))
{
plot(reconciled[[i]], main=names(aggts)[i])
lines(fc[[i]]$mean, col='red')
}
Temporal hierarchical forecasting
Description
Takes a time series as input and produces forecasts using the temporal hierarchical approach of Athanasopoulos et al (2016).
Usage
thief(y, m = frequency(y), h = m * 2, comb = c("struc", "mse", "ols",
"bu", "shr", "sam"), usemodel = c("ets", "arima", "theta", "naive",
"snaive"), forecastfunction = NULL, aggregatelist = NULL, ...)
Arguments
y |
Time series input |
m |
Seasonal period |
h |
Forecast horizon |
comb |
Combination method of temporal hierarchies, taking one of the following values:
|
usemodel |
Model used for forecasting each aggregation level:
|
forecastfunction |
User-defined function to be used instead of |
aggregatelist |
User-selected list of forecast aggregates to consider |
... |
Arguments to be passed to the time series modelling function
(such as |
Details
This function computes the temporal aggregates of y
using
tsaggregates
, then calculates all forecasts using the model function
specified by usemodel
or forecastfunction
, and finally reconciles the
forecasts using reconcilethief
. The reconciled forecasts of y
are returned.
Value
forecast object.
Author(s)
Rob J Hyndman and Nikolaos Kourentzes
See Also
Examples
## Not run:
# Select ARIMA models for all series using auto.arima()
z <- thief(AEdemand[,12], usemodel='arima')
plot(z)
# Use your own function
ftbats <- function(y,h,...){forecast(tbats(y),h,...)}
z <- thief(AEdemand[,12], forecastfunction=ftbats)
plot(z)
## End(Not run)
Non-overlapping temporal aggregation of a time series
Description
Produces all temporal aggregations for frequencies greater than 1
Usage
tsaggregates(y, m = frequency(y), align = c("end", "start"),
aggregatelist = NULL)
Arguments
y |
Univariate time series of class |
m |
Integer seasonal period |
align |
Indicates how the aggregates are to be aligned:
either with the |
aggregatelist |
User-selected list of aggregates to consider. |
Value
A list of time series. The first element is the series 'y', followed by series with increasing levels of aggregation. The last element is the "annual" series (i.e., the series aggregated over all seasons).
Author(s)
Rob J Hyndman
See Also
Examples
tsaggregates(USAccDeaths)