Learn R Programming

autostsm (version 1.1)

stsm_forecast: Kalman Filter and Forecast

Description

Kalman filter and forecast an estimated model from stsm_estimate output

Usage

stsm_forecast(
  model,
  y,
  n.ahead = 0,
  freq = NULL,
  exo = NULL,
  exo.fc = NULL,
  ci = 0.8,
  plot = FALSE,
  plot.decomp = FALSE,
  plot.fc = FALSE,
  n.hist = NULL,
  smooth = TRUE,
  dampen_cycle = FALSE
)

Arguments

model

Structural time series model estimated using stsm_estimate.

y

Univariate time series of data values. May also be a 2 column data frame containing a date column.

n.ahead

the number of periods to forecast

freq

Frequency of the data (1 (yearly), 4 (quarterly), 12 (monthly), 365.25/7 (weekly), 365.25 (daily)), default is NULL and will be automatically detected

exo

Matrix of exogenous variables used for the historical data. Can be used to specify regression effects or other seasonal effects like holidays, etc.

exo.fc

Matrix of exogenous variables used for the forecast

ci

Confidence interval, value between 0 and 1 exclusive.

plot,

Logical, whether to plot everything

plot.decomp

Logical, whether to plot the filtered historical data

plot.fc

Logical, whether to plot the forecast

n.hist

Number of historical periods to include in the forecast plot. If plot = TRUE and n.hist = NULL, defaults to 3 years.

smooth

Whether or not to use the Kalman smoother

dampen_cycle

Whether to remove oscillating cycle dynamics and smooth the cycle forecast into the trend using a sigmoid function that maintains the rate of convergence

Value

data table (or list of data tables) containing the filtered and/or smoothed series.

Examples

Run this code
# NOT RUN {
#GDP Not seasonally adjusted
library(autostsm)
data("NA000334Q", package = "autostsm") #From FRED
NA000334Q = data.table(NA000334Q, keep.rownames = TRUE)
colnames(NA000334Q) = c("date", "y")
NA000334Q[, "date" := as.Date(date)]
NA000334Q[, "y" := as.numeric(y)]
NA000334Q = NA000334Q[date >= "1990-01-01", ]
stsm = stsm_estimate(NA000334Q)
fc = stsm_forecast(stsm, y = NA000334Q, n.ahead = floor(stsm$freq)*3, plot = TRUE)
# }

Run the code above in your browser using DataLab