ARIMA

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

> View(mydata)

> mydata<- read.csv("file:///C:/Users/JENSENATICS/Desktop/thesis/Coffeeproduction2.csv")


> attach(mydata)
> View(mydata)
> library(MASS)
> library(tseries)
‘tseries’ version: 0.10-46

‘tseries’ is a package for time series analysis and computational finance.

See ‘library(help="tseries")’ for details.


> library(forecast)
This is forecast 8.5
Use suppressPackageStartupMessages() to eliminate package startup messages.
> lnstock=log(C[1:11])
Error in C[1:11] : object of type 'closure' is not subsettable
> #plot and convert to ln format
> lnstock=log(C[1:11])
Error in C[1:11] : object of type 'closure' is not subsettable
> #plot and convert to ln format
> lnstock=log(C[1:11])
Error in C[1:11] : object of type 'closure' is not subsettable
> lnstock
Error: object 'lnstock' not found
> #plot and convert to ln format
> lnstock=log(C[1.11])
Error in C[1.11] : object of type 'closure' is not subsettable
> #plot and convert to ln format
> lnstock=log(CP[1.11])
> #plot and convert to ln format
> lnstock=log(CP[1:11])
> lnstock
[1] 11.49146 11.48687 11.47660 11.45674 11.39105 11.39575 11.27256 11.23128 11.18916
[10] 11.13929 11.03615
> acf(lnstock,lag.max = 11)
> pacf(lnstock,lag.max = 11)
> difflnstock=diff(lnstock,1)
> adf.test(lnstock)

Augmented Dickey-Fuller Test


data: lnstock
Dickey-Fuller = -1.8042, Lag order = 2, p-value = 0.647
alternative hypothesis: stationary

> difflnstock=diff(lnstock,2)
> difflnstock=diff(lnstock,0)
Error in diff.default(lnstock, 0) :
'lag' and 'differences' must be integers >= 1
> difflnstock=diff(lnstock,1)
> adf.test(lnstock)

Augmented Dickey-Fuller Test

data: lnstock
Dickey-Fuller = -1.8042, Lag order = 2, p-value = 0.647
alternative hypothesis: stationary

> adf.test(difflnstock)

Augmented Dickey-Fuller Test


data: difflnstock
Dickey-Fuller = -1.7894, Lag order = 2, p-value = 0.6526
alternative hypothesis: stationary
>
> pricearima<- ts(lnstock, start=c(2007,1),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,2017),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,20),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,25),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,30),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,90),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,30),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,1),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,90),frequency = 11)
> pricearima<- ts(lnstock, start=c(2007,100),frequency = 11)
> fitlnstock<- auto.arima(pricearima)
Warning message:
In value[[3L]](cond) :
The chosen test encountered an error, so no seasonal differencing is selected. Check th
time series data.
> pricearima<- ts(lnstock, start=c(2007,0),frequency = 11)
> pricearima<- ts(lnstock, start=c(2017,0),frequency = 11)
> fitlnstock<- auto.arima(pricearima)
Warning message:
In value[[3L]](cond) :
The chosen test encountered an error, so no seasonal differencing is selected. Check th
time series data.
> pricearima<- ts(lnstock, start=c(2007,1),frequency = 1)
> fitlnstock<- auto.arima(pricearima)
> fitlnstock
Series: pricearima
ARIMA(0,1,0) with drift

Coefficients:
drift
-0.0455
s.e. 0.0126

sigma^2 estimated as 0.001782: log likelihood=18.03


AIC=-32.06 AICc=-30.34 BIC=-31.45
> plot(pricearima,type = "l")
> title('jb c')
> productionarima<- ts(lnstock, start=c(2007,1),frequency = 1)
> fitlnstock<- auto.arima(productionarima)
> fitlnstock
Series: productionarima
ARIMA(0,1,0) with drift

Coefficients:
drift
-0.0455
s.e. 0.0126

sigma^2 estimated as 0.001782: log likelihood=18.03


AIC=-32.06 AICc=-30.34 BIC=-31.45
> plot(productionarima,type = "l")
> title('Coffee production')
> exp(lnstock)
[1] 97876.68 97427.99 96432.95 94536.01 88526.09 88943.00 78633.92 75454.49 72341.82
[10] 68822.93 62077.95
> forecastedvalues_ln=forecast(fitlnstock,h=11)
> forecastedvalues_ln
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2018 10.99061 10.93651 11.04472 10.90787 11.07336
2019 10.94508 10.86857 11.02159 10.82807 11.06210
2020 10.89955 10.80584 10.99326 10.75624 11.04286
2021 10.85402 10.74582 10.96222 10.68854 11.01950
2022 10.80849 10.68751 10.92946 10.62347 10.99350
2023 10.76296 10.63043 10.89548 10.56028 10.96563
2024 10.71742 10.57428 10.86056 10.49851 10.93634
2025 10.67189 10.51887 10.82492 10.43786 10.90592
2026 10.62636 10.46406 10.78867 10.37814 10.87458
2027 10.58083 10.40974 10.75191 10.31918 10.84248
2028 10.53530 10.35586 10.71473 10.26087 10.80972
> forecastedvalues_ln=forecast(fitlnstock,h=3)
> forecastedvalues_ln
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2018 10.99061 10.93651 11.04472 10.90787 11.07336
2019 10.94508 10.86857 11.02159 10.82807 11.06210
2020 10.89955 10.80584 10.99326 10.75624 11.04286
> plot(forecastedvalues_ln)
> forecastedvaluesextracted=as.numeric(forecastedvalues_ln$mean)
> finalforecastvalues=exp(forecastedvaluesextracted)
> finalforecastvalues
[1] 59314.82 56674.67 54152.04
>
> Box.test(fitlnstock$residuals,lag = 2,type = "Lyung-box")
Error in match.arg(type) :
'arg' should be one of “Box-Pierce”, “Ljung-Box”
> Box.test(fitlnstock$residuals,lag = 2,type = "Lyung-box")
Error in match.arg(type) :
'arg' should be one of “Box-Pierce”, “Ljung-Box”
> Box.test(fitlnstock$residuals,lag = 2,type = "Ljung-box")
Error in match.arg(type) :
'arg' should be one of “Box-Pierce”, “Ljung-Box”
> Box.test(fitlnstock$residuals,lag = 2,type = "Ljung-Box")
Box-Ljung test

data: fitlnstock$residuals
X-squared = 1.1, df = 2, p-value = 0.577

> Box.test(fitlnstock$residuals,lag = 4,type = "Ljung-Box")

Box-Ljung test
data: fitlnstock$residuals
X-squared = 2.0561, df = 4, p-value = 0.7254

> Box.test(fitlnstock$residuals,lag = 6,type = "Ljung-Box")

Box-Ljung test

data: fitlnstock$residuals
X-squared = 4.6182, df = 6, p-value = 0.5936

>

You might also like