basicf: Basic forecasting (mean, median, random walk)

View source: R/basic.R

basicfR Documentation

Basic forecasting (mean, median, random walk)

Description

Basic forecasting functions for multivariate time series

Usage

basicf(
  y,
  h = 5,
  level = 95,
  method = c("mean", "median", "rw"),
  type_pi = c("gaussian", "bootstrap", "blockbootstrap", "movingblockbootstrap"),
  block_length = NULL,
  seed = 1,
  B = 100,
  show_progress = TRUE
)

Arguments

y

A multivariate time series of class ts or a matrix

h

Forecasting horizon

level

Confidence level for prediction intervals

method

forecasting method, either "mean", "median", or random walk ("rw")

type_pi

type of prediction interval currently, "gaussian", "bootstrap", "blockbootstrap" or "movingblockbootstrap"

block_length

length of block for (circular) "blockbootstrap" or "movingblockbootstrap"

seed

reproducibility seed for type_pi == 'bootstrap'

B

Number of bootstrap replications for type_pi == 'bootstrap'

show_progress

A boolean; show progress bar for bootstrapping? Default is TRUE.

Value

An object of class "mtsforecast"; a list containing the following elements:

method

The name of the forecasting method as a character string

mean

Point forecasts for the time series

lower

Lower bound for prediction interval

upper

Upper bound for prediction interval

sims

Model simulations for bootstrapping (basic, or block)

x

The original time series

residuals

Residuals from the fitted model

coefficients

Regression coefficients for type_pi == 'gaussian' for now

Examples


require(fpp)

res <- ahead::basicf(fpp::insurance, h=10)
par(mfrow=c(1, 2))
plot(res, "TV.advert")
plot(res, "Quotes")


res <- ahead::basicf(fpp::insurance, method="rw", h=10)
par(mfrow=c(1, 2))
plot(res, "TV.advert")
plot(res, "Quotes")


# block bootstrap
res3 <- ahead::basicf(fpp::insurance, h=10, type_pi = "bootstrap", B=10)
res5 <- ahead::basicf(fpp::insurance, h=10, type_pi = "blockbootstrap", B=10,
                      block_length = 4)

print(res3$sims[[2]])
print(res5$sims[[2]])

par(mfrow=c(2, 2))
plot(res3, "Quotes")
plot(res3, "TV.advert")
plot(res5, "Quotes")
plot(res5, "TV.advert")


# moving block bootstrap
res6 <- ahead::basicf(fpp::insurance, h=10,
                      type_pi = "movingblockbootstrap", B=10,
                      block_length = 4, method = "rw")

par(mfrow=c(1, 2))
plot(res6, "Quotes")
plot(res6, "TV.advert")


Techtonique/ahead documentation built on Nov. 24, 2024, 10:33 a.m.