Learn R Programming

tsgc (version 0.0)

FilterResults-class: FilterResults

Description

Class for estimated Dynamic Gompertz Curve model and contains methods to extract smoothed/filtered estimates of the states, the level of the incidence variable \(y\), and forecasts of \(y\).

Arguments

Methods

get_growth_y(smoothed = FALSE, return.components = FALSE)

Returns the growth rate of the incidence (\(y\)) of the cumulated variable (\(Y\)). Computed as $$g_t = \exp\{\delta_t\}+\gamma_t.$$

Parameters

  • smoothed Logical value indicating whether to use the smoothed estimates of \(\delta\) and \(\gamma\) to compute the growth rate (TRUE), or the contemporaneous filtered estimates (FALSE). Default is FALSE.

  • return.components Logical value indicating whether to return the estimates of \(\delta\) and \(\gamma\) as well as the estimates of the growth rate, or just the growth rate. Default is FALSE.

Return Value

xts object containing smoothed/filtered growth rates and components (\(\delta\) and \(\gamma\)), where applicable.

get_gy_ci(smoothed = FALSE, confidence_level = 0.68)

Returns the growth rate of the incidence (\(y\)) of the cumulated variable (\(Y\)). Computed as $$g_t = \exp\{\delta_t\}+\gamma_t.$$

Parameters

  • smoothed Logical value indicating whether to use the smoothed estimates of \(\delta\) and \(\gamma\) to compute the growth rate (TRUE), or the contemporaneous filtered estimates (FALSE). Default is FALSE.

  • confidence_level Confidence level for the confidence interval. Default is \(0.68\), which is one standard deviation for a normally distributed random variable.

Return Value

xts object containing smoothed/filtered growth rates and upper and lower bounds for the confidence intervals.

predict_all(n.ahead, sea.on = FALSE, return.all = FALSE)

Returns forecasts of the incidence variable \(y\), the state variables and the conditional covariance matrix for the states.

Parameters

  • n.ahead The number of forecasts you wish to create from the end of your sample period.

  • sea.on Logical value indicating whether seasonal components should be included in the state-space model or not. Default is TRUE.

  • return.all Logical value indicating whether to return all filtered estimates and forecasts (TRUE) or only the forecasts (FALSE). Default is FALSE.

Return Value

xts object containing the forecast (and filtered, where applicable) level of \(y\) (y.hat), \(\delta\) (level.t.t), \(\gamma\) (slope.t.t), vector of states including the seasonals where applicable (a.t.t) and covariance matrix of all states including seasonals where applicable (P.t.t).

predict_level( y.cum, n.ahead, confidence_level, sea.on = FALSE, return.diff = FALSE )

Forecast the cumulated variable or the incidence of it. This function returns the forecast of the cumulated variable \(Y\), or the forecast of the incidence of the cumulated variable, \(y\). For example, in the case of an epidemic, \(y\) might be daily new cases of the disease and \(Y\) the cumulative number of recorded infections.

Parameters

  • y.cum The cumulated variable.

  • n.ahead The number of periods ahead you wish to forecast from the end of the estimation window.

  • confidence_level The confidence level for the log growth rate that should be used to compute the forecast intervals of \(y\).

  • return.diff Logical value indicating whether to return the cumulated variable, \(Y\), or the incidence of it, \(y\) (i.e., the first difference of the cumulated variable). Default is FALSE.

Return Value

xts object containing the point forecasts and upper and lower bounds of the forecast interval.

print_estimation_results()

Prints a table of estimated parameters in a format ready to paste into LaTeX.

References

Harvey, A. C. and Kattuman, P. (2021). A Farewell to R: Time Series Models for Tracking and Forecasting Epidemics, Journal of the Royal Society Interface, vol 18(182): 20210179

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()
# Print estimation results
res$print_estimation_results()
# Forecast 7 days ahead from the end of the estimation window
res$predict_level(y.cum = gauteng[idx.est], n.ahead = 7,
  confidence_level = 0.68)
# Forecast 7 days ahead from the model and return filtered states
res$predict_all(n.ahead = 7, return.all = TRUE)
# Return the filtered growth rate and its components
res$get_growth_y(return.components = TRUE)
# Return smoothed growth rate of incidence variable and its confidence
# interval
res$get_gy_ci(smoothed = TRUE, confidence_level = 0.68)

Run the code above in your browser using DataLab