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