library(TTR)
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(graphics)
library(forecast)
library(TSA)
## Registered S3 methods overwritten by 'TSA':
##   method       from    
##   fitted.Arima forecast
##   plot.Arima   forecast
## 
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
## 
##     acf, arima
## The following object is masked from 'package:utils':
## 
##     tar
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric

####1. Database Daily Minimum Temperatures

setwd("c:/Users/Ilham Kurnia/Documents/SEMESTER 6/UTS/MPDW")
dt1<-read.csv("daily-minimum-temperatures-in-me.csv")
head(dt1)

Menjadikan data time series dan membuat plot

dt1.ts1<-ts(dt1$Daily.minimum.temperatures)

ts.plot(dt1.ts1, xlab="Time Period", ylab ="Temperatures", main="Plot Data Time Series Daily Minimum Temperatures", col ="red")

Berdasarkan plot di atas terlihat bahwa data memiliki trend naik turun sehingga dapat diasmusikan tidak stationer.

Plot ACF dan PACF

acf(dt1.ts1, lag.max = 20, main = "Plot ACF Daily Minimum Temperatures")

pacf(dt1.ts1, lag.max = 20, main = "Plot PACF Daily Minimum Temperatures")

Berdasarkan plot ACF terlihat tails off atau menurun secara perlahan menunjukan data tidak tidak stationer dalam rataan. Sedangkan plot PACF terlihat cuts off setelah lag ke-1 menunjukan stationer dengan model tentatif AR(1). Selanjutnya melakukan Uji Augmented Fuller untuk uji lebih lanjut.

Uji Augmented Fuller

adf.test(dt1.ts1)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dt1.ts1
## Dickey-Fuller = -2.3545, Lag order = 7, p-value = 0.4273
## alternative hypothesis: stationary

Berdasarkan Uji Augmented Fuller di atas kita mendapatkan p-value = 0.4273 dengan H1 data stationer sehingga tak tolak H0. Artinya belum cukup bukti menyatakan bahwa data stationer pada taraf nyata 5%.

Melakukan differencing pertama dan Plot differrencing pertama

dif1 <- diff(dt1.ts1, differences = 1)

plot.ts(dif1, lty=1, ylab = expression(Ydif[t]), col = "red", main="Plot Data Time Series Daily Minimum Temperatures Setelah Differencing Pertama")

Berdasarkan plot di atas terlihat data sudah stationer karena rataan sudah konstan di satu titik.

Plot ACF dan PACF setelah Differencing pertama

acf(dif1, lag.max = 20, main="Plot ACF Daily Minimum Temperatures Setelah Differencing Pertama")

Pacf(dif1, lag.max = 20, main="Plot PACF Daily Minimum Temperatures Setelah Differencing Pertama")

Plot ACF terlihat stationer dengan cuts off setelah lag ke-3. Sedangkan Plot PACF terlihat tails off dengan model tentatif MA(3).

Uji Augmented Fuller setelah differencing pertama

adf.test(dif1)
## Warning in adf.test(dif1): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dif1
## Dickey-Fuller = -10.838, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary

Berdasarkan Uji Augmented Fuller di atas kita mendapatkan p-value = 0.01 dengan H1 data stationer sehingga tolak H0. Artinya cukup bukti menyatakan bahwa data stationer pada taraf nyata 5%.

Membuat Plot EACF Setelah Pembedaan Pertama untuk Menentukan Model Dugaan

eacf(dif1)
## AR/MA
##   0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 x x x o o o o o o o o  o  o  o 
## 1 x x x o o o o o o o o  o  o  o 
## 2 x x x o o o o o o o o  o  o  o 
## 3 x x x x o o o o o o o  o  o  o 
## 4 x x x o o o o o o o o  o  o  o 
## 5 x x o o o o o o o o o  o  o  o 
## 6 x x x o x o o x o o o  o  o  o 
## 7 x x o o o x o o o o o  o  o  o

Berdasarkan hasil plot EACF di atas, diperoleh 4 model dugaan yang dapat diduga dari data daily minimum temperatures sebagai model tentatifnya yaitu ARIMA(0,1,3), ARIMA(1,1,3), ARIMA(2,1,3), dan ARIMA(4,1,3). Untuk memastikan model tentatif dari keempat model dugaan tersebut, dilakukan uji lanjut yaitu Uji Signifikansi Parameter.

