thetaModels: Theta Models

Theta ModelsR Documentation

Theta Models

Description

Functions for forecast univariate time series using the Dynamic Optimised Theta Model, Dynamic Standard Theta Model, Optimised Theta Model and Standard Theta Model (Fiorucci et al, 2016). We also provide an implementation for the Standard Theta Method (STheta) of Assimakopoulos and Nikolopoulos (2000).

Usage

dotm(y, h=5, level=c(80,90,95),	s_type="multiplicative", s_test="default",
  	lambda=NULL, par_ini=c(y[1]/2, 0.5, 2),	estimation=TRUE,
  	lower=c(-1e+10, 0.1, 1.0), upper=c(1e+10, 0.99, 1e+10),
  	opt.method="Nelder-Mead", xreg=NULL, s=NULL)

dstm(y, h=5, level=c(80,90,95), s_type="multiplicative", s_test="default",
  	lambda=NULL, par_ini=c(y[1]/2, 0.5), estimation=TRUE,
  	lower=c(-1e+10, 0.1), upper=c(1e+10, 0.99),
  	opt.method="Nelder-Mead", xreg=NULL, s=NULL)

otm(y, h=5, level=c(80,90,95), s_type="multiplicative", s_test="default",
  	lambda=NULL, par_ini=c(y[1]/2, 0.5, 2), estimation=TRUE,
  	lower=c(-1e+10, 0.1, 1.0), upper=c(1e+10, 0.99, 1e+10),
  	opt.method="Nelder-Mead", xreg=NULL, s=NULL)

stm(y, h=5, level=c(80,90,95), s_type="multiplicative", s_test="default",
  	lambda=NULL, par_ini=c(y[1]/2, 0.5), estimation=TRUE,
  	lower=c(-1e+10, 0.1), upper=c(1e+10, 0.99),
  	opt.method="Nelder-Mead", xreg=NULL, s=NULL)

stheta(y, h=5, s_type="multiplicative", s_test="default", s=NULL)

Arguments

y

Object of time series class.

h

Number of required forecasting periods.

level

Levels for prediction intervals.

s_type

Use "multiplicative" for the classic multiplicative seasonal decomposition, "additive" for the classic additive seasonal decomposition and "stl" for the STL decomposition (in this case, forecast::mstl is considered).

s_test

If TRUE, seasonal decomposition is used. If FALSE, seasonal decomposition is not used. If default, the time series is tested for statistically seasonal behaviour. If uni_root, then first a difference is taken if a unit root is detected.

lambda

Parameter for Box-Cox transformation (forecast::BoxCox is considered). If lambda=NULL, then it is ignored. If lambda="auto", then this parameter is automatically selected (see forecast::BoxCox.lambda()). Furthermore, lambda=0 corresponds to the logarithmic transformation, which can be used to get strictly positive forecasts.

par_ini

Vector of initialization for (ell, alpha, theta) parameters.

estimation

If TRUE, the optim() function is consider for compute the minimum square estimator of parameters. If FALSE, the models/methods are computed for par_ini values.

lower

The lower limit of parametric space.

upper

The upper limit of parametric space.

opt.method

The numeric optimisation method for optim() function. Choose one among 'Nelder-Mead', 'L-BFGS-B', 'SANN'.

xreg

A matrix with the regressor variables including the out-of-sample data.

s

The argument s is deprecated and has been replaced by s_type and s_test for improved functionality and clarity. While s is still supported in this version for backward compatibility, it may be removed in future releases. Users are strongly encouraged to update their code accordingly.

Details

By default, the 90% significance seasonal Z-test, used by Assimakopoulos and Nikolopoulos (2000), is applied for quarterly and monthly time series. The possibility of first checking the unit root was included because it was pointed out that this test presents many flaws for time series with this characteristic (Fiorucci et al, 2016). In this case, the KPSS test is performed with a significance level of 5% and in the case of a unit root, then the series is differentiated before checking for seasonal behavior.

For details of each model see Fiorucci et al, 2016. If you are looking for the methods presented in the arXiv paper (Fiorucci et al, 2015), see otm.arxiv function.

