Learn R Programming

forecastSNSTS (version 1.3-0)

measure-of-accuracy: Mean squared or absolute \(h\)-step ahead prediction errors

Description

The function MSPE computes the empirical mean squared prediction errors for a collection of \(h\)-step ahead, linear predictors (\(h=1,\ldots,H\)) of observations \(X_{t+h}\), where \(m_1 \leq t+h \leq m_2\), for two indices \(m_1\) and \(m_2\). The resulting array provides $$\frac{1}{m_{\rm lo} - m_{\rm up} + 1} \sum_{t=m_{\rm lo}}^{m_{\rm up}} R_{(t)}^2,$$ with \(R_{(t)}\) being the prediction errors $$R_t := | X_{t+h} - (X_t, \ldots, X_{t-p+1}) \hat v_{N,T}^{(p,h)}(t) |,$$ ordered by magnitude; i.e., they are such that \(R_{(t)} \leq R_{(t+1)}\). The lower and upper limits of the indices are \(m_{\rm lo} := m_1-h + \lfloor (m_2-m_1+1) \alpha_1 \rfloor\) and \(m_{\rm up} := m_2-h - \lfloor (m_2-m_1+1) \alpha_2 \rfloor\). The function MAPE computes the empirical mean absolute prediction errors $$\frac{1}{m_{\rm lo} - m_{\rm up} + 1} \sum_{t=m_{\rm lo}}^{m_{\rm up}} R_{(t)},$$ with \(m_{\rm lo}\), \(m_{\rm up}\) and \(R_{(t)}\) defined as before.

Usage

MSPE(X, predcoef, m1 = length(X)/10, m2 = length(X), P = 1, H = 1,
  N = c(0, seq(P + 1, m1 - H + 1)), trimLo = 0, trimUp = 0)

MAPE(X, predcoef, m1 = length(X)/10, m2 = length(X), P = 1, H = 1, N = c(0, seq(P + 1, m1 - H + 1)), trimLo = 0, trimUp = 0)

Arguments

X

the data \(X_1, \ldots, X_T\)

predcoef

the prediction coefficients in form of a list of an array coef, and two integer vectors t and N. The two integer vectors provide the information for which indices \(t\) and segment lengths \(N\) the coefficients are to be interpreted; (m1-H):(m2-1) has to be a subset of predcoef$t. if not provided the necessary coefficients will be computed using predCoef.

m1

first index from the set in which the indices \(t+h\) shall lie

m2

last index from the set in which the indices \(t+h\) shall lie

P

maximum order of prediction coefficients to be used; must not be larger than dim(predcoef$coef)[1].

H

maximum lead time to be used; must not be larger than dim(predcoef$coef)[3].

N

vector with the segment sizes to be used, 0 corresponds to using 1, ..., t; has to be a subset of predcoef$N.

trimLo

percentage \(\alpha_1\) of lower observations to be trimmed away

trimUp

percentage \(\alpha_2\) of upper observations to be trimmed away

Value

MSPE returns an object of type MSPE that has mspe, an array of size H\(\times\)P\(\times\)length(N), as an attribute, as well as the parameters N, m1, m2, P, and H. MAPE analogously returns an object of type MAPE that has mape and the same parameters as attributes.

Examples

Run this code
# NOT RUN {
T <- 1000
X <- rnorm(T)
P <- 5
H <- 1
m <- 20
Nmin <- 20
pcoef <- predCoef(X, P, H, (T - m - H + 1):T, c(0, seq(Nmin, T - m - H, 1)))

mspe <- MSPE(X, pcoef, 991, 1000, 3, 1, c(0, Nmin:(T-m-H)))

plot(mspe, vr = 1, Nmin = Nmin)
# }

Run the code above in your browser using DataLab