future: Future forecasting procedure

Description Usage Arguments Value Author(s) Examples

View source: R/analysis.R

Description

Take fitted ARIMA model and forecast future values. If the realization of future values are given, it also computes prediction diagnostics. For prediction, it supports two methods: One-shot prediction predicts all future values only using the given model. One-step prediction predicts one step ahead and refit the model with the realized future value for the next prediction. As noticed, for one-step prediction user must provide realized future values.

Usage

1
2
3
4
5
6
7
8
future(
  fit,
  ndays = 30,
  method = c("one-shot", "one-step"),
  ...,
  real = NULL,
  plot = TRUE
)

Arguments

fit

Fitted ARIMA model(ARIMA object) which will be used for forecasting.

ndays

The number of days to be forecasted. (default = 30)

method

Method of prediction. Should be one of "one-shot" or "one-step". (default = "one-shot")

...

Extra parameters for SARIMA fitting. Refer to Arima.

real

Realizations of future values. This parameter is mandatory for one-step forecasting, while it is only optional for one-shot forecasting. Also, for one-step forecasting, the number of realized future values must be greater than ndays. It should be either ts object or numeric vector. (default = NULL)

plot

If TRUE, the predicted future values will be plotted with 95% and 80% CI, some of the past observations, and future realizations if given. Otherwise, not. (default = TRUE)

Value

A list containing the following elements:

mean Predicted future values.
CI Data frame holding lower and upper bounds of 80% and 95% CI.
statistics A numeric vector holding prediction diagnostics, RMSE(Root Mean Square Error) and MAE(Mean Absolute Error). If the number of predicted future values and the number of given future realizations differ, it just ignores extra information in the longer one. (Returned only if real is given.)
plot ggplot object of the plot. (Returned only if plot is TRUE.)

Author(s)

Sanghyun Park, Daun Jeong, and Sehun Kim

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 228 is the station code for SNU
# We want to predict the last 100 total count of passengers
data <- get.subway(228)
obs <- data$total[1:(nrow(data) - 100)]
real <- data$total[(nrow(data) - 99):nrow(data)]

# Fit SARIMA model
fit <- auto.arima(ts(obs, frequency = 7))

# One-shot prediction
future(fit, ndays = 100, method = "one-shot", real = real)

# One-step prediction
future(fit, ndays = 100, method = "one-step", real = real)

eik4862/Subway documentation built on Sept. 24, 2021, 3:39 a.m.