Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

ESSENTIALS OF

DATA ANALYTICS
Lab : 2

Date: 27-01-2022

Name: K SAI KUMAR

Reg. no: 19BEC1073

TIMESERIES FORECASTING

Aim:

To convert data into timeseries data and then to predict the future values by
forecasting the timeseries dataset.

For Soyaoil Dataset:

Importing dataset:
Dataset preview:

Converting into timeseries:


Dataset plotting:

It is a non-stationary data, as mean and varience both are not constant.


Differentiated dataset:
Logarithmical conversion:
Differentiated logarithmic plotting:
ACF and PACF:
ARIMA:
Forecasting:

Forecasting plot:
ACF and PACF after forecasting:
FINAL CODE :

class(Soyaoil)
Soya=ts(Soyaoil$Dollar,start=1,frequency = 4)
class(Soya)
plot(Soya,xlab='years',ylab='Dollors')
dTs<-diff(Soya)
plot(dTs)
lTs<-log10(Soya)
plot(lTs)
dlTs<-diff(lTs)
plot(dlTs)
par(mfrow=c(1,2))
acf(dlTs,main='AutoCorrelationFactor')
pacf(dlTs,main='PartialAutoCorrelationFactor')
library(forecast)
library(tseries)
ar<-auto.arima(dlTs,ic="aic",trace = TRUE)
attributes(ar)
par(mfrow=c(1,1))
myfc<-forecast(ar,level=c(95),h=10*4)
myfc
plot(myfc)
par(mfrow=c(1,2))
acf(ts(ar$residuals),main='ACF Residual')
pacf(ts(ar$residuals),main='PACF Residual')

For Crudeoil Dataset:

Importing dataset:
Dataset preview:

Converting into timeseries:


Dataset plotting:

It is a non-stationary data, as mean and varience both are not constant.


Differentiated dataset:
Logarithmical conversion:

Differentiated logarithmic plotting:


ACF and PACF:
ARIMA:

Forecasting:
Forecasting plot:

ACF and PACF after forecasting:


FINAL CODE :
class(Crudeoil_NS)
Crude=ts(Crudeoil_NS$POILBREUSDQ,start=1,frequency=4)
class(Crude)
plot(Crude,xlab='years',ylab='Poilbreusdq')
dTs<-diff(Crude)
plot(dTs)
lTs<-log10(Crude)
plot(lTs)
dlTs<-diff(lTs)
plot(dlTs)
par(mfrow=c(1,2))
acf(dlTs,main='AutoCorrelationFactor')
pacf(dlTs,main='PartialAutoCorrelationFactor')
library(forecast)
library(tseries)
ar<-auto.arima(dlTs,ic="aic",trace = TRUE)
attributes(ar)
par(mfrow=c(1,1))
myfc<-forecast(ar,level=c(95),h=10*4)
myfc
plot(myfc)
par(mfrow=c(1,2))
acf(ts(ar$residuals),main='ACF Residual')
pacf(ts(ar$residuals),main='PACF Residual')

Inference:

We successfully performed forcasting for given two non-stationary datasets.

You might also like