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

UAS ANALISIS DERET WAKTU

“ Simulasi ARIMA musiman”

Dosen Pengampu :
Aswi, S.Pd., M.Si., Ph.D.

Oleh:
Dedi Ariyanto
210112502045
Kelas 02 Statistika 2021

Program Studi Statistika


Fakultas Matematika dan Ilmu Pengetahuan Alam
Universitas Negeri Makassar
library(tseries)

## Registered S3 method overwritten by 'quantmod':


## method from
## as.zoo.data.frame zoo

library(forecast)
library(lmtest) #untuk coeftest

## Loading required package: zoo

##
## Attaching package: 'zoo'

## The following objects are masked from 'package:base':


##
## as.Date, as.Date.numeric

library(nortest) #untuk normality test

data <- ead_csv("C:/Users/Abi/Downloads/final.xlsx",sep=",")


data

## t zt
## 1 1 681.0
## 2 2 1136.0
## 3 3 179.0
## 4 4 178.0
## 5 5 91.0
## 6 6 15.0
## 7 7 50.0
## 8 8 8.0
## 9 9 31.0
## 10 10 281.0
## 11 11 213.0
## 12 12 1308.0
## 13 13 568.0
## 14 14 820.0
## 15 15 283.0
## 16 16 141.0
## 17 17 39.0
## 18 18 13.0
## 19 19 14.0
## 20 20 0.0
## 21 21 0.0
## 22 22 2.0
## 23 23 57.0
## 24 24 328.0
## 25 25 105.0
## 26 26 88.0
## 27 27 187.0
## 28 28 424.0
## 29 29 241.0
## 30 30 145.0
## 31 31 316.0
## 32 32 71.0
## 33 33 69.0
## 34 34 221.0
## 35 35 541.0
## 36 36 790.0
## 37 37 1125.0
## 38 38 915.0
## 39 39 435.0
## 40 40 413.0
## 41 41 129.0
## 42 42 73.0
## 43 43 106.0
## 44 44 4.0
## 45 45 21.0
## 46 46 308.0
## 47 47 281.0
## 48 48 928.0
## 49 49 748.0
## 50 50 838.0
## 51 51 293.0
## 52 52 235.0
## 53 53 127.0
## 54 54 210.0
## 55 55 28.0
## 56 56 0.4
## 57 57 17.0
## 58 58 220.0
## 59 59 406.0
## 60 60 391.0
## 61 61 858.4
## 62 62 867.0
## 63 63 601.4
## 64 64 237.8
## 65 65 76.8
## 66 66 243.8
## 67 67 108.0
## 68 68 0.0
## 69 69 118.0
## 70 70 181.8
## 71 71 539.2
## 72 72 1015.0
## 73 73 697.6
## 74 74 346.2
## 75 75 528.2
## 76 76 408.8
## 77 77 180.0
## 78 78 53.8
## 79 79 1.4
## 80 80 0.0
## 81 81 3.4
## 82 82 5.0
## 83 83 229.8
## 84 84 580.8
## 85 85 610.8
## 86 86 584.8
## 87 87 220.8
## 88 88 175.0
## 89 89 158.8
## 90 90 31.4
## 91 91 20.2
## 92 92 14.8
## 93 93 21.8
## 94 94 26.6
## 95 95 294.8
## 96 96 1054.0
## 97 97 448.0
## 98 98 685.2
## 99 99 676.2
## 100 100 149.0
## 101 101 112.8
## 102 102 98.0
## 103 103 0.9
## 104 104 0.0
## 105 105 0.4
## 106 106 264.4
## 107 107 179.8
## 108 108 489.0
## 109 109 379.4
## 110 110 211.8
## 111 111 304.0
## 112 112 297.8
## 113 113 100.0
## 114 114 5.4
## 115 115 3.6
## 116 116 1.0
## 117 117 0.0
## 118 118 263.0
## 119 119 347.2
## 120 120 545.0

head(data)

