From a7a5f03b022daebf3ba07ea499bae9fd21c501b0 Mon Sep 17 00:00:00 2001 From: Ronit Jaiswal Date: Mon, 16 Aug 2021 07:50:02 +0000 Subject: [PATCH] version 0.1.0 --- DESCRIPTION | 34 +++++++++++++++++++++++++++++++++ MD5 | 6 ++++++ NAMESPACE | 10 ++++++++++ R/stlARIMA.R | 30 +++++++++++++++++++++++++++++ data/Data_potato.rda | Bin 0 -> 925 bytes man/Data_potato.Rd | 29 ++++++++++++++++++++++++++++ man/STLARIMA.Rd | 44 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 153 insertions(+) create mode 100644 DESCRIPTION create mode 100644 MD5 create mode 100644 NAMESPACE create mode 100644 R/stlARIMA.R create mode 100644 data/Data_potato.rda create mode 100644 man/Data_potato.Rd create mode 100644 man/STLARIMA.Rd diff --git a/DESCRIPTION b/DESCRIPTION new file mode 100644 index 0000000..f70d4be --- /dev/null +++ b/DESCRIPTION @@ -0,0 +1,34 @@ +Package: stlARIMA +Type: Package +Title: STL Decomposition and ARIMA Hybrid Forecasting Model +Version: 0.1.0 +Authors@R: + c(person(given = "Ronit", + family = "Jaiswal", + role = c("aut", "cre"), + email = "ronitjaiswal2912@gmail.com"), + person(given = "Girish Kumar", + family = "Jha", + role = c("aut", "ctb")), + person(given = "Rajeev Ranjan", + family = "Kumar", + role = "ctb"), + person(given = "Kapil", + family = "Choudhary", + role = "ctb")) +Maintainer: Ronit Jaiswal +Description: Univariate time series forecasting with STL decomposition based auto regressive integrated moving average (ARIMA) hybrid model. For method details see Xiong T, Li C, Bao Y (2018). . +License: GPL-3 +Encoding: UTF-8 +LazyData: true +RoxygenNote: 7.1.1 +Imports: forecast +Depends: R (>= 2.10) +NeedsCompilation: no +Packaged: 2021-08-13 17:23:06 UTC; Rajeev-PC +Author: Ronit Jaiswal [aut, cre], + Girish Kumar Jha [aut, ctb], + Rajeev Ranjan Kumar [ctb], + Kapil Choudhary [ctb] +Repository: CRAN +Date/Publication: 2021-08-16 08:50:02 UTC diff --git a/MD5 b/MD5 new file mode 100644 index 0000000..9f4e429 --- /dev/null +++ b/MD5 @@ -0,0 +1,6 @@ +a52ee39a66858005bbd9c20895a8c797 *DESCRIPTION +8cb0f0728deb5edcc089fc19dc2c7b73 *NAMESPACE +47bc6e83c37015b01579040b78f51ca7 *R/stlARIMA.R +f0a2e9084cebb1889f1f6afa82616a7a *data/Data_potato.rda +0d97cfe4eaedc0c46fac5e7ef3f921e2 *man/Data_potato.Rd +72af6d9d5c21651075079bbee8ef71bc *man/STLARIMA.Rd diff --git a/NAMESPACE b/NAMESPACE new file mode 100644 index 0000000..22c68a3 --- /dev/null +++ b/NAMESPACE @@ -0,0 +1,10 @@ +# Generated by roxygen2: do not edit by hand + +export(STLARIMA) +importFrom(forecast,auto.arima) +importFrom(forecast,mstl) +importFrom(graphics,plot) +importFrom(stats,as.ts) +importFrom(stats,ts) +importFrom(utils,head) +importFrom(utils,tail) diff --git a/R/stlARIMA.R b/R/stlARIMA.R new file mode 100644 index 0000000..2e1fa89 --- /dev/null +++ b/R/stlARIMA.R @@ -0,0 +1,30 @@ +#' @importFrom forecast mstl auto.arima +#' @importFrom utils head tail +#' @importFrom graphics plot +#' @importFrom stats as.ts ts +#' @export +#' +STLARIMA <- function(data, stepahead=10){ + STLcomp <- mstl(data) + STLcomp_plots<-plot(STLcomp) + data_trn <- ts(head(data, round(length(data) - stepahead))) + data_test <- ts(tail(data, stepahead)) + STLcomp_trn <- STLcomp[-c(((length(data)-stepahead)+1):length(data)),] + Fcast_STLcomp <- NULL + for (STLcomp in 2:ncol(STLcomp_trn)) { + Indcomp <- NULL + Indcomp <- STLcomp_trn[ ,STLcomp] + stlARIMAFit <- forecast::auto.arima(as.ts(Indcomp)) + stlARIMA_fcast=forecast::forecast(stlARIMAFit, h=stepahead) + stlARIMA_fcast_Mean=stlARIMA_fcast$mean + Fcast_STLcomp <- cbind(Fcast_STLcomp, as.matrix(stlARIMA_fcast_Mean)) + } + FinalstlARIMA_fcast <- ts(rowSums(Fcast_STLcomp, na.rm = T)) + MAE_stlARIMA=mean(abs(data_test - FinalstlARIMA_fcast)) + MAPE_stlARIMA=mean(abs(data_test - FinalstlARIMA_fcast)/data_test) + rmse_stlARIMA=sqrt(mean((data_test - FinalstlARIMA_fcast)^2)) + return(list(data_test=data_test, STLcomp_forecast=Fcast_STLcomp, + stlARIMA_forecast=FinalstlARIMA_fcast, MAE_stlARIMA=MAE_stlARIMA, + MAPE_stlARIMA=MAPE_stlARIMA, rmse_stlARIMA=rmse_stlARIMA, + STLcomp_plots=STLcomp_plots)) +} diff --git a/data/Data_potato.rda b/data/Data_potato.rda new file mode 100644 index 0000000000000000000000000000000000000000..9817d2b6ed5a14c7b775de71bb644b4f9980f6eb GIT binary patch literal 925 zcmV;O17iF_T4*^jL0KkKS-i|(R{#Lk|NsC0|GWSH|Ns8(|8M{I{r-Qy|Ns8A{`>d7 z^8fPxciX@M9ANI`=*nmS4Ff|>G5{I?8fXEa00000XaE2Kpa1{>4Fez=0iXZ|hJ#Fu znhL1NF))mb15E~or=m7M(qW(odWM)2G@gS%13=WkM$phSGzp2C38$t&01Y9g1oSl0 zV?m=e4Ky-M4G&Pz9-sgK8UO*H9-sgKXaE4n00Te(0000Upa1{>8UO%f&>CtphYXE>X;jM&^(9JB;?d(L|rzb|vAnZfnH*6=qtwynU};3z)cL=ge_fcrrcl z(C;T{EogCbHx_pgf4~~Ryvjnld0k*Rr2fC3;houW|nvjw@t zY7&ntv=O*1BMYyk$sjdtD5ow3bDc?TRkT)MifjN#(;o`MefAsQV8Ljv>(;8aKco$lFNiO zeT{J&r_663|5g!gRV*EdiD{&*$CbE%&yrQ5q^LouVG-8y7fs1!A04UNgQ|^S8Vt@z zw1Xi6%GBbbk=Z%g@o~KFLg@YG*&F%e311-+94&g>;PcvaqMF;o*#RPe9~DQT3IN9n z5#}IIvB{=BhzP3K`WU4Wc$IODO#}o1qCso|kPixF>nJ2o8u1Q|Knz;|D?na6z;2-y zeP9mS3EUi*@gzuXGU3vNlX0r~`B-HXiU>KxS)JKV=?F1|2||#? zL?b~19#Yi&NC{actw{mxWwsMpf1s-QDFt%nwPh4Wq3Q-(BpmvtTi1B7@bSZ2%wFk=- literal 0 HcmV?d00001 diff --git a/man/Data_potato.Rd b/man/Data_potato.Rd new file mode 100644 index 0000000..6ff8126 --- /dev/null +++ b/man/Data_potato.Rd @@ -0,0 +1,29 @@ +\name{Data_potato} +\alias{Data_potato} +\docType{data} +\title{ +Normalized Monthly Average Potato Price of India +} +\description{ +Normalized monthly average potato price of India from January 2014 to July 2020. +} +\usage{data("Data_potato")} +\format{ + A time series data with 79 observations. + \describe{ + \item{\code{price}}{a time series} + } +} +\details{ +Dataset contains 79 observations of normalized monthly average potato price of India. +} +\source{ +Department of Consumer Affairs, Govt. of India +} +\references{ +https://consumeraffairs.nic.in/ +} +\examples{ +data(Data_potato) +} +\keyword{datasets} diff --git a/man/STLARIMA.Rd b/man/STLARIMA.Rd new file mode 100644 index 0000000..5f2da39 --- /dev/null +++ b/man/STLARIMA.Rd @@ -0,0 +1,44 @@ +\name{STLARIMA} +\alias{STLARIMA} +%- Also NEED an '\alias' for EACH other topic documented here. +\title{ +STL Based ARIMA Forecasting Model +} +\description{ +The STLARIMA function forecasts a time series using a hybrid model made of a decomposition technique called seasonal trend decomposition based on loess (STL) and a forecasting technique called ARIMA. The function further computes the values of different forecasting evaluation criteria. +} +\usage{ +STLARIMA(data, stepahead=10) +} +\arguments{ + \item{data}{ +Input univariate time series (ts) data. +} + \item{stepahead}{ +The forecast horizon. +} +} +\details{ +This function decomposes a nonlinear, nonstationary and seasonal time series into trend-cycle, seasonal and remainder component using STL (Cleveland et al., 1990). ARIMA model is used to forecast these components individually (Box et al., 2015, Jha and Sinha, 2013). Finally, the prediction results of all the three components are aggregated to formulate an ensemble output for the input time series. +} +\value{ + \item{data_test }{Testing set used to measure the out of sample performance.} + \item{STLcomp_forecast }{Forecasted value of all individual components.} + \item{stlARIMA_forecast }{Final forecasted value of the stlARIMA model. It is obtained by combining the forecasted value of all individual components.} + \item{MAE_stlARIMA }{Mean Absolute Error (MAE) for stlARIMA model.} + \item{MAPE_stlARIMA }{Mean Absolute Percentage Error (MAPE) for stlARIMA model.} + \item{rmse_stlARIMA }{Root Mean Square Error (RMSE) for stlARIMA model.} +} +\references{ +Cleveland, R.B., Cleveland, W.S., McRae, J.E., Terpenning, I. (1990). STL: A seasonal-trend decomposition procedure based on loess, Journal of Official Statistics, 6, 3--73. + +Box, G.E.P, Reinsel, G.C., Jenkins, G.M., Ljung, G.M. (2015). Time Series Analysis: Forecasting and Control. Wiley, Germany. + +Jha, G.K., Sinha, K. (2013). Agricultural price forecasting using neural network model: An innovative information delivery system. Agricultural Economics Research Review, 26, 229--239. + +} +\examples{ +data("Data_potato") +STLARIMA(Data_potato) +} +\keyword{ stl }