SlideShare a Scribd company logo
Time Series Analysis Using ARIMA Model For
Forecasting In R (Practical)
By
Laud Randy Amofah
February 2020
Time series refers to a set of observation on a particular variable recorded in time sequence. This
time sequence or space can be hourly, daily, weekly, monthly, quarterly or yearly.
Why time series analysis
1. Its emphasis is to support in decision making
2. To fit a mathematical model and then proceed to forecast the future.
The tool that we will be using for the practical is the RStudio you can click on the link below and
download the RStudio setup and install it;
https://rstudio.com/products/rstudio/download/
The dataset that will be used is the daily-minimum-temperatures-in-me.csv you can download it
from Kaggle. Below is the link to download the daily minimum temperatures in me dataset;
https://www.kaggle.com/paulbrabban/daily-minimum-temperatures-in-melbourne
The libraries that will be used for the model in time series are tseries and forecast. The # tag
means comment
I think the above information is enough for us to start our practical. Now let’s launch our RStudio.
Figure 1 – RStudio
We start:
#Importing the necessary libraries for the model
library(tseries)
library(forecast)
#load the daily minimum temperatures in me data.
#NB: To copy the path press on the shift button and right click on the file to copy the path
temp=read.csv("C:UsersLENOVODesktopR tutorialsdaily-minimum-temperatures-in-
me.csv")
temp
Figure 2 – Temp output
#NB: In time series we need only the observation, so we open the daily-minimum-temperatures-in-
me.csv file
# and delete the date column or the first column that will left with observation column in the csv file
# after we are done we will save the file as dailytemperature so that it will not conflict with the first file.
###load the daily temperatures data.
temperature=read.csv("C:UsersLENOVODesktopR tutorialsdailytemperatures.csv", header =
TRUE)
temperature
Figure 3 – Temperature output
### we convert the data to time series
temperature <- ts(temperature, start = c(1981,1), frequency = 365)
plot.ts(temperature)
Figure 4 – Temperature plot output
###Test the data for stationarity using adf test
###H0: Unit root
adf.test(temperature)
Figure 5 – Testing for its stationary output
###Difference the data to make it stationary
#NB: You only differeniate when the p-value is greater then 0.01
dtemperature=diff(temperature)
adf.test(dtemperature)
###Plotting ACF and PACF
acf(as.numeric(temperature), main="ACF OF DIFFERNCED TEMPERATURES")
pacf(as.numeric(temperature), main="PACF OF DIFFERNCED TEMPERATURES")
Figure 6 – AFC output
Figure 7 – PAFC output
###Plotting both the ACF and PACF together
par(mfcol=c(2,1))
acf(as.numeric(temperature), main="ACF OF DIFFERNCED TEMPERATURES")
pacf(as.numeric(temperature), main="PACF OF DIFFERNCED TEMPERATURES")
Figure 8 – ACF AND PAFC output
###Fit Integrated AR models
model1=arima(temperature,order = c(15,1,0))
summary(model1)
Figure 9 – Summary of AR model output
#######Diagnosing the model for Adequecy
###Obtained the residuals of the model
res1=model1$resid
###Test for zero mean
t.test(res1)
Figure 10 – Residuals of the model and testing for zero mean output
###Plot the PACF of the Residuals to check for Autocorrelation
pacf(as.vector(res1),lag=25, na.action=na.pass)
pacf(as.vector(res1^2),lag=25, na.action=na.pass)
Figure 11 – Checking for Autocorrelation in the residuals of the PACF output
###Test for Independence
Box.test(res1, type="Ljung-Box", lag=15)
tsdiag(model1)
Figure 12 – Testing for independence output
Figure 13 – Testing for independence output with plot diagram
#######Forecasting from the model Model for 10 days
pred<-predict(model1,n.ahead=10)
pred
Figure 14 – The 10 days predictions output
#######Plot the data and fitted values
plot.ts(temperature)
lines(fitted(model1),col="red")
lines(fitted(model1),col="blue")
Figure 15 – Plotting fitted line with plot diagram
plot(forecast(model1,10))
Figure 16 – 10 days Forecast output with plot diagram

More Related Content

What's hot

Time Series Analysis with R
Time Series Analysis with RTime Series Analysis with R
Time Series Analysis with R
ARCHIT GUPTA
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with R
Yanchang Zhao
 
Arima model
Arima modelArima model
Arima model
Jassika
 
STATA - Time Series Analysis
STATA - Time Series AnalysisSTATA - Time Series Analysis
STATA - Time Series Analysisstata_org_uk
 
Time series forecasting
Time series forecastingTime series forecasting
Time series forecasting
Firas Kastantin
 
ARIMA
ARIMA ARIMA
Quantitative forecasting
Quantitative forecastingQuantitative forecasting
Quantitative forecasting
Ravi Loriya
 
ARIMA Models - [Lab 3]
ARIMA Models - [Lab 3]ARIMA Models - [Lab 3]
ARIMA Models - [Lab 3]
Theodore Grammatikopoulos
 
Time series
Time seriesTime series
Time series
Haitham Ahmed
 
demand forecasting
demand forecastingdemand forecasting
demand forecasting
Priyanshu Gandhi
 
Statistical system
Statistical systemStatistical system
Statistical system
barghouthi2016
 
Time Series Analysis/ Forecasting
Time Series Analysis/ Forecasting  Time Series Analysis/ Forecasting
Time Series Analysis/ Forecasting
Samudra Kanankearachchi
 
Time series analysis
Time series analysisTime series analysis
Time series analysis
Utkarsh Sharma
 
Mba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysisMba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysisChandra Kodituwakku
 
Time Series Forecasting Project Presentation.
Time Series Forecasting Project  Presentation.Time Series Forecasting Project  Presentation.
Time Series Forecasting Project Presentation.
Anupama Kate
 
Presentation on Index Number
Presentation on Index NumberPresentation on Index Number
Presentation on Index Number
Asraf Hossain
 
Lesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_seriesLesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_series
ankit_ppt
 
Module 3 - Time Series.pptx
Module 3 - Time Series.pptxModule 3 - Time Series.pptx
Module 3 - Time Series.pptx
nikshaikh786
 
Lesson 2 stationary_time_series
Lesson 2 stationary_time_seriesLesson 2 stationary_time_series
Lesson 2 stationary_time_series
ankit_ppt
 
Presentation
PresentationPresentation
Presentation
Srinivas KNS
 

What's hot (20)

Time Series Analysis with R
Time Series Analysis with RTime Series Analysis with R
Time Series Analysis with R
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with R
 
Arima model
Arima modelArima model
Arima model
 
STATA - Time Series Analysis
STATA - Time Series AnalysisSTATA - Time Series Analysis
STATA - Time Series Analysis
 
Time series forecasting
Time series forecastingTime series forecasting
Time series forecasting
 
ARIMA
ARIMA ARIMA
ARIMA
 
Quantitative forecasting
Quantitative forecastingQuantitative forecasting
Quantitative forecasting
 
ARIMA Models - [Lab 3]
ARIMA Models - [Lab 3]ARIMA Models - [Lab 3]
ARIMA Models - [Lab 3]
 
Time series
Time seriesTime series
Time series
 
demand forecasting
demand forecastingdemand forecasting
demand forecasting
 
Statistical system
Statistical systemStatistical system
Statistical system
 
Time Series Analysis/ Forecasting
Time Series Analysis/ Forecasting  Time Series Analysis/ Forecasting
Time Series Analysis/ Forecasting
 
Time series analysis
Time series analysisTime series analysis
Time series analysis
 
Mba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysisMba 532 2011_part_3_time_series_analysis
Mba 532 2011_part_3_time_series_analysis
 
Time Series Forecasting Project Presentation.
Time Series Forecasting Project  Presentation.Time Series Forecasting Project  Presentation.
Time Series Forecasting Project Presentation.
 
Presentation on Index Number
Presentation on Index NumberPresentation on Index Number
Presentation on Index Number
 
Lesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_seriesLesson 1 introduction_to_time_series
Lesson 1 introduction_to_time_series
 
Module 3 - Time Series.pptx
Module 3 - Time Series.pptxModule 3 - Time Series.pptx
Module 3 - Time Series.pptx
 
Lesson 2 stationary_time_series
Lesson 2 stationary_time_seriesLesson 2 stationary_time_series
Lesson 2 stationary_time_series
 
Presentation
PresentationPresentation
Presentation
 

Similar to TIME SERIES ANALYSIS USING ARIMA MODEL FOR FORECASTING IN R (PRACTICAL)

PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
The Statistical and Applied Mathematical Sciences Institute
 
SAP HANA SPS09 - Series Data
SAP HANA SPS09 - Series DataSAP HANA SPS09 - Series Data
SAP HANA SPS09 - Series Data
SAP Technology
 
PART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTPART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORT
Andrea Antonello
 
Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発
Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発
Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発
Ryo 亮 Kawahara 河原
 
Data Science - Part II - Working with R & R studio
Data Science - Part II -  Working with R & R studioData Science - Part II -  Working with R & R studio
Data Science - Part II - Working with R & R studio
Derek Kane
 
Unit-5 Time series data Analysis.pptx
Unit-5 Time series data Analysis.pptxUnit-5 Time series data Analysis.pptx
Unit-5 Time series data Analysis.pptx
Sheba41
 
[計一] Basic r programming final0918
[計一] Basic r programming   final0918[計一] Basic r programming   final0918
[計一] Basic r programming final0918Yen_CY
 
[計一] Basic r programming final0918
[計一] Basic r programming   final0918[計一] Basic r programming   final0918
[計一] Basic r programming final0918Chia-Yi Yen
 
e_lumley.pdf
e_lumley.pdfe_lumley.pdf
e_lumley.pdf
betsegaw123
 
Mixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive StatisticsMixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive Statistics
Scott Fraundorf
 
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docxprog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
stilliegeorgiana
 
Twitter_Sentiment_analysis.pptx
Twitter_Sentiment_analysis.pptxTwitter_Sentiment_analysis.pptx
Twitter_Sentiment_analysis.pptx
JOELFRANKLIN13
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
todd331
 
Twitter Mention Graph - Analytics Project
Twitter Mention Graph - Analytics ProjectTwitter Mention Graph - Analytics Project
Twitter Mention Graph - Analytics Project
Sotiris Baratsas
 
Linking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scriptsLinking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scripts
Khalid Belhajjame
 
Unit 5 Time series Data Analysis.pdf
Unit 5 Time series Data Analysis.pdfUnit 5 Time series Data Analysis.pdf
Unit 5 Time series Data Analysis.pdf
Sheba41
 
1 CMIS 102 Hands-On Lab Week 8 Overview Th.docx
1  CMIS 102 Hands-On Lab  Week 8 Overview Th.docx1  CMIS 102 Hands-On Lab  Week 8 Overview Th.docx
1 CMIS 102 Hands-On Lab Week 8 Overview Th.docx
honey725342
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
KabilaArun
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
DrGSakthiGovindaraju
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
attalurilalitha
 

Similar to TIME SERIES ANALYSIS USING ARIMA MODEL FOR FORECASTING IN R (PRACTICAL) (20)

PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
 
SAP HANA SPS09 - Series Data
SAP HANA SPS09 - Series DataSAP HANA SPS09 - Series Data
SAP HANA SPS09 - Series Data
 
PART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTPART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORT
 
Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発
Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発
Apache Sparkを用いたスケーラブルな時系列データの異常検知モデル学習ソフトウェアの開発
 
Data Science - Part II - Working with R & R studio
Data Science - Part II -  Working with R & R studioData Science - Part II -  Working with R & R studio
Data Science - Part II - Working with R & R studio
 
Unit-5 Time series data Analysis.pptx
Unit-5 Time series data Analysis.pptxUnit-5 Time series data Analysis.pptx
Unit-5 Time series data Analysis.pptx
 
[計一] Basic r programming final0918
[計一] Basic r programming   final0918[計一] Basic r programming   final0918
[計一] Basic r programming final0918
 
[計一] Basic r programming final0918
[計一] Basic r programming   final0918[計一] Basic r programming   final0918
[計一] Basic r programming final0918
 
e_lumley.pdf
e_lumley.pdfe_lumley.pdf
e_lumley.pdf
 
Mixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive StatisticsMixed Effects Models - Descriptive Statistics
Mixed Effects Models - Descriptive Statistics
 
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docxprog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
prog-05.pdfProgramming Assignment #5CSci 430, Spring 2.docx
 
Twitter_Sentiment_analysis.pptx
Twitter_Sentiment_analysis.pptxTwitter_Sentiment_analysis.pptx
Twitter_Sentiment_analysis.pptx
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
 
Twitter Mention Graph - Analytics Project
Twitter Mention Graph - Analytics ProjectTwitter Mention Graph - Analytics Project
Twitter Mention Graph - Analytics Project
 
Linking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scriptsLinking the prospective and retrospective provenance of scripts
Linking the prospective and retrospective provenance of scripts
 
Unit 5 Time series Data Analysis.pdf
Unit 5 Time series Data Analysis.pdfUnit 5 Time series Data Analysis.pdf
Unit 5 Time series Data Analysis.pdf
 
1 CMIS 102 Hands-On Lab Week 8 Overview Th.docx
1  CMIS 102 Hands-On Lab  Week 8 Overview Th.docx1  CMIS 102 Hands-On Lab  Week 8 Overview Th.docx
1 CMIS 102 Hands-On Lab Week 8 Overview Th.docx
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 

Recently uploaded

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
ewymefz
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
NABLAS株式会社
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
ewymefz
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
ArpitMalhotra16
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Subhajit Sahu
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Linda486226
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
ahzuo
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
nscud
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 

Recently uploaded (20)

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
 
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
standardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghhstandardisation of garbhpala offhgfffghh
standardisation of garbhpala offhgfffghh
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 

TIME SERIES ANALYSIS USING ARIMA MODEL FOR FORECASTING IN R (PRACTICAL)

  • 1. Time Series Analysis Using ARIMA Model For Forecasting In R (Practical) By Laud Randy Amofah February 2020 Time series refers to a set of observation on a particular variable recorded in time sequence. This time sequence or space can be hourly, daily, weekly, monthly, quarterly or yearly. Why time series analysis 1. Its emphasis is to support in decision making 2. To fit a mathematical model and then proceed to forecast the future. The tool that we will be using for the practical is the RStudio you can click on the link below and download the RStudio setup and install it; https://rstudio.com/products/rstudio/download/ The dataset that will be used is the daily-minimum-temperatures-in-me.csv you can download it from Kaggle. Below is the link to download the daily minimum temperatures in me dataset; https://www.kaggle.com/paulbrabban/daily-minimum-temperatures-in-melbourne
  • 2. The libraries that will be used for the model in time series are tseries and forecast. The # tag means comment I think the above information is enough for us to start our practical. Now let’s launch our RStudio. Figure 1 – RStudio We start: #Importing the necessary libraries for the model library(tseries) library(forecast) #load the daily minimum temperatures in me data. #NB: To copy the path press on the shift button and right click on the file to copy the path temp=read.csv("C:UsersLENOVODesktopR tutorialsdaily-minimum-temperatures-in- me.csv") temp
  • 3. Figure 2 – Temp output #NB: In time series we need only the observation, so we open the daily-minimum-temperatures-in- me.csv file # and delete the date column or the first column that will left with observation column in the csv file # after we are done we will save the file as dailytemperature so that it will not conflict with the first file. ###load the daily temperatures data. temperature=read.csv("C:UsersLENOVODesktopR tutorialsdailytemperatures.csv", header = TRUE) temperature
  • 4. Figure 3 – Temperature output ### we convert the data to time series temperature <- ts(temperature, start = c(1981,1), frequency = 365) plot.ts(temperature)
  • 5. Figure 4 – Temperature plot output ###Test the data for stationarity using adf test ###H0: Unit root adf.test(temperature) Figure 5 – Testing for its stationary output
  • 6. ###Difference the data to make it stationary #NB: You only differeniate when the p-value is greater then 0.01 dtemperature=diff(temperature) adf.test(dtemperature) ###Plotting ACF and PACF acf(as.numeric(temperature), main="ACF OF DIFFERNCED TEMPERATURES") pacf(as.numeric(temperature), main="PACF OF DIFFERNCED TEMPERATURES") Figure 6 – AFC output
  • 7. Figure 7 – PAFC output ###Plotting both the ACF and PACF together par(mfcol=c(2,1)) acf(as.numeric(temperature), main="ACF OF DIFFERNCED TEMPERATURES") pacf(as.numeric(temperature), main="PACF OF DIFFERNCED TEMPERATURES")
  • 8. Figure 8 – ACF AND PAFC output ###Fit Integrated AR models model1=arima(temperature,order = c(15,1,0)) summary(model1) Figure 9 – Summary of AR model output
  • 9. #######Diagnosing the model for Adequecy ###Obtained the residuals of the model res1=model1$resid ###Test for zero mean t.test(res1) Figure 10 – Residuals of the model and testing for zero mean output ###Plot the PACF of the Residuals to check for Autocorrelation pacf(as.vector(res1),lag=25, na.action=na.pass) pacf(as.vector(res1^2),lag=25, na.action=na.pass)
  • 10. Figure 11 – Checking for Autocorrelation in the residuals of the PACF output ###Test for Independence Box.test(res1, type="Ljung-Box", lag=15) tsdiag(model1) Figure 12 – Testing for independence output
  • 11. Figure 13 – Testing for independence output with plot diagram #######Forecasting from the model Model for 10 days pred<-predict(model1,n.ahead=10) pred Figure 14 – The 10 days predictions output
  • 12. #######Plot the data and fitted values plot.ts(temperature) lines(fitted(model1),col="red") lines(fitted(model1),col="blue")
  • 13. Figure 15 – Plotting fitted line with plot diagram
  • 14. plot(forecast(model1,10)) Figure 16 – 10 days Forecast output with plot diagram