## t zt
## 1 1 681
## 2 2 1136
## 3 3 179
## 4 4 178
## 5 5 91
## 6 6 15

tail(data)

## t zt
## 115 115 3.6
## 116 116 1.0
## 117 117 0.0
## 118 118 263.0
## 119 119 347.2
## 120 120 545.0

#plot time series


#melabel data zt dengan "Penjualan"
Curah <- data$zt
Bulan <- data$t
#Tahap Identifikasi
ts.plot(Curah)

#cek kestasioneran data


adf.test(Curah)

## Warning in adf.test(Curah): p-value smaller than printed p-value

##
## Augmented Dickey-Fuller Test
##
## data: Curah
## Dickey-Fuller = -6.8457, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary

#plot ACF dan PACF


acf(Curah, lag.max = 56)

par(mfrow=c(1,2))
acf(Curah, lag.max = 56)
pacf(Curah, lag.max = 56)

Kita melakukan differencing karena aapola dari acfnya masih menunjukkan turun dengan
lambat disekitar musimannya
#differencing 1 non musiman
differencing1 <- diff(Curah, differences =1 )
differencing1

## [1] 455.0 -957.0 -1.0 -87.0 -76.0 35.0 -42.0 23.0 250.0 -
68.0
## [11] 1095.0 -740.0 252.0 -537.0 -142.0 -102.0 -26.0 1.0 -14.0
0.0
## [21] 2.0 55.0 271.0 -223.0 -17.0 99.0 237.0 -183.0 -96.0
171.0
## [31] -245.0 -2.0 152.0 320.0 249.0 335.0 -210.0 -480.0 -22.0 -
284.0
## [41] -56.0 33.0 -102.0 17.0 287.0 -27.0 647.0 -180.0 90.0 -
545.0
## [51] -58.0 -108.0 83.0 -182.0 -27.6 16.6 203.0 186.0 -15.0
467.4
## [61] 8.6 -265.6 -363.6 -161.0 167.0 -135.8 -108.0 118.0 63.8
357.4
## [71] 475.8 -317.4 -351.4 182.0 -119.4 -228.8 -126.2 -52.4 -1.4
3.4
## [81] 1.6 224.8 351.0 30.0 -26.0 -364.0 -45.8 -16.2 -127.4 -
11.2
## [91] -5.4 7.0 4.8 268.2 759.2 -606.0 237.2 -9.0 -527.2 -
36.2
## [101] -14.8 -97.1 -0.9 0.4 264.0 -84.6 309.2 -109.6 -167.6
92.2
## [111] -6.2 -197.8 -94.6 -1.8 -2.6 -1.0 263.0 84.2 197.8

#plot time series dan plot ACF data hasil


ts.plot(differencing1)
acf(differencing1, lag.max = 56)

pacf(differencing1,lag.max = 56)

#cek kestasioneran data


adf.test(differencing1)

## Warning in adf.test(differencing1): p-value smaller than printed p-value


##
## Augmented Dickey-Fuller Test
##
## data: differencing1
## Dickey-Fuller = -6.5649, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary

#differencing 1 musiman 17 dari data yang sudah didifferencing 1


diffnonmus_mus12 <- diff(differencing1, lag = 12)
diffnonmus_mus12

## [1] -203.0 420.0 -141.0 -15.0 50.0 -34.0 28.0 -23.0 -248.0
123.0
## [11] -824.0 517.0 -269.0 636.0 379.0 -81.0 -70.0 170.0 -231.0 -
2.0
## [21] 150.0 265.0 -22.0 558.0 -193.0 -579.0 -259.0 -101.0 40.0 -
138.0
## [31] 143.0 19.0 135.0 -347.0 398.0 -515.0 300.0 -65.0 -36.0
176.0
## [41] 139.0 -215.0 74.4 -0.4 -84.0 213.0 -662.0 647.4 -81.4
279.4
## [51] -305.6 -53.0 84.0 46.2 -80.4 101.4 -139.2 171.4 490.8 -
784.8
## [61] -360.0 447.6 244.2 -67.8 -293.2 83.4 106.6 -114.6 -62.2 -
132.6
## [71] -124.8 347.4 325.4 -546.0 73.6 212.6 -1.2 41.2 -4.0
3.6
## [81] 3.2 43.4 408.2 -636.0 263.2 355.0 -481.4 -20.0 112.6 -
85.9
## [91] 4.5 -6.6 259.2 -352.8 -450.0 496.4 -404.8 101.2 521.0 -
161.6
## [101] -79.8 95.3 -1.7 -1.4 -1.0 168.8 -111.4

