error_measures: Functions to calculate the forecast errors.

Description Usage Arguments Details Value Functions Examples

View source: R/error_measures.R

Description

error_measures returns the forecast errors for the following error measures: MSE, MAD, sMAPE, MASE, and OWA.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
error_measures(
  forecasts,
  outsample,
  insample = NULL,
  ts.frequency,
  forecast.horizon,
  alpha.level = 0.05,
  error.measure = NULL
)

measure_MSE(forecasts, outsample)

measure_MAD(forecasts, outsample)

measure_SMAPE(forecasts, outsample)

measure_MASE(forecasts, outsample, insample)

measure_OWA(
  forecasts,
  outsample,
  insample,
  forecast.horizon,
  alpha.level,
  ts.frequency
)

Arguments

forecasts

A numeric vector with the point forecasts.

outsample

A numeric vector with the test data set.

insample

A numeric vector with the training data set.

ts.frequency

The frequency of a ts object.

forecast.horizon

A numeric value with the length of the forecast lead.

alpha.level

A numeric value with the alpha level to be used in the test to detect seasonality. Default is 0.05.

error.measure

Error measure to be used when calculating the in-sample prediction errors.

Details

These can be 'mse', 'mad', 'smape', 'mase', and 'owa' (see Details).

Value

A 5-object list with the numeric values of the forecast error for each one of the error measures.

Functions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Using NAIVE2:
# Observations until the 100th will be in the insample (train) data set.
tmp.cut.at <- 100

tmp.forecast.horizon <- length(datasets::AirPassengers) - tmp.cut.at

tmp.orig.start <- stats::tsp(datasets::AirPassengers)[1]
tmp.orig.end   <- stats::tsp(datasets::AirPassengers)[2]
tmp.orig.freq  <- stats::tsp(datasets::AirPassengers)[3]


# Get train data (insample)

tmp.train.start <- tmp.orig.start
tmp.train.end   <- tmp.orig.start + ((tmp.cut.at - 1) * 1 / tmp.orig.freq)

tmp.train.data  <- stats::window(
  x         = datasets::AirPassengers,
  start     = tmp.train.start,
  end       = tmp.train.end,
  frequency = tmp.orig.freq
)

# Get test data (outsample)

tmp.test.start <- tmp.orig.start + (tmp.cut.at * 1 / tmp.orig.freq)
tmp.test.end   <- tmp.orig.end

tmp.test.data  <- stats::window(
  x         = datasets::AirPassengers,
  start     = tmp.test.start,
  end       = tmp.test.end,
  frequency = tmp.orig.freq
)

# Get Forecasts
tmp.forecasts <- gears::forecast_naive2(
  ts.data          = tmp.train.data,
  ts.frequency     = tmp.orig.freq,
  forecast.horizon = tmp.forecast.horizon,
  alpha.level      = 0.05
)

# Get error measures for the forecast
error_measures(
  forecasts          = tmp.forecasts,
  outsample          = tmp.test.data,
  insample           = tmp.train.data,
  ts.frequency       = tmp.orig.freq,
  forecast.horizon   = tmp.forecast.horizon,
  alpha.level        = 0.05,
  error.measure      = "mse"
)

gu-stat/gears documentation built on Oct. 20, 2021, 2:53 a.m.