Title: | Forecasting Routines for Locally Stationary Wavelet Processes |
---|---|
Description: | Implementation to perform forecasting of locally stationary wavelet processes by examining the local second order structure of the time series. |
Authors: | Rebecca Killick [aut, cre], Matt Nunes [aut], Guy Nason [aut], Marina Knight [aut], Idris Eckley [ctb] |
Maintainer: | Rebecca Killick <[email protected]> |
License: | GPL-2 |
Version: | 1.0 |
Built: | 2024-11-01 11:48:14 UTC |
Source: | CRAN |
This package computes forecasts for a time series with prediction errors. The forecasting methodology is designed with an underlying locally stationary wavelet model in mind. However, it is possible that the forecasting methodology will work well for other time series, including those where an underlying model is not necessarily known. Note: the methodology can work with any length of time series. The package also contains functions to display the forecasts and their prediction intervals or a fan chart, a function to evaluate the performance of the new forecasting methods and compare it to Box-Jenkins ARMA-based forecasting and a routine to identify wavelets that enable the forecasting routines to perform well.
Package: | lpacf |
Type: | Package |
Version: | 1.0 |
Date: | 2023-04-24 |
License: | GPL-2 |
The forecastlpacf
function computes forecasts of a locally
stationary (wavelet) time series using the localized partial autocorrelation
to help with history identification. The results of such forecasting
can be printed using print.forecastlpacf
or plotted
with plot.forecastlpacf
.
Two other useful functions are testforecast
which
runs some testing on forecasting some end values of a series using earlier
values and compares the new forecasting with standard Box-Jenkins ARMA
forecasting (visualisation via forecastpanel
) and
which.wavelet.best
which attempts to identify which wavelet is
well-suited to forecasting a particular series.
Rebecca Killick, Marina Knight, Guy Nason, Matt Nunes
Maintainer: Rebecca Killick <[email protected]>
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
forecastlpacf
,
testforecast
,
which.wavelet.best
# # See examples in each of the functions' help pages linked above. #
# # See examples in each of the functions' help pages linked above. #
Essentially GVA is a component in the estimator for UK Gross Domestic Product (GDP) an important economic time series. The series can be downloaded from the UK Office of National Statistics website, see below for references.
data("abml") data("abmld2")
data("abml") data("abmld2")
The GVA series that we obtain are the quarterly reports from Q1 1955 until Q4 2020. This is a series of 264 observations. The series has a strong mean trend which we have removed using twice differencing (diff(abml, diff=2)) to obtain the series abmld2. This vector is of length 262.
www.statistics.gov.uk/statbase/TSDtables1.asp and www.statistics.gov.uk/cci/nugget.asp?id=254
Takes the abmld2 data and analyzes it.
analyze.abmld2(h=10,atTime=NULL,atLag=NULL)
analyze.abmld2(h=10,atTime=NULL,atLag=NULL)
h |
Numeric value for a 1:h-steps ahead forecast. In reality we treat the |
atTime |
Vector of the times (rows) of the |
atLag |
Vector of the lags (columns) of the |
Takes the abmld2 data and analyzes it. Specifically the following is produced:
time series plot of the abmld2 data
the lpacf for the abmld2 data
plots of the lpacf + CI for the specified times and lags
the forecast for h to last data point(s) using the lpacf method
the forecast for h to last data point(s) using the standard ARMA method
plot of the original data, forecasts and confidence intervals for both methods, red=lpacf, blue=ARMA.
List containing the lpacf, forecast + accuracy measures using the lpacf method and forecast +accuracy measures using the ARMA method.
Rebecca Killick
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
## Not run: data(abmld2) out=analyze.abmld2() ## End(Not run)
## Not run: data(abmld2) out=analyze.abmld2() ## End(Not run)
Takes the windanomaly data and analyzes it.
analyze.windanomaly(h=10,atTime=NULL,atLag=NULL)
analyze.windanomaly(h=10,atTime=NULL,atLag=NULL)
h |
Numeric vector for a h-steps ahead forecast. In reality we treat the |
atTime |
Vector of the times (rows) of the |
atLag |
Vector of the lags (columns) of the |
Takes the windanomaly data and analyzes it. Specifically the following is produced:
time series plot of the windanomaly data
the lpacf for the windanomaly data
plots of the lpacf + CI for the specified times and lags
the forecast for h to last data point(s) using the lpacf method
the forecast for h to last data point(s) using the standard ARMA method
plot of the original data, forecasts and confidence intervals for both methods, red=lpacf, blue=ARMA.
List containing the lpacf, forecast + accuracy measures using the lpacf method and forecast +accuracy measures using the ARMA method.
Rebecca Killick
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
## Not run: data(windanomaly) out=analyze.windanomaly() ## End(Not run)
## Not run: data(windanomaly) out=analyze.windanomaly() ## End(Not run)
x
h
-steps ahead. (for the specified horizon h
) using the lpacf to decide the dimension of the generalized Yule-Walker equations.
This function forecasts a x
time series h
-steps
ahead. The time series is assumed to be locally stationary
(actualy locally stationary wavelet) and uses a local prediction
method. The function makes use of the localized partial autocorrelation
function to decide the order of the local Yule-Walker equations
used in the forecast.
forecastlpacf(x,h=1,regularize=TRUE,lag.max=max(10,2*h),forecast.type=NULL,...)
forecastlpacf(x,h=1,regularize=TRUE,lag.max=max(10,2*h),forecast.type=NULL,...)
x |
Vector containing time series to generate forecasts for. |
h |
Integer. Maximum prediction horizon. Forecasts will be given for
one to |
regularize |
Logical. If |
lag.max |
Maximum lag that the |
forecast.type |
Options are |
... |
Other parameters to be passed to the periodogram and lacv (local autocovariance) estimation, e.g. |
The function calculates the wavelet periodogram followed by the lacv and
lpacf
.
NOTE: Often when local (windowed) estimates are created one assigns the
estimated value to the central point in the window.
This is NOT the approach we take here when calculating the lacv and
lpacf
.
Instead we operate a rear facing window where the estimate is assigned to the
final point in the window.
The lpacf is used to decide the dimension of the local Yule-Walker equations used for forecasting.
The periodogram is then smoothed using a running mean smoother,
and then to get forecast lacv estimates.
The Yule-Walker equations give the forecast mean for h
steps ahead.
The standard deviation of the forecasts is also returned.
When we are trying to forecast h
steps ahead we use the lpacf to decide how many values (p
) we should use for prediction. The original method of Fryzlewicz et al. (2003) decides on p
and then does a h
step ahead forecast only using the p
last values. This is what forecast.type='fixed'
does, regardless of the size of p
in relation to h
. Note that the left hand side of the Yule-Walker matrix is fixed and only the right hand size (the forecast lacv) is changing. Thus the size of h
is not explicitly taken into account, there is just an inflated variance in the lacv estimate.
One other option is to use the intermediate forecast values as if they were observed and perform a recursive forecast - this is what forecast.type='recursive'
does. Here everything in the Yule-Walker equations is different for each forecast value.
A third option is to use forecast.type='fixed'
when p
is greater or equal to h
but then when we are trying to forecast beyond this we extend the Yule-Walker equations to be the same dimension as the forecast horizon. Thus using h
previous values instead of p
. This is what forecast.type='extend'
does.
The method closest to the stationary world is forecast.type='recursive'
.
The dforecastlpacf
internally differences the time series
and then performs the local forecasting as in forecastlpacf
but only for one-step ahead. The advantage is that subsequent plotting
routines can nicely show the original time series, with the forecasts
on the original (not differenced) scale with the forecast and appropriate
confidence interval.
An object of class forecastlpacf
which is a list
with the following components.
mean |
Returns time series forecasts from one to |
std.err |
Returns the prediction error, which can be used for assessing the prediction intervals. Item |
lpacf |
Returns the estimated local partial autocovariance function |
ci |
The confidence interval on lpacf which was used used for the automatic calculation of p |
binwidth |
The automatic bandwidth used for the running mean smoother |
p |
Returns the automatic choice of p - the dimension of the generalized Yule-Walker equations. |
x |
The supplied original time series |
d |
Differencing that was applied to the input series before forecasting.
For |
R. Killick
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
Fryzlewicz, P., Van Bellegem, S. and von Sachs, R. (2003) Forecasting non-stationary time series by wavelet process modelling. Annals of the Institute of Statistical Mathematics, 55, 737-764.
Nason, G.P., von Sachs, R., Kroisandt, G. (2000) Wavelet processes and adaptive estimation of the evolutionary wavelet spectrum. J. Roy. Statist. Soc. B, 62, 271-292.
Xi, Y., Yu, J., Ranneby, B. (2007) Forecasting Using Locally Stationary Wavelet Processes.
lpacf
, forecastpanel
,
plot.forecastlpacf
,
print.forecastlpacf
,
summary.forecastlpacf
# first generate some non-stationary data we want to forecast set.seed(1) x=tvar2sim() #predict 1-step ahead using Daubechies wavelets with 2 vanishing moments, although #other choices for the wavelet family and filter are possible (including Haar) pred<-forecastlpacf(x,h=1,filter.number=2,family="DaubExPhase",forecast.type='recursive') #pred$mean gives the predicted value, while pred$std.err gives the prediction error
# first generate some non-stationary data we want to forecast set.seed(1) x=tvar2sim() #predict 1-step ahead using Daubechies wavelets with 2 vanishing moments, although #other choices for the wavelet family and filter are possible (including Haar) pred<-forecastlpacf(x,h=1,filter.number=2,family="DaubExPhase",forecast.type='recursive') #pred$mean gives the predicted value, while pred$std.err gives the prediction error
This function produces a plot of the data forecast with confidence intervals (if supplied) and, if supplied, against the truth. Optionally, summaries of the forecast fit are returned.
forecastpanel(forecastobj,truth=NULL,add=FALSE,summary=TRUE,test="all",move=0, conf.level=95,col="red",pch=c(17,19,95),...)
forecastpanel(forecastobj,truth=NULL,add=FALSE,summary=TRUE,test="all",move=0, conf.level=95,col="red",pch=c(17,19,95),...)
forecastobj |
Either an object of class |
truth |
The true values of the signal that has been forecast. |
add |
If FALSE a new plot is created, otherwise points are added to the active graphics device. |
summary |
If TRUE a summary of the forecast fit is supplied, see |
test |
Argument supplied to |
move |
If move does not equal 0 then this is the amount to move the points+confidence intervals for the forecasts to the left (if negative) and to the right (if positive) to offset the plotted location (0) to potentially make the graphic clearer. |
conf.level |
Confidence level used for the |
col |
Specifies the colour of forecasts on the plot, see |
pch |
Length 3 vector specifying the plotting character (pch) of the truth, forecast and CI in that order. |
... |
Additional arguments can be supplied which will be passed to |
Plots the forecast data, confidence intervals and true signal if supplied. If summary=TRUE
then the output of accuracy
is returned.
If summary=TRUE
then the output of accuracy
is returned.
Rebecca Killick
# first generate a time-varying process x=tvar2sim() # forecast the last 12 data points using the lpacf ans<-forecastlpacf(x[1:500],h=12,forecast.type='recursive') # then plot it and get summaries to see how we did ## Not run: plot(ans,truth=x[501:512],move=0.05)
# first generate a time-varying process x=tvar2sim() # forecast the last 12 data points using the lpacf ans<-forecastlpacf(x[1:500],h=12,forecast.type='recursive') # then plot it and get summaries to see how we did ## Not run: plot(ans,truth=x[501:512],move=0.05)
This function merely wraps some excellent functions from the forecast package up and returns the forecast values and their lower and upper prediction intervals.
fp.forecast(x, h = 1, conf.level = 95)
fp.forecast(x, h = 1, conf.level = 95)
x |
The time series you wish to forecast. |
h |
The number of steps ahead (forecast horizon) |
conf.level |
The confidence level for the forecast prediction interval expressed as a value between 0 and 100. |
This function entirely relies on existing functions from
the forecast package. It applies auto.arima
to x
to fit an ARIMA model to the series with an automatic choice
of parameters. Then the forecast
function is applied
to the ARIMA object to obtain forecasts and prediction intervals.
A matrix with h
rows and three columns. The first column
contains the forecasted values. The second and third columns
contrain the lower and upper prediction intervals.
G.P. Nason
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
Hyndman, R.J. and Khandakar, Y. (2008) Automatic Time Series Forecasting: The forecast package for R. Journal of Statistical Software, 27, Issue 3.
# # Generate random test series # x.test <- tvar2sim() # # Produce stationary Box-Jenkins forecasts and prediction intervals for # two-steps ahead # fp.forecast(x.test, h=2)
# # Generate random test series # x.test <- tvar2sim() # # Produce stationary Box-Jenkins forecasts and prediction intervals for # two-steps ahead # fp.forecast(x.test, h=2)
forecastlpacf
The forecastlpacf
performs forecasting on
a locally stationary (wavelet) time series. This function
provides several options to plot the results in a user-friendly
fashion.
## S3 method for class 'forecastlpacf' plot(x, extra.y = NULL, f.col = 4, show.pi = "standard", pi.col = 2, xlab = "Time", ylab = "Time Series", zoom = FALSE, zoom.no = 30, sw = 0.2, conf.level = 95, pc.fan = (1:9) * 10, fan.seps = FALSE, fan.rgb.col=c(1,0,0), ...)
## S3 method for class 'forecastlpacf' plot(x, extra.y = NULL, f.col = 4, show.pi = "standard", pi.col = 2, xlab = "Time", ylab = "Time Series", zoom = FALSE, zoom.no = 30, sw = 0.2, conf.level = 95, pc.fan = (1:9) * 10, fan.seps = FALSE, fan.rgb.col=c(1,0,0), ...)
x |
The object returned by the |
extra.y |
Sometimes other routines wish to add to the plot generated by this function. The y-axis extent of those extra values might be larger than the values that this plot alone would generate. So, you can use this argument to provide a set of y-values that you want to later plot and this plot takes those into account when setting the scale of the y-axis. So, if you have extra characters or lines to plot after this plot, and you want to ensure they'll get plotted and that the y-axis is going to be large enough, supply the y values as a vector (or just their maximum and minimum) and this function will use them to help set the y-axis scale. |
f.col |
The colour used to drae the forecasted values - both the points and line joining the forecasts. |
show.pi |
If set to "standard" then 100*conf.level percent prediction
intervals are drawn for each forecasted point in the colour specified
by |
pi.col |
Colour of the prediction intervals or fan plot. |
xlab |
The x-axis label. |
ylab |
The y-axis label. |
zoom |
Sometimes for a long time series with a few forecasts the
forecast values can be hard to see and particularly how they relate
to the values of the series near to the end of the series. If
|
zoom.no |
The number of time series values plotted if |
sw |
The width of the prediction intervals if |
conf.level |
A single confidence value associated with the prediction interval expressed as a numerical value from 0-100. |
pc.fan |
A vector of confidence values associated with the fan plot prediction intervals expressed as a percentage. |
fan.seps |
If |
fan.rgb.col |
A vector of length three containing the red, green and blue intensities of the fan plot colour |
... |
Other arguments to plot. |
This function produces a plot of a time series and its forecasts
generated by the forecastlpacf
function.
The function only returns information if show.pi="fan"
.
In this case an array is returned that contained the coordinates
of the fan part of the plot. The array is three-dimensional.
Dimension 1 corresponds to the number of steps ahead that we computed
for the forecast in the object x
, dimension 2 corresponds to
the number of fan prediction intervals specified by the number of
confidence bands in pc.fan
, dimension 3 always has two
dimensions: 1 corresponding to the upper prediction interval and
2 correspond to the lower interval. For example, element[2, 3, 1]
corresponds to the upper prediction interval, for the fan component
associated with the third fan confidence level value in pc.fan
for the h=2
step ahead forecast.
Guy Nason
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
# # Simulate an example # x.test <- tvar2sim() # # Do a two-step ahead forecast # x.fl <- forecastlpacf(x.test, h=2, forecast.type="recursive") # # Now plot it. # # zoom=TRUE: so we only plot the last 30 time series observations, by default # change zoom.no if you want more or less. # f.col=3: the forecasts and connecting lines are drawn in colour 3 (blue) # show.pi="fan": do a fan chart for the forecasts # fan.rgb.col=c(1,0,1): draw the fan in magenta (default is red) # ylab="My Time Series": change the y label to something nice # plot(x.fl,zoom=TRUE, f.col=3, show.pi="fan", fan.rgb.col=c(1,0,1), ylab="My Time Series")
# # Simulate an example # x.test <- tvar2sim() # # Do a two-step ahead forecast # x.fl <- forecastlpacf(x.test, h=2, forecast.type="recursive") # # Now plot it. # # zoom=TRUE: so we only plot the last 30 time series observations, by default # change zoom.no if you want more or less. # f.col=3: the forecasts and connecting lines are drawn in colour 3 (blue) # show.pi="fan": do a fan chart for the forecasts # fan.rgb.col=c(1,0,1): draw the fan in magenta (default is red) # ylab="My Time Series": change the y label to something nice # plot(x.fl,zoom=TRUE, f.col=3, show.pi="fan", fan.rgb.col=c(1,0,1), ylab="My Time Series")
forecastlpacf
object
Prints a forecastlpacf
object, basically telling
you what's there.
## S3 method for class 'forecastlpacf' print(x, ...)
## S3 method for class 'forecastlpacf' print(x, ...)
x |
The |
... |
Other arguments (not used) |
Prints a forecastlpacf
object, basically telling
you what's there.
None.
Guy Nason
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
forecastlpacf
, summary.forecastlpacf
# # Simulate an example # x.test <- tvar2sim() # # Do a two-step ahead forecast # x.fl <- forecastlpacf(x.test, h=2, forecast.type="recursive") # # Print out the object # print(x.fl) # # This is what gets output # #Class 'forecastlpacf' : Forecast from Locally Stationary Time Series: # ~~~~ : List with 8 components with names # mean std.err lpacf ci binwidth p x d # # #summary(.): #---------- #Number of steps ahead predicted: 2 #Predictions are (3dp): 1.52 -0.365 #Std err are (3dp): 0.952 0.955 #Smoothing binwidth was: 293 #Forecast was based on a p-backlag value selected as: 3 #There was no explicit differencing.
# # Simulate an example # x.test <- tvar2sim() # # Do a two-step ahead forecast # x.fl <- forecastlpacf(x.test, h=2, forecast.type="recursive") # # Print out the object # print(x.fl) # # This is what gets output # #Class 'forecastlpacf' : Forecast from Locally Stationary Time Series: # ~~~~ : List with 8 components with names # mean std.err lpacf ci binwidth p x d # # #summary(.): #---------- #Number of steps ahead predicted: 2 #Predictions are (3dp): 1.52 -0.365 #Std err are (3dp): 0.952 0.955 #Smoothing binwidth was: 293 #Forecast was based on a p-backlag value selected as: 3 #There was no explicit differencing.
forecastlpacf
object
Print out summary information about a forecastlpacf
object.
## S3 method for class 'forecastlpacf' summary(object, ...)
## S3 method for class 'forecastlpacf' summary(object, ...)
object |
The object you want to print out summary info for. |
... |
Other arguments |
Prints out the maximum number of steps ahead considered in the object, prints out the first few predictions (up to 6), and their standard errors. The smoothing binwidth associated with the localized partial autocorrelation object used to compute the predictions is printed. The order, p, of the localized partial autocorrelation is printed. A note of whether differencing was actioned is printed.
None
Guy Nason
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
forecastlpacf
, print.forecastlpacf
# # Example for print.forecastlpacf contains a call to summary.forecastlpacf
# # Example for print.forecastlpacf contains a call to summary.forecastlpacf
A good way of evaluating a forecasting method is to
apply the method to most of a series (apart from the last few values)
to forecast those last few values. Then, the forecasts and the true
values can be compared to see how good the forecast is. This function
performs this for the locally stationary forecasting based
on wavelet processes in forecastlpacf
and
a version of the Box-Jenkins forecasting, and also produces
both plots and returns results of the testing.
testforecast(x, n.to.test, go.back=0, plot.it = TRUE, regularize = TRUE, lag.max = max(10, 2 * n.to.test), truth.pch = 23, truth.col = 3, zoom = TRUE, zoom.no = 30, forecast.type = NULL, conf.level = 0.95, stycol = 6, silent = TRUE, lapplyfn=lapply, ...)
testforecast(x, n.to.test, go.back=0, plot.it = TRUE, regularize = TRUE, lag.max = max(10, 2 * n.to.test), truth.pch = 23, truth.col = 3, zoom = TRUE, zoom.no = 30, forecast.type = NULL, conf.level = 0.95, stycol = 6, silent = TRUE, lapplyfn=lapply, ...)
x |
The time series you want to use in testing. |
n.to.test |
Suppose the length of |
go.back |
If |
plot.it |
If |
regularize |
Passed through to |
lag.max |
Passed through to |
truth.pch |
The type of plotting character used for the true
values, see |
truth.col |
Colour of plot symbol used for true values. |
zoom |
Typically, we're interested in the later values of a time
series when doing forecasting. If this argument is |
zoom.no |
If |
forecast.type |
Passed through to |
conf.level |
Controls the width of the prediction intervals for both stationary and nonstationary forecasting. |
stycol |
The colour of both the stationary forecasts and their confidence intervals. |
silent |
If |
lapplyfn |
For single-processor use this argument should
be |
... |
Other arguments to the |
Suppose n.to.test=1
. Then this function uses all the values of
the time series x
apart from the last to generate two forecasts
of the last value. The two methods used to forecast are
the locally stationary method forecastlpacf
and a Box-Jenkins
ARIMA alternative for stationary series coded in fp.forecast
.
Then, if plot.it=TRUE
a plot of the time series x
is produced,
overlaid with both types of forecast and their related prediction intervals
(the locally stationary ones are hached thin rectangles, the stationary
ones indicated by vertical < > symbols. The true value is also indicated
by a character whose visual characteristics are controlled by
the truth.pch
and truth.col
arguments, but by default
are a green diamond.
If n.to.test
is bigger than 1 then all of the data, apart from
the last n.to.test
values are used in constructing the forecasts
(both stationary and locally stationary) for the last n.to.test
values.
Values of the empirical root mean squared error of the two forecast
methods are printed out (unless silent=TRUE
). The predictions
and their standard errors for the n.to.test
values are printed out.
If go.back=0
a matrix with n.to.test
values with four columns is returned. The
first column is the actual true value of the time series in the last
n.to.test
positions. The second and fourth columns are the forecast
values from the locally stationary and stationary methods. The third column
are the locally stationary prediction error values.
If go.back
is a positive integer then a data frame with two
columns. The first column corresponds to stationary forecasting
using the standard Box-Jenkins type method encapsulated by
fp.forecast
. The second column corresponds to
the locally stationary forecasting encapsulated by
forecastlpacf
. Each row of the frame corresponds to
a different forecasting horizon, the horizon is indicated by
the row name of the data frame.
G.P. Nason
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
forecastlpacf
,
fp.forecast
,
plot.forecastlpacf
# # Generate simulated time series from TVAR(2) model. # x.test <- tvar2sim() # # Now run testforecast on this example time series. # We've only supplied plot.it=FALSE because its in an R help page, normally # you would set plot.it=TRUE, which is the default, because you want to see # the plot. # tmp <- testforecast(x.test, n.to.test=3, forecast.type="recursive", plot.it=FALSE)
# # Generate simulated time series from TVAR(2) model. # x.test <- tvar2sim() # # Now run testforecast on this example time series. # We've only supplied plot.it=FALSE because its in an R help page, normally # you would set plot.it=TRUE, which is the default, because you want to see # the plot. # tmp <- testforecast(x.test, n.to.test=3, forecast.type="recursive", plot.it=FALSE)
A big question with many wavelet methods is which wavelet should one use for a particular task. This function tries some forecasting on your time series with all Daubechies compactly supported wavelets available to it and returns a list of the forecasting performance for each choice, and indicates which wavelet gave the best results. This wavelet can then be used in future forecasting.
which.wavelet.best(x, n.to.test = 10, go.back=5, forecast.type = "recursive", lapplyfn = lapply)
which.wavelet.best(x, n.to.test = 10, go.back=5, forecast.type = "recursive", lapplyfn = lapply)
x |
Your times series (not necessarily of dyadic length!) |
n.to.test |
How many observations at the end to test as part of the assessment process. The default, 10, means that 10 observations at the end of the series will all be forecast. This number should be reasonably big to enable forecasts of more than a few data points, but not too large. |
go.back |
Controls the |
forecast.type |
The type of forecasting as detailed in
|
lapplyfn |
Type of list processing function. By default it
uses R's |
This function uses all choices of wavelet to forecast the
last n.to.test
observations of your time series. It
works out the forecasting error in doing so for each choice of
wavelet and returns a list telling you which wavelet did best.
A data frame containing information on the root mean squared forecasting error performance of the locally stationary forecasting method for different wavelets. The data frame has four columns and a row for each wavelet tried. The first and second column give the filter number and family for each wavelet. The third column gives the root mean squared error for each combination of wavelet. The fourth column contains an indicator that shows which wavelet was best (there might be more than one).
Guy Nason
Killick, R., Knight, M.I., Nason, G.P., Nunes M.A., Eckley I.A. (2023) Automatic Locally Stationary Time Series Forecasting with application to predicting U.K. Gross Value Added Time Series under sudden shocks caused by the COVID pandemic arXiv:2303.07772
# # Generate simulated example # x <- tvar2sim() # # Work out which wavelet is best for forecasting this series # # Note: to speed up I also do: # library("parallel") # options(mc.cores=4) # You have a four core machine, eg # tmp <- which.wavelet.best(x, lapplyfn=mclapply) # # Note2: The following command can take a few minutes to run, even on # a fairly recent (2013) machine. You can speed it up by using # parallel execution as noted above, or by reducing go.back or # by reducing n.to.test, and also shortening the time series x to # more recent values. However, you need to be careful if you shorten # x too much then you are not basing the best wavelet decision on the # right time series. Similarly, by reducing go.back you are not # insuring your answer across runs across many internal forecasts. # ## Not run: tmp <- which.wavelet.best(x) # # Print out what the result was: # ## Not run: print(tmp) # filter.number family mse min.mse #1 1 DaubExPhase 0.2139173 <- Min MSE #2 2 DaubExPhase 0.5040532 #3 3 DaubExPhase 0.4064091 #4 4 DaubExPhase 0.3077695 #5 5 DaubExPhase 0.3706422 #6 6 DaubExPhase 0.6617254 #7 7 DaubExPhase 0.5477581 #8 8 DaubExPhase 0.6881407 #9 9 DaubExPhase 0.5514298 #10 10 DaubExPhase 0.5551846 #11 4 DaubLeAsymm 0.3134285 #12 5 DaubLeAsymm 0.3910101 #13 6 DaubLeAsymm 0.7480980 #14 7 DaubLeAsymm 0.5700830 #15 8 DaubLeAsymm 0.5661297 #16 9 DaubLeAsymm 0.5689345 #17 10 DaubLeAsymm 0.5580267
# # Generate simulated example # x <- tvar2sim() # # Work out which wavelet is best for forecasting this series # # Note: to speed up I also do: # library("parallel") # options(mc.cores=4) # You have a four core machine, eg # tmp <- which.wavelet.best(x, lapplyfn=mclapply) # # Note2: The following command can take a few minutes to run, even on # a fairly recent (2013) machine. You can speed it up by using # parallel execution as noted above, or by reducing go.back or # by reducing n.to.test, and also shortening the time series x to # more recent values. However, you need to be careful if you shorten # x too much then you are not basing the best wavelet decision on the # right time series. Similarly, by reducing go.back you are not # insuring your answer across runs across many internal forecasts. # ## Not run: tmp <- which.wavelet.best(x) # # Print out what the result was: # ## Not run: print(tmp) # filter.number family mse min.mse #1 1 DaubExPhase 0.2139173 <- Min MSE #2 2 DaubExPhase 0.5040532 #3 3 DaubExPhase 0.4064091 #4 4 DaubExPhase 0.3077695 #5 5 DaubExPhase 0.3706422 #6 6 DaubExPhase 0.6617254 #7 7 DaubExPhase 0.5477581 #8 8 DaubExPhase 0.6881407 #9 9 DaubExPhase 0.5514298 #10 10 DaubExPhase 0.5551846 #11 4 DaubLeAsymm 0.3134285 #12 5 DaubLeAsymm 0.3910101 #13 6 DaubLeAsymm 0.7480980 #14 7 DaubLeAsymm 0.5700830 #15 8 DaubLeAsymm 0.5661297 #16 9 DaubLeAsymm 0.5689345 #17 10 DaubLeAsymm 0.5580267
This dataset gives the monthly ENSO meridional wind anomaly index for the region 12-2N, 160E-80W from January 1900 until June 2005.
data("windanomaly")
data("windanomaly")
A vector of wind anomalies with length 1266.
http://jisao.washington.edu/data_sets/eqpacmeridwindts/