This version allows bagging to be used in conjunction with these models, see bagged_dotm, bagged_dstm, bagged_otm and bagged_stm functions.

Value

An object of thetaModel class with one list containing the elements:

$method

The name of the model/method

$y

The original time series.

$s

A binary indication for seasonal decomposition.

type

Classical seasonal decomposition type.

opt.method

The optimisation method used in the optim() function.

$par

The estimated values for (ell, alpha, theta) parameters

$weights

The estimated weights values.

$fitted

A time series element with the fitted points.

$residuals

A time series element with the residual points.

$mean

The forecasting values.

$level

The levels for prediction intervals.

$lower

Lower limits for prediction intervals.

$upper

Upper limits for prediction intervals.

$tests

The p.value of Teraesvirta Neural Network test applied on unseasoned time series and the p.value of Shapiro-Wilk test applied on unseasoned residuals.

Author(s)

Jose Augusto Fiorucci, Francisco Louzada

References

Fiorucci J.A., Pellegrini T.R., Louzada F., Petropoulos F., Koehler, A. (2016). Models for optimising the theta method and their relationship to state space models, International Journal of Forecasting, 32 (4), 1151–1161, <doi:10.1016/j.ijforecast.2016.02.005>.

Assimakopoulos, V. and Nikolopoulos k. (2000). The theta model: a decomposition approach to forecasting. International Journal of Forecasting 16 (4), 521–530, <doi:10.1016/S0169-2070(00)00066-2>.

See Also

forecTheta-package, bagged_dotm, bagged_dstm, bagged_otm, bagged_stm, otm.arxiv

Examples


y1 = 2+ 0.15*(1:20) + rnorm(20)
y2 = y1[20]+ 0.3*(1:30) + rnorm(30)
y =  as.ts(c(y1,y2))
out <- dotm(y, h=10)
summary(out)
plot(out)

#### additive seasonal decomposition ###
x = sin(2*pi*seq(0,9,len=300)) + exp((1:300)/150) + rnorm(mean=0,sd=0.5,n=300)
y = ts(x, frequency=33)
out <- dotm(y, h=50, s_type='additive')
summary(out)
plot(out)

# #########################################################
# ######### Reproducing the M3 results by DOTM ############
# #########################################################
#
# library(Mcomp)
# data(M3)
#
# forec = matrix(NA, nrow=3003, ncol=18)
# obs = matrix(NA, nrow=3003, ncol=18) #matrix of the out-sample values
# meanDiff <- rep(1, 3003)
#
# for(i in 1:3003){
#   x=M3[[i]]$x
#   h=M3[[i]]$h
#   out = dotm(x,h,level=NULL)
#   forec[i,1:h] = out$mean
#   obs[i,1:h] = M3[[i]]$xx
#   meanDiff[i] = mean(abs(diff(x, lag = frequency(x))))
# }
#
# ############## sMAPE ###################
# sAPE_matrix = errorMetric(obs=obs, forec=forec, type="sAPE", statistic="N")
# #### Yearly ###
# mean( sAPE_matrix[1:645, 1:6] )
# #### QUARTERLY ###
# mean( sAPE_matrix[646:1401, 1:8] )
# #### MONTHLY ###
# mean( sAPE_matrix[1402:2829, 1:18] )
# #### Other ###
# mean( sAPE_matrix[2830:3003, 1:8] )
# #### ALL ###
# mean( sAPE_matrix, na.rm=TRUE )
# #
# ############# MASE ######################
# AE_matrix = errorMetric(obs=obs, forec=forec, type="AE", statistic="N")
# ASE_matrix=AE_matrix/meanDiff
# #### Yearly ###
# mean( ASE_matrix[1:645, 1:6] )
# #### QUARTERLY ###
# mean( ASE_matrix[646:1401, 1:8] )
# #### MONTHLY ###
# mean( ASE_matrix[1402:2829, 1:18] )
# #### Other ###
# mean( ASE_matrix[2830:3003, 1:8] )
# #### ALL ###
# mean( ASE_matrix, na.rm=TRUE )
# ########################################################



forecTheta documentation built on June 8, 2025, 10:02 a.m.