Set Directory

getwd()
## [1] "C:/Users/HP/Downloads/SDR_Datamatica/R_Directory"
setwd("C:/Users/HP/Downloads/SDR_Datamatica/R_Directory")

Install Required Packages

install.packages(c("xlsx","rJava","xlsxjars","XLConnectJars","XLConnect","lubridate","base"),repos = "http://cran.us.r-project.org",dependencies = TRUE)
## Installing packages into 'C:/Users/HP/Documents/R/win-library/3.3'
## (as 'lib' is unspecified)
## Warning: package 'base' is not available (for R version 3.3.1)
## Warning: package 'base' is a base package, and should not be updated
## package 'xlsx' successfully unpacked and MD5 sums checked
## package 'rJava' successfully unpacked and MD5 sums checked
## package 'xlsxjars' successfully unpacked and MD5 sums checked
## package 'XLConnectJars' successfully unpacked and MD5 sums checked
## package 'XLConnect' successfully unpacked and MD5 sums checked
## package 'lubridate' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\HP\AppData\Local\Temp\RtmpUdKLSQ\downloaded_packages
install.packages("lubridate",repos = "http://cran.us.r-project.org",dependencies = TRUE)
## Installing package into 'C:/Users/HP/Documents/R/win-library/3.3'
## (as 'lib' is unspecified)
## package 'lubridate' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\HP\AppData\Local\Temp\RtmpUdKLSQ\downloaded_packages
install.packages("base",repos = "http://cran.us.r-project.org",dependencies = TRUE)
## Installing package into 'C:/Users/HP/Documents/R/win-library/3.3'
## (as 'lib' is unspecified)
## Warning: package 'base' is not available (for R version 3.3.1)

## Warning: package 'base' is a base package, and should not be updated
install.packages("forecast",repos = "http://cran.us.r-project.org",dependencies = TRUE)
## Installing package into 'C:/Users/HP/Documents/R/win-library/3.3'
## (as 'lib' is unspecified)
## package 'forecast' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\HP\AppData\Local\Temp\RtmpUdKLSQ\downloaded_packages
install.packages("zoo",repos = "http://cran.us.r-project.org",dependencies = TRUE)
## Installing package into 'C:/Users/HP/Documents/R/win-library/3.3'
## (as 'lib' is unspecified)
## package 'zoo' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\HP\AppData\Local\Temp\RtmpUdKLSQ\downloaded_packages
library("xlsx")
## Loading required package: rJava
## Loading required package: xlsxjars
library("rJava")
library("xlsxjars")
library("XLConnectJars")
library("XLConnect")
## XLConnect 0.2-12 by Mirai Solutions GmbH [aut],
##   Martin Studer [cre],
##   The Apache Software Foundation [ctb, cph] (Apache POI, Apache Commons
##     Codec),
##   Stephen Colebourne [ctb, cph] (Joda-Time Java library),
##   Graph Builder [ctb, cph] (Curvesapi Java library)
## http://www.mirai-solutions.com ,
## http://miraisolutions.wordpress.com
## 
## Attaching package: 'XLConnect'
## The following objects are masked from 'package:xlsx':
## 
##     createFreezePane, createSheet, createSplitPane, getCellStyle,
##     getSheets, loadWorkbook, removeSheet, saveWorkbook,
##     setCellStyle, setColumnWidth, setRowHeight
library("base")
library("lubridate")
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library("forecast")
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: timeDate
## This is forecast 7.1
library("zoo")

read data from CSV

3.Importing the Excel file data into ‘R’

Customers_data_2013_2014<-read.xlsx("C:/Users/HP/Downloads/SDR_Datamatica/R_Directory/2013-16 Customer.xlsx",1)
Customers_data_2014_2015<-read.xlsx("C:/Users/HP/Downloads/SDR_Datamatica/R_Directory/2013-16 Customer.xlsx",2)
Customers_data_2015_2016<-read.xlsx("C:/Users/HP/Downloads/SDR_Datamatica/R_Directory/2013-16 Customer.xlsx",3)
dim(Customers_data_2013_2014)  
## [1] 76  9
dim(Customers_data_2014_2015)
## [1] 107   9
dim(Customers_data_2015_2016) 
## [1] 208   9
customer_data<-rbind(Customers_data_2013_2014,Customers_data_2014_2015,Customers_data_2015_2016)
View(Customers_data_2013_2014)

structure of the Date in cust dataset

