forecTheta (version 2.0)

thetaModels: 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 Theta Method (stheta) of Assimakopoulos and Nikolopoulos (2000).

Usage

dotm(y, h=5, level=c(80,90,95), s=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))
	
	dstm(y, h=5, level=c(80,90,95), s=NULL, par_ini=c(y[1]/2, 0.5), 
	estimation=TRUE, lower=c(-1e+10, 0.1), upper=c(1e+10, 0.99))
	
	otm(y, h=5, level=c(80,90,95), s=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))
	
	stm(y, h=5, level=c(80,90,95), s=NULL, par_ini=c(y[1]/2, 0.5), 
	estimation=TRUE, lower=c(-1e+10, 0.1), upper=c(1e+10, 0.99))
	
	stheta(y, h=5, s=NULL)

Arguments

y
Object of time series class.
h
Number of required forecasting periods.
level
Levels for prediction intervals.
s
If TRUE, the multiplicative seasonal decomposition is used. If NULL, quarterly and monthly time series are tested for statistically seasonal behaviour, with 95% of significance. Default is NULL.
par_ini
Vector of inicialization 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.

Value

  • An object of thetaModel class with one list containing the elements:
  • $methodThe name of the model/method
  • $yThe original time series.
  • $sA binary indication for seasonal decomposition
  • $parThe estimated values for (ell, alpha, theta) parameters
  • $weightsThe estimated weights values.
  • $fittedA time series element with the fitted points.
  • $residualsA time series element with the residual points.
  • $meanThe forecasting values
  • $levelThe levels for prediction intervals
  • $lowerLower limits for prediction intervals
  • $upperUpper limits for prediction intervals

Details

By default (s=NULL), the 90% significance seasonal Z-test, used by Assimakopoulos and Nikolopoulos (2000), is applied for quarterly and monthly time series. 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.

References

Fioruci 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. Accepted Paper. https://www.researchgate.net/publication/294420765_Models_for_optimising_the_theta_method_and_their_relationship_to_state_space_models Fioruci J.A., Pellegrini T.R., Louzada F., Petropoulos F. (2015). The Optimised Theta Method. Free available at http://arxiv.org/abs/1503.03529. Assimakopoulos, V. and Nikolopoulos k. (2000). The theta model: a decomposition approach to forecasting. International Journal of Forecasting 16, 4, 521-530.

See Also

forecTheta-package, otm.arxiv

Examples

Run this code
y1 = 2+ 0.15*(1:20) + rnorm(20,2)
y2 = y1[20]+ 0.3*(1:30) + rnorm(30,2)
y =  as.ts(c(y1,y2))

out <- dotm(y, h=10)
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){
#	 if(i \%\% 100 == 0){print(i);}
#	 x=M3[[i]]$x
#	 h=M3[[i]]$h
#	 out = dotm(x,h)
#	 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 )
########################################################

Run the code above in your browser using DataLab