testforecast {forecastLSW}R Documentation

Compare locally stationary forecasting with Box-Jenkins-type forecasting, by predicting the final values of a time series.

Description

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.

Usage

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, ...)

Arguments

x

The time series you want to use in testing.

n.to.test

Suppose the length of x is T. This function uses the first T-n.to.test observations to predict the last n.to.test observations.

go.back

If go.back=0 then a single forecasting operation forecasting the last n.to.test observations from the previous data is conducted. If go.back is an integer greater than zero then the same forecasting as with go.back occurs but each time the end of the series is moved back one point. This shifting back occurs from one shift to go.back shifts. The purpose of this is to repeat the exercise for using previous data to forecast n.to.test points at the end of the series, but to then repeat this for the series one step earlier, then two steps earlier, ..., back to go.back steps earlier. The results of each forecast are combined into an overall root-mean-squared error result for each forecast horizon (there will be n.to.test values) for both of the Box-Jenkins and the new forecast methodology provided by forecastlpacf. These additionally forecasts will be computed in parallel if the parallel package is loaded and mclapply is used as an argument to lapplyfn.

plot.it

If TRUE a plot is produced showing the original time series, the stationary and locally stationary forecasts, and their prediction intervals. If FALSE then no plot is produced.

regularize

Passed through to forecastlpacf

lag.max

Passed through to forecastlpacf

truth.pch

The type of plotting character used for the true values, see pch argument to points function in R.

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 TRUE then only the last zoom.no observations are plotted, so one can focus on the end of the series.

zoom.no

If zoom=TRUE then this argument controls how much of the end of the series is plotted.

forecast.type

Passed through to forecastlpacf

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 TRUE then nothing gets printed, otherwise messages get printed.

lapplyfn

For single-processor use this argument should be lapply (the default). However, you can set the argument to mclapply if you have the parallel package loaded. Remember to set the number of processors you want to use with the mc.cores option, e.g. options(mc.cores=4) if you had four cores available.

...

Other arguments to the forecastlpacf call

Details

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.

Value

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.

Author(s)

G.P. Nason

References

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

See Also

forecastlpacf, fp.forecast, plot.forecastlpacf

Examples

#
# 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)

[Package forecastLSW version 1.0 Index]