Learn R Programming

tsgc (version 0.0)

plot_forecast: Plots forecast and realised values of the log cumulative growth rate

Description

Plots actual and filtered values of the log cumulative growth rate (\(\ln(g_t)\)) in the estimation sample and the forecast and realised log cumulative growth rate out of the estimation sample.

Usage

plot_forecast(
  res,
  y.eval,
  n.ahead = 14,
  plt.start.date = NULL,
  title = "",
  caption = ""
)

Value

A ggplot2 plot.

Arguments

res

Results object estimated using the estimate() method.

y.eval

The out-of-sample realisation of the log growth rate of the cumulated variable (i.e. the actual values to which the forecasts should be compared).

n.ahead

The number of time periods ahead from the end of the sample to be forecast. The default is 14.

plt.start.date

Plot start date. Default is NULL which is the start of the estimation sample.

title

Plot title. Enter as text string.

caption

Plot caption. Enter as text string.

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 forecast and realised log growth rate of cumulative cases
plot_forecast(res, y.eval = df2ldl(gauteng[idx.eval]), n.ahead = 7,
  title = "Forecast ln(g)", plt.start.date = as.Date("2020-07-13"))

Run the code above in your browser using DataLab