str(customer_data$Transaction.Date)
##  Factor w/ 226 levels "01/01/2014","01/03/2014",..: 24 33 40 44 44 46 9 11 11 11 ...
str(customer_data)
## 'data.frame':    391 obs. of  9 variables:
##  $ S.No.                   : Factor w/ 208 levels "1","10","11",..: 1 12 23 34 45 56 67 75 76 2 ...
##  $ Value.Date              : Factor w/ 239 levels "01/01/2014","01/03/2014",..: 24 34 42 46 46 49 9 11 11 11 ...
##  $ Transaction.Date        : Factor w/ 226 levels "01/01/2014","01/03/2014",..: 24 33 40 44 44 46 9 11 11 11 ...
##  $ Cheque.Number           : Factor w/ 1 level "-": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Transaction.Remarks     : Factor w/ 378 levels "020021/CITI",..: 76 55 50 25 67 64 6 29 49 52 ...
##  $ Withdrawal.Amount..INR..: num  0 0 111 10000 54213 ...
##  $ Deposit.Amount..INR..   : num  20000 50000 0 0 0 ...
##  $ Balance..INR..          : num  20000 70000 69889 59889 5676 ...
##  $ NA.                     : logi  NA NA NA NA NA NA ...
names(customer_data)
## [1] "S.No."                    "Value.Date"              
## [3] "Transaction.Date"         "Cheque.Number"           
## [5] "Transaction.Remarks"      "Withdrawal.Amount..INR.."
## [7] "Deposit.Amount..INR.."    "Balance..INR.."          
## [9] "NA."

change the name of the Columns in cutomer data

names(customer_data)<-c("Si_No","Value_Date","Transaction_Date","Cheque_Number","Transaction_Remarks","Withdrawal_Amount_INR","Deposit_Amount_INR","Balance_INR")
View(customer_data)

Ordering the Date format

customer_data<- customer_data[order(customer_data$Transaction_Date), ]

——————-Perform Forecasting using ARIMA model———————

Extract Transaction_Date column from Dataset

customer_data<-ts(customer_data[,3],start = c(2013,1),end=c(2016,1),frequency = 12)
customer_data
##      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 2013   1   2   3   3   3   4   5   6   6   7   8   9
## 2014  10  10  10  10  11  11  11  12  13  14  15  15
## 2015  16  17  18  19  20  20  21  22  23  23  24  25
## 2016  26

Include the Plot Diagram

plot.ts(customer_data)

require(forecast)
ARIMAfit <- auto.arima(customer_data, approximation=FALSE,trace=FALSE)
summary(ARIMAfit)
## Series: customer_data 
## ARIMA(0,1,0) with drift         
## 
## Coefficients:
##        drift
##       0.6944
## s.e.  0.0768
## 
## sigma^2 estimated as 0.2183:  log likelihood=-23.18
## AIC=50.35   AICc=50.72   BIC=53.52
## 
## Training set error measures:
##                        ME      RMSE       MAE        MPE     MAPE
## Training set 8.258254e-06 0.4543748 0.4129212 -0.4108704 5.127029
##                    MASE       ACF1
## Training set 0.05135835 0.07142669
pred <- forecast.Arima(ARIMAfit)
pred
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Feb 2016       26.69444 26.09573 27.29316 25.77880 27.61009
## Mar 2016       27.38889 26.54218 28.23559 26.09397 28.68381
## Apr 2016       28.08333 27.04634 29.12033 26.49738 29.66928
## May 2016       28.77778 27.58036 29.97520 26.94648 30.60908
## Jun 2016       29.47222 28.13346 30.81098 27.42477 31.51968
## Jul 2016       30.16667 28.70013 31.63320 27.92379 32.40954
## Aug 2016       30.86111 29.27707 32.44515 28.43853 33.28369
## Sep 2016       31.55556 29.86215 33.24897 28.96571 34.14540
## Oct 2016       32.25000 30.45387 34.04613 29.50305 34.99695
## Nov 2016       32.94444 31.05115 34.83773 30.04891 35.83998
## Dec 2016       33.63889 31.65319 35.62459 30.60202 36.67575
## Jan 2017       34.33333 32.25934 36.40733 31.16143 37.50524
## Feb 2017       35.02778 32.86909 37.18646 31.72636 38.32920
## Mar 2017       35.72222 33.48205 37.96239 32.29618 39.14827
## Apr 2017       36.41667 34.09787 38.73546 32.87037 39.96296
## May 2017       37.11111 34.71627 39.50595 33.44851 40.77371
## Jun 2017       37.80556 35.33701 40.27410 34.03024 41.58087
## Jul 2017       38.50000 35.95988 41.04012 34.61523 42.38477
## Aug 2017       39.19444 36.58472 41.80416 35.20322 43.18567
## Sep 2017       39.88889 37.21137 42.56641 35.79398 43.98380
## Oct 2017       40.58333 37.83970 43.32697 36.38730 44.77937
## Nov 2017       41.27778 38.46957 44.08598 36.98300 45.57255
## Dec 2017       41.97222 39.10091 44.84354 37.58092 46.36352
## Jan 2018       42.66667 39.73359 45.59974 38.18092 47.15241
plot(pred,type="l",xlab = "Year",ylab = "Balance",lwd = 2,col = 'red',main="Forecasting using ARIMA Model")

Including Plots

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.