Melakukan uji signifikansi parameter setelah pembedaan pertama

dugaan.model1 <- arima(dt1.ts1, order=c(0,1,3), method = "ML")
coeftest(dugaan.model1)
## 
## z test of coefficients:
## 
##      Estimate Std. Error z value  Pr(>|z|)    
## ma1 -0.376190   0.053355 -7.0507 1.781e-12 ***
## ma2 -0.344919   0.051104 -6.7494 1.485e-11 ***
## ma3 -0.130385   0.054851 -2.3771   0.01745 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada seluruh parameter. Dengan demikian, seluruh parameter signifikan untuk dugaan model tentatif ARIMA(0,1,3).

dugaan.model2 <- arima(dt1.ts1, order=c(1,1,3), method = "ML")
coeftest(dugaan.model2)
## 
## z test of coefficients:
## 
##     Estimate Std. Error z value  Pr(>|z|)    
## ar1 -0.24257    0.25980 -0.9337 0.3504726    
## ma1 -0.13889    0.25243 -0.5502 0.5821852    
## ma2 -0.44265    0.11953 -3.7032 0.0002129 ***
## ma3 -0.23183    0.10921 -2.1228 0.0337699 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada parameter ma2 dan ma3. Dengan demikian, hanya parameter ma2 dan ma3 yang signifikan untuk dugaan model tentatif ARIMA(1,1,3).

dugaan.model3 <- arima(dt1.ts1, order=c(2,1,3), method = "ML")
coeftest(dugaan.model3)
## 
## z test of coefficients:
## 
##     Estimate Std. Error z value Pr(>|z|)
## ar1  0.11927    0.54814  0.2176   0.8278
## ar2 -0.18432    0.17438 -1.0570   0.2905
## ma1 -0.50459    0.54862 -0.9197   0.3577
## ma2 -0.13859    0.35596 -0.3893   0.6970
## ma3 -0.19149    0.17271 -1.1088   0.2675

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value > alpha = 0.05 pada seluruh parameter. Dengan demikian, tidak ada parameter yang signifikan untuk dugaan model tentatif ARIMA(2,1,3).

dugaan.model4 <- arima(dt1.ts1, order=c(4,1,3), method = "ML")
coeftest(dugaan.model4)
## 
## z test of coefficients:
## 
##      Estimate Std. Error  z value  Pr(>|z|)    
## ar1 -0.718846   0.057744 -12.4488 < 2.2e-16 ***
## ar2 -0.530530   0.078395  -6.7674 1.312e-11 ***
## ar3  0.250187   0.077751   3.2178  0.001292 ** 
## ar4 -0.175673   0.055377  -3.1723  0.001512 ** 
## ma1  0.349233   0.030449  11.4694 < 2.2e-16 ***
## ma2 -0.111657   0.035901  -3.1101  0.001870 ** 
## ma3 -0.894096   0.030041 -29.7623 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada seluruh parameter. Dengan demikian, seluruh parameter signifikan untuk dugaan model tentatif ARIMA(4,1,3).

Berdasarkan keempat dugaan model tentatif tersebut dapat disimpulkan bahwa model tentatif ARIMA(0,1,3) dan ARIMA(4,1,3) menjadi model tentatif yang paling cocok digunakan untuk tahapan analisis selanjutnya.

Melakukan uji kestasioneran setelah pembedaan pertama (Uji Augmented Dickey Fuller)

Baik secara uji eksploratif maupun uji formal, diperoleh hasil bahwa data tersebut stasioner. Artinya asumsi kestasioneran data telah terpenuhi. Sehingga pembedaan (differencing) dilakukan cukup sampai pembedaan pertama. Dengan model tentatif dari data daily minimum temperatures adalah ARIMA(0,1,3) dan ARIMA(4,1,3).

####2. Database Electric Production

setwd("c:/Users/Ilham Kurnia/Documents/SEMESTER 6/UTS/MPDW")
dt2<-read.csv("Electric_Production.csv")
head(dt2)

Menjadikan data time series dan membuat plot

dt2.ts2<-ts(dt2$IPG2211A2N)

ts.plot(dt2.ts2, xlab="Time Period", ylab ="Electric Production", main="Plot Data Time Series Electric Producton", col ="red")

