Learn R Programming

tsgc (version 0.0)

plot_holdout: Plots the forecast of new cases (the difference of the cumulated variable) over a holdout sample.

Description

Plots actual values of the difference in the cumulated variable, the forecasts of the cumulated variable (both including and excluding the seasonal component, where a seasonal is specified) and forecast intervals around the forecasts, plus the actual outcomes from the holdout sample. The forecast intervals are based on the prediction intervals for \(\ln(g_t)\). Also reports the mean absolute percentage prediction error over the holdout sample.

Usage

plot_holdout(
  res,
  Y,
  Y.eval,
  confidence.level = 0.68,
  date_format = "%Y-%m-%d",
  series.name = NULL,
  title = NULL,
  caption = NULL
)

Value

A ggplot2 plot.

Arguments

res

Results object estimated using the estimate() method.

Y

Values of the cumulated variable to be used in the estimation window.

Y.eval

Values of the cumulated variable to be used in the holdout sample (i.e. to which the forecasts should be compared to).

confidence.level

Width of prediction interval for \(\ln(g_t)\) to use in forecasts of \(y_t = \Delta Y_t\). Default is 0.68, which is approximately one standard deviation for a Normal distribution.

date_format

Date format, e.g. '%Y-%m-%d', which is the default.

series.name

Name of the variable you are forecasting for the purposes of a $y$-axis label. E.g. if series.name = "Cases" the \(y\)-axis will show "New Cases".

title

Title for forecast plot. Enter as text string. NULL (i.e. no title) by default.

caption

Caption for forecast plot. Enter as text string. NULL (i.e. no caption) by default.

Examples

Run this code
library(tsgc)
data(gauteng,package="tsgc")
idx.est <- zoo::index(gauteng) <= as.Date("2020-07-20")
idx.eval <- (zoo::index(gauteng) >= as.Date("2020-07-20")) &
     zoo::index(gauteng) <= as.Date("2020-07-27")

# Specify a model
model <- SSModelDynamicGompertz$new(Y = gauteng[idx.est], q = 0.005)
# Estimate a specified model
res <- model$estimate()

# Plot forecasts and outcomes over evaluation period
plot_holdout(res = res, Y = gauteng[idx.est], Y.eval = gauteng[idx.eval])

Run the code above in your browser using DataLab