par(mfrow=c(1,2))
Setelah dilakukan differencing kita Kembali membuat plot acf dan pacf dan melihat bahwa
acfnya cut off di lag pertama dan pacfnya turun secara eksponensial sehinggal model yang
dapat di ajaukan adalah MA(1)

acf(diffnonmus_mus12,lag.max = 56)
pacf(diffnonmus_mus12,lag.max = 55)
#plot ts, plot ACF dan hasil differencing non musiman dan musiman 12
ts.plot(diffnonmus_mus12)

par(mfrow=c(1,2))
acf(diffnonmus_mus12, lag.max = 56)
pacf(diffnonmus_mus12, lag.max = 56)
Kemudian kita mencari model untuk musiman 12 dengan melihat acf dan pacfnya dan
didapatkan dugaan model arima(0,1,1)

#cek kestasioneran data


adf.test(diffnonmus_mus12)

## Warning in adf.test(diffnonmus_mus12): p-value smaller than printed p-


value

##
## Augmented Dickey-Fuller Test
##
## data: diffnonmus_mus12
## Dickey-Fuller = -6.4138, Lag order = 4, p-value = 0.01
## alternative hypothesis: stationary

#Terdapat beberapa dugaan model ARIMA sementara yaitu ARIMA (0,1,1)(0,1,1),


periode=12
#ARIMA (0,1,1)(0,1,1) atau ARIMA (0,1,1)(1,1,1) atau ARIMA (0,1,1)(1,1,0),
periode=12

model1 <- arima(Curah, order=c(0,1,1), seasonal =


list(order=c(0,1,1),period=12), method = "ML")
model1

##
## Call:
## arima(x = Curah, order = c(0, 1, 1), seasonal = list(order = c(0, 1, 1),
period = 12),
## method = "ML")
##
## Coefficients:
## ma1 sma1
## -0.7190 -0.9999
## s.e. 0.0965 0.2887
##
## sigma^2 estimated as 32663: log likelihood = -722.04, aic = 1450.08

#Diagnostic Checking
#1. uji kesignifikanan parameter: uji t
coeftest(model1)

##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## ma1 -0.719007 0.096459 -7.4540 9.054e-14 ***
## sma1 -0.999870 0.288723 -3.4631 0.000534 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#2. pengujian residual apakah white noise


Box.test(model1$residuals, type="Ljung")

##
## Box-Ljung test
##
## data: model1$residuals
## X-squared = 0.55244, df = 1, p-value = 0.4573

#3. pengujian residual apakah berdistribusi normal


shapiro.test(model1$residuals)

##
## Shapiro-Wilk normality test
##
## data: model1$residuals
## W = 0.93262, p-value = 1.407e-05

#shapiro-francia normality test


sf.test(model1$residuals)

##
## Shapiro-Francia normality test
##
## data: model1$residuals
## W = 0.92578, p-value = 1.875e-05

#Alternative model kedua ARIMA (0,0,0)(0,1,1), periode=12

model2 <- arima(Curah, order=c(0,1,1), seasonal =


list(order=c(1,1,1),period=12), method = "ML")
model2

##
## Call:
## arima(x = Curah, order = c(0, 1, 1), seasonal = list(order = c(1, 1, 1),
period = 12),
## method = "ML")
##
## Coefficients:
## ma1 sar1 sma1
## -0.7664 -0.1778 -0.8933
## s.e. 0.1015 0.1246 0.2348
##
## sigma^2 estimated as 33808: log likelihood = -721.07, aic = 1450.13