Berdasarkan plot di atas terlihat bahwa data relatif konstan sehingga dapat diasmusikan stationer.

Plot ACF dan PACF

acf(dt2.ts2, lag.max = 20, main = "Plot ACF Electric Production")

pacf(dt2.ts2, lag.max = 20, main = "Plot PACF Electric Production")

Plot ACF terlihat cuts off setelah lag ke-1 menunjukan data stationer. Sedangkan plot PACF terlihat tail off setelah lag ke-1 menunjukan stationer.

Membuat plot EACF untuk menentukan model dugaan

eacf(dt2.ts2)
## AR/MA
##   0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 x o x o x x x o x o x  x  x  o 
## 1 x o x o x x x x x o x  x  x  x 
## 2 x x x x x x x x x x x  x  x  x 
## 3 x x o o o o o o o o o  x  x  x 
## 4 x x x o o o o o o o o  x  x  x 
## 5 x x x x o o o o o o o  x  o  o 
## 6 x x x x o o o o o o o  x  x  o 
## 7 x x o x x o o o o o o  x  o  o

Berdasarkan hasil plot EACF di atas, diperoleh 4 model dugaan yang dapat diduga dari data electric production sebagai model tentatifnya yaitu ARIMA(0,0,1), ARIMA(3,0,2), ARIMA(4,0,3), dan ARIMA(3,0,3). Untuk memastikan model tentatif dari keempat model dugaan tersebut, dilakukan uji lanjut yaitu Uji Signifikansi Parameter.

Melakukan uji signifikansi parameter

dugaan.model1 <- arima(dt2.ts2, order=c(0,0,1), method = "ML")
coeftest(dugaan.model1)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value  Pr(>|z|)    
## ma1        0.784482   0.028321   27.70 < 2.2e-16 ***
## intercept 98.464776   0.798692  123.28 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada seluruh parameter. Dengan demikian, seluruh parameter signifikan untuk dugaan model tentatif ARIMA(0,0,1).

dugaan.model2 <- arima(dt2.ts2, order=c(3,0,2), method = "ML")
coeftest(dugaan.model2)
## 
## z test of coefficients:
## 
##            Estimate Std. Error z value  Pr(>|z|)    
## ar1        1.957865   0.031671  61.820 < 2.2e-16 ***
## ar2       -1.860912   0.052258 -35.610 < 2.2e-16 ***
## ar3        0.893386   0.029550  30.233 < 2.2e-16 ***
## ma1       -1.078578   0.030680 -35.156 < 2.2e-16 ***
## ma2        0.290811   0.020046  14.507 < 2.2e-16 ***
## intercept 97.569873   4.605480  21.186 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada seluruh parameter. Dengan demikian, seluruh parameter signifikan untuk dugaan model tentatif ARIMA(3,0,2).

dugaan.model3 <- arima(dt2.ts2, order=c(4,0,3), method = "ML")
coeftest(dugaan.model3)
## 
## z test of coefficients:
## 
##            Estimate Std. Error  z value Pr(>|z|)    
## ar1        0.869205   0.045532  19.0898  < 2e-16 ***
## ar2       -0.028553   0.048342  -0.5906  0.55476    
## ar3       -0.970810   0.048340 -20.0830  < 2e-16 ***
## ar4        0.839695   0.042463  19.7749  < 2e-16 ***
## ma1       -0.074245   0.035658  -2.0822  0.03733 *  
## ma2       -0.030799   0.038380  -0.8025  0.42228    
## ma3        0.943979   0.037393  25.2450  < 2e-16 ***
## intercept 98.486976   1.442149  68.2918  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada parameter ar1, ar3, ar4, ma1, dan ma3. Dengan demikian, parameter ar1, ar3, ar4, ma1, dan ma3 signifikan untuk dugaan model tentatif ARIMA(4,0,3).

