Learn R Programming

tsgc (version 0.0)

plot_new_cases: Plots the forecast of new cases (the difference of the cumulated variable)

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. The forecast intervals are based on the prediction intervals for \(\ln(g_t)\).

Usage

plot_new_cases(
  res,
  Y,
  n.ahead,
  confidence.level = 0.68,
  date_format = "%Y-%m-%d",
  title = NULL,
  plt.start.date = NULL
)

Value

A ggplot2 plot.

Arguments

res

Results object estimated using the estimate() method.

Y

Cumulated variable.

n.ahead

Number of forecasts (i.e. number of periods ahead to forecast from end of estimation window).

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. Default is '%Y-%m-%d'.

title

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

plt.start.date

First date of actual data (from estimation sample) to plot on graph.NULL (i.e. plots all data in estimation window) by default.

Examples

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

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

# Plot forecast of new cases 7 days ahead
plot_new_cases(res, Y = gauteng[idx.est], n.ahead = 7,
confidence.level = 0.68, date_format = "%Y-%m-%d",
title = "Forecast new cases", plt.start.date = as.Date("2020-07-13"))

Run the code above in your browser using DataLab