#Diagnostic Checking
#1. uji kesignifikanan parameter: uji t
coeftest(model2)
##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## ma1 -0.76641 0.10149 -7.5513 4.311e-14 ***
## sar1 -0.17784 0.12457 -1.4277 0.1533891
## sma1 -0.89332 0.23481 -3.8045 0.0001421 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#2. pengujian residual apakah white noise


Box.test(model2$residuals, type="Ljung")

##
## Box-Ljung test
##
## data: model2$residuals
## X-squared = 0.6843, df = 1, p-value = 0.4081

#3. pengujian residual apakah berdistribusi normal


shapiro.test(model2$residuals)

##
## Shapiro-Wilk normality test
##
## data: model2$residuals
## W = 0.94289, p-value = 6.742e-05

#Alternative model ketiga ARIMA (0,0,0)(1,1,0), periode=12


sf.test(model2$residuals)

##
## Shapiro-Francia normality test
##
## data: model2$residuals
## W = 0.93686, p-value = 7.267e-05

model3<- arima(Curah, order=c(0,1,1), seasonal = list(order=c(1,1,0),


period=12), method="ML")
model3

##
## Call:
## arima(x = Curah, order = c(0, 1, 1), seasonal = list(order = c(1, 1, 0),
period = 12),
## method = "ML")
##
## Coefficients:
## ma1 sar1
## -0.6556 -0.5103
## s.e. 0.1118 0.0842
##
## sigma^2 estimated as 49712: log likelihood = -732.47, aic = 1470.94

#Diagnostic Checking
#1. uji kesignifikanan parameter: uji t
coeftest(model3)

##
## z test of coefficients:
##
## Estimate Std. Error z value Pr(>|z|)
## ma1 -0.655634 0.111796 -5.8646 4.503e-09 ***
## sar1 -0.510308 0.084187 -6.0616 1.348e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

#2. pengujian residual apakah white noise


Box.test(model3$residuals, type="Ljung")

##
## Box-Ljung test
##
## data: model3$residuals
## X-squared = 0.9495, df = 1, p-value = 0.3298

#3. pengujian residual apakah berdistribusi normal


shapiro.test(model3$residuals)

##
## Shapiro-Wilk normality test
##
## data: model3$residuals
## W = 0.94808, p-value = 0.0001568

#forecasting untuk 12 tahap ke depan berdasarkan model terbaik


forecasting <- forecast(Curah, model=model1, h=12)
forecasting

## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 121 552.728977 309.20822 796.2497 180.29612 925.1618
## 122 579.808967 326.90392 832.7140 193.02408 966.5939
## 123 301.369058 39.41569 563.3224 -99.25404 701.9922
## 124 196.549068 -74.15034 467.2485 -217.44995 610.5481
## 125 56.149106 -223.02248 335.3207 -370.80699 483.1052
## 126 19.449131 -267.94499 306.8432 -420.08224 458.9805
## 127 -4.580847 -299.96870 290.8070 -456.33758 447.1759
## 128 -59.470805 -362.64169 243.7001 -523.13066 404.1891
## 129 -41.230778 -351.98983 269.5283 -516.49574 434.0342
## 130 107.889246 -210.27705 426.0555 -378.70412 594.4826
## 131 239.489268 -85.91571 564.8942 -258.17470 737.1532
## 132 673.489193 341.00310 1005.9753 164.99559 1181.9828
plot(forecasting, main= "plot hasil peramalan")

Kita mendapatkan bahwa model dugaan terbaik dan memenuhi seluruh asusi terdapat pad
model 1 yaitu ARIMA(0,1,1)(0,1,1) musiman 12 dengan nilai aic 1450.08

Nilai akhir yang saya inginkan:


A ( karena saya tidak pernah alpa di kelas ADW)

You might also like