Misalkan kita adalah seorang statistikawan yang diminta oleh sebuah perusahaan PDAM Kota X untuk membantu menganalisis dan meramalkan permintaan air bersih harian selama 1 tahun (365 hari). Dengan data sebagai berikut :

Load Data

library(readxl)
setwd("~/Mine/Youtube/Series Time Series/ARIMA (Stasioner Rata-Rata dan Variansi)")
data <- read_excel("Data Permintaan Air.xlsx")
head(data)
## # A tibble: 6 × 2
##    Hari Permintaan_Air
##   <dbl>          <dbl>
## 1     1           92  
## 2     2           91.4
## 3     3           98.0
## 4     4           88.8
## 5     5           82.7
## 6     6           84.6

Eksploarasi Awal

# Ambil Variabel Permintaan Air
air <- data$Permintaan_Air
air <- ts(air, frequency = 365)

# Plot Time Series
ts.plot(air)

Setelah eksplorasi awal menunjukkan data fluktuasi acak, tidak ada tren kuat, dan tidak ada pola musiman signifikan. Sehingga pendekatan yang digunakan adalah model ARIMA (AutoRegressive Integrated Moving Average)

Uji Stasioner

Stasioneritas ini terbagi 2 yakni:

1. Uji Stasioner dalam Rata Rata dengan ADF Test

Uji ini digunakan untuk mengecek apakah data sudah stasioner atau belum.

library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
adf.test(air)
## Warning in adf.test(air): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  air
## Dickey-Fuller = -6.075, Lag order = 7, p-value = 0.01
## alternative hypothesis: stationary

Berdasarkan output diatas diperoleh p-value < 0.05 yakni 0.01 sehingga tolak H0 yang berarti data telah stasioner dalam rata rata.

2. Uji Stasioner dalam Variansi

library(forecast)
BoxCox.lambda(air)
## [1] 1

Berdasarkan output diatas diperoleh λ ≈ 1 sehingga tidak perlu transpormasi hal ini sesuai dengan interpretassi lambda sebagai berikut :

λ ≈ 1 → tidak perlu transformasi λ ≈ 0 → log transform λ < 1 → transformasi diperlukan

Identifikasi Model

acf(air, lag.max = 70)

pacf(air, lag.max = 70)

Berdasarkan output diatas diperoleh plot ACF turun secara perlahan sehingga MA(0), dan plot PACF terpotong setelah lag 1 maka AR(1) dan tidak ada diferencing maka diperoleh I(0), maka model yang diperoleh ada ARIMA(1,0,0) sebagai berikut:

\[ Y_t = \mu + \phi Y_{t-1} + \varepsilon_t \]

Estimasi Model ARIMA

model <- arima(air, order = c(1,0,0))
model
## 
## Call:
## arima(x = air, order = c(1, 0, 0))
## 
## Coefficients:
##          ar1  intercept
##       0.6741   100.6151
## s.e.  0.0386     0.8230
## 
## sigma^2 estimated as 26.55:  log likelihood = -1116.66,  aic = 2239.32

Berdasarkan output diatas diperoleh model sebagai berikut:

\[ Y_t = 100.6151 + 0.6741 Y_{t-1} + \varepsilon_t \]

Diagnostik Residual

1. Ljung Box

Apakah residual tidak berkorelasi (white noise), model yang baik adalah model yang memiliki residual yang tidak berkorelasi.

Box.test(residuals(model), lag = 20, type = "Ljung-Box")
## 
##  Box-Ljung test
## 
## data:  residuals(model)
## X-squared = 6.507, df = 20, p-value = 0.998

Berdasarkan output diatas diperoleh p-value > 0.05 maka gagal tolak H0 sehingga residual tidak berkorelasi (white noise)

2. Normalitas

library(nortest)

shapiro.test(residuals(model))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(model)
## W = 0.99302, p-value = 0.08785