dugaan.model4 <- arima(dt2.ts2, order=c(3,0,3), method = "ML")
coeftest(dugaan.model4)
## 
## z test of coefficients:
## 
##            Estimate Std. Error  z value  Pr(>|z|)    
## ar1        1.936860   0.031856  60.8002 < 2.2e-16 ***
## ar2       -1.936596   0.031875 -60.7562 < 2.2e-16 ***
## ar3        0.936932   0.031937  29.3364 < 2.2e-16 ***
## ma1       -1.333769   0.084293 -15.8231 < 2.2e-16 ***
## ma2        1.283265   0.089064  14.4083 < 2.2e-16 ***
## ma3       -0.304591   0.088232  -3.4522 0.0005561 ***
## intercept 98.545667   2.221278  44.3644 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada seluruh parameter. Dengan demikian, seluruh parameter signifikan untuk dugaan model tentatif ARIMA(3,0,3).

Berdasarkan keempat dugaan model tentatif tersebut dapat disimpulkan bahwa model tentatif ARIMA(0,0,1), ARIMA(3,0,2), dan ARIMA(3,0,3) menjadi model tentatif yang paling cocok digunakan untuk tahapan analisis selanjutnya.

Berdasarkan uji eksploratif diperoleh hasil yang sama antara plot data deret waktu, plot ACF dan PACF yang menunjukkan bahwa data stasioner. Namun tetap perlu dilakukan uji lebih lanjut menggunakan Uji Formal yaitu Uji Augmented Dickey Fuller untuk lebih memastikan.

Uji Augmented Fuller

adf.test(dt2.ts2)
## Warning in adf.test(dt2.ts2): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dt2.ts2
## Dickey-Fuller = -4.3717, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary

Berdasarkan Uji Augmented Fuller di atas kita mendapatkan p-value = 0.01 H1 data stationer sehingga tolak H0. Artinya cukup bukti menyatakan bahwa data stationer pada taraf nyata 5%.

####3. Database Monthly Beer Production In Austr

setwd("c:/Users/Ilham Kurnia/Documents/SEMESTER 6/UTS/MPDW")
dt3<-read.csv("monthly-beer-production-in-austr.csv")
head(dt3)

Menjadikan data time series dan membuat plot

dt3.ts3<-ts(dt3$Monthly.beer.production)

ts.plot(dt3.ts3, xlab="Time Period", ylab ="Beer Production", main="Plot Data Time Series Electric Producton in Austr", col ="red")

Berdasarkan plot di atas terlihat bahwa data relatif konstan sehingga dapat diasmusikan stationer.

Plot ACF dan PACF

acf(dt3.ts3, lag.max = 20, main = "Plot ACF Electric Production")

pacf(dt3.ts3, lag.max = 20, main = "Plot PACF Electric Production")

Plot ACF terlihat cuts off setelah lag ke-1 menunjukan data stationer. Sedangkan plot PACF terlihat tail off setelah lag ke-1 menunjukan stationer.

Membuat plot EACF untuk menentukan model dugaan

eacf(dt3.ts3)
## AR/MA
##   0 1 2 3 4 5 6 7 8 9 10 11 12 13
## 0 x o o x x x x o o o x  x  x  o 
## 1 o o o x o o o o o o x  x  o  o 
## 2 o o o o o o o o o o o  x  o  o 
## 3 o x o o o x o o o o o  x  x  o 
## 4 o x o o o x o o o o o  x  o  o 
## 5 o x o x x o o o o o o  x  o  o 
## 6 o o o o x o o o o o o  x  o  o 
## 7 x o o o x o o o o o o  x  x  o

Berdasarkan hasil plot EACF di atas, diperoleh 4 model dugaan yang dapat diduga dari data monthly beer production sebagai model tentatifnya yaitu ARIMA(1,0,0), ARIMA(1,0,4), ARIMA(2,0,1) dan ARIMA(3,0,2). Untuk memastikan model tentatif dari keempat model dugaan tersebut, dilakukan uji lanjut yaitu Uji Signifikansi Parameter.

Melakukan uji signifikansi parameter

dugaan.model1 <- arima(dt3.ts3, order=c(1,0,0), method = "ML")
coeftest(dugaan.model1)
## 
## z test of coefficients:
## 
##             Estimate Std. Error z value  Pr(>|z|)    
## ar1         0.419343   0.083639  5.0137 5.338e-07 ***
## intercept 154.565591   3.123924 49.4780 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada seluruh parameter. Dengan demikian, seluruh parameter signifikan untuk dugaan model tentatif ARIMA(1,0,0).

