Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronit10976 authored and cran-robot committed Aug 16, 2021
0 parents commit a7a5f03
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 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 <ronitjaiswal2912@gmail.com>
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). <doi:10.1016/j.neucom.2017.11.053>.
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
6 changes: 6 additions & 0 deletions 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
10 changes: 10 additions & 0 deletions 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)
30 changes: 30 additions & 0 deletions 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))
}
Binary file added data/Data_potato.rda
Binary file not shown.
29 changes: 29 additions & 0 deletions 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}
44 changes: 44 additions & 0 deletions 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 }

0 comments on commit a7a5f03

Please sign in to comment.