Berdasarkan output diatas diperoleh p-value > 0.05 maka gagal tolak H0 sehingga residual berdistribusi normal

Kesimpulan Diagnostik

  • Uji Ljung-Box (Lolos)

  • Uji Normalitas (Lolos)

Forecasting 30 Hari Kedepan

forecast_30 <- forecast(model, h = 30)

# Tampilkan hasil
forecast_30
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 2.000000       99.18929 92.58548 105.7931 89.08963 109.2890
## 2.002740       99.65395 91.68981 107.6181 87.47384 111.8341
## 2.005479       99.96718 91.45643 108.4779 86.95111 112.9832
## 2.008219      100.17832 91.43047 108.9262 86.79963 113.5570
## 2.010959      100.32066 91.46716 109.1742 86.78039 113.8609
## 2.013699      100.41661 91.51551 109.3177 86.80355 114.0297
## 2.016438      100.48129 91.55865 109.4039 86.83529 114.1273
## 2.019178      100.52489 91.59247 109.4573 86.86394 114.1858
## 2.021918      100.55428 91.61743 109.4911 86.88655 114.2220
## 2.024658      100.57409 91.63523 109.5130 86.90328 114.2449
## 2.027397      100.58745 91.64767 109.5272 86.91523 114.2597
## 2.030137      100.59645 91.65625 109.5366 86.92360 114.2693
## 2.032877      100.60252 91.66213 109.5429 86.92938 114.2757
## 2.035616      100.60661 91.66614 109.5471 86.93334 114.2799
## 2.038356      100.60937 91.66886 109.5499 86.93604 114.2827
## 2.041096      100.61123 91.67070 109.5518 86.93787 114.2846
## 2.043836      100.61248 91.67194 109.5530 86.93911 114.2859
## 2.046575      100.61333 91.67279 109.5539 86.93995 114.2867
## 2.049315      100.61390 91.67335 109.5544 86.94052 114.2873
## 2.052055      100.61428 91.67374 109.5548 86.94090 114.2877
## 2.054795      100.61454 91.67399 109.5551 86.94116 114.2879
## 2.057534      100.61471 91.67417 109.5553 86.94133 114.2881
## 2.060274      100.61483 91.67429 109.5554 86.94145 114.2882
## 2.063014      100.61491 91.67437 109.5555 86.94153 114.2883
## 2.065753      100.61496 91.67442 109.5555 86.94158 114.2883
## 2.068493      100.61500 91.67446 109.5555 86.94162 114.2884
## 2.071233      100.61502 91.67448 109.5556 86.94164 114.2884
## 2.073973      100.61504 91.67450 109.5556 86.94166 114.2884
## 2.076712      100.61505 91.67451 109.5556 86.94167 114.2884
## 2.079452      100.61506 91.67451 109.5556 86.94168 114.2884
plot(forecast_30,
     main="Forecast Permintaan Air 30 Hari ke Depan",
     xlab="Waktu",
     ylab="Permintaan Air")

Daftar Pustaka

George E. P. Box, Gwilym M. Jenkins, Gregory C. Reinsel, & Greta M. Ljung. (2015). Time Series Analysis: Forecasting and Control (5th ed.). Wiley.

Rob J. Hyndman, & George Athanasopoulos. (2021). Forecasting: Principles and Practice (3rd ed.). OTexts. Tersedia online: https://otexts.com/fpp3/

William W. S. Wei. (2006). Time Series Analysis: Univariate and Multivariate Methods (2nd ed.). Pearson.

James D. Hamilton. (1994). Time Series Analysis. Princeton University Press.

George Box, & David Cox. (1964). An Analysis of Transformations. Journal of the Royal Statistical Society: Series B, 26(2), 211–252.

David A. Dickey, & Wayne A. Fuller. (1979). Distribution of the Estimators for Autoregressive Time Series with a Unit Root. Journal of the American Statistical Association, 74(366), 427–431.