dugaan.model2 <- arima(dt3.ts3, order=c(1,0,4), method = "ML")
coeftest(dugaan.model2)
## 
## z test of coefficients:
## 
##             Estimate Std. Error z value  Pr(>|z|)    
## ar1         0.598467   0.194809  3.0721  0.002126 ** 
## ma1        -0.087231   0.208646 -0.4181  0.675890    
## ma2        -0.325773   0.115854 -2.8119  0.004925 ** 
## ma3         0.191037   0.139805  1.3665  0.171797    
## ma4        -0.288049   0.101044 -2.8507  0.004362 ** 
## intercept 154.703927   2.127669 72.7105 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada parameter ar1, ma2, dan ma4. Dengan demikian, parameter ar1, ma2, dan ma4 signifikan untuk dugaan model tentatif ARIMA(1,0,4).

dugaan.model3 <- arima(dt3.ts3, order=c(2,0,1), method = "ML")
coeftest(dugaan.model3)
## 
## z test of coefficients:
## 
##             Estimate Std. Error z value  Pr(>|z|)    
## ar1        -0.411628   0.090044 -4.5714 4.845e-06 ***
## ar2         0.252947   0.090245  2.8029  0.005065 ** 
## ma1         0.999996   0.102462  9.7597 < 2.2e-16 ***
## intercept 154.503198   2.939931 52.5533 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada seluruh parameter. Dengan demikian, seluruh parameter signifikan untuk dugaan model tentatif ARIMA(2,0,1).

dugaan.model4 <- arima(dt3.ts3, order=c(3,0,2), method = "ML")
coeftest(dugaan.model4)
## 
## z test of coefficients:
## 
##             Estimate Std. Error z value  Pr(>|z|)    
## ar1         0.353921   0.138223  2.5605  0.010452 *  
## ar2         0.521883   0.099105  5.2660 1.395e-07 ***
## ar3        -0.285192   0.091640 -3.1121  0.001858 ** 
## ma1         0.241959   0.124373  1.9454  0.051723 .  
## ma2        -0.758025   0.119321 -6.3528 2.114e-10 ***
## intercept 154.781073   2.033708 76.1078 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Berdasarkan hasil uji signifikansi parameter tersebut, diperoleh nilai p-value < alpha = 0.05 pada parameter ar1, ar2, ar3, ma1, dan ma2. Dengan demikian, parameter ar1, ar2, ar3, ma1, dan ma2 signifikan untuk dugaan model tentatif ARIMA(3,0,2).

Berdasarkan keempat dugaan model tentatif tersebut dapat disimpulkan bahwa model tentatif ARIMA(1,0,0) dan ARIMA(2,0,1) menjadi model tentatif yang paling cocok digunakan untuk tahapan analisis selanjutnya.

Berdasarkan uji eksploratif diperoleh hasil yang sama antara plot data deret waktu, plot ACF dan PACF yang menunjukkan bahwa data stasioner. Namun tetap perlu dilakukan uji lebih lanjut menggunakan Uji Formal yaitu Uji Augmented Dickey Fuller untuk lebih memastikan.

Uji Augmented Fuller

adf.test(dt3.ts3)
## Warning in adf.test(dt3.ts3): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  dt3.ts3
## Dickey-Fuller = -5.6857, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary

Berdasarkan Uji Augmented Fuller di atas kita mendapatkan p-value = 0.01 H1 data stationer sehingga tolak H0. Artinya cukup bukti menyatakan bahwa data stationer pada taraf nyata 5%

###Kesimpulan

Berdasarkan eksploratif dengan plot ACF dan PACF atau Uji Augmented Dickey Fuller. Data Daily Minimum temperature tidak stationer. Sehingga dilakukan differencing satu kali sampai stationer. Sedangkan data Electric Production dan Beer Production in Austr.

Dengan menggunakan Uji Signifikansi Parameter pada setiap dugaan model tentatif yang diperoleh, ketiga data tersebut memiliki model tentatif yang berbeda-beda yaitu :

  1. Daily Minimum Temperatures dengan model tentatifnya adalah ARIMA(0,1,3) dan ARIMA(4,1,3)
  2. Electric Production dengan model tentatifnya adalah arima(0,0,1) dan ARIMA(3,0,3)
  3. Monthly Beer Production dengan model tentatifnya adalah ARIMA(1,0,0) dan ARIMA(2,0,1).