Library
library(seastests)
## Warning: package 'seastests' was built under R version 4.3.3
library(readr)
## Warning: package 'readr' was built under R version 4.3.3
library(forecast)
## Warning: package 'forecast' was built under R version 4.3.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(tseries)
## Warning: package 'tseries' was built under R version 4.3.3
Load dataset
data <- read.csv("C:\\Users\\ahyan\\Downloads\\datadw\\data.csv")
Seasonality Test
data$ts <- as.POSIXct(data$ts, format="%Y-%m-%dT%H:%M:%SZ", tz="UTC")
rate_ts <- ts(data$rate, frequency = 144)
is_seasonal <- isSeasonal(rate_ts)
print(is_seasonal)
## [1] TRUE
Modelling
data <- read.csv("C:\\Users\\ahyan\\Downloads\\datadw\\data.csv", stringsAsFactors = FALSE)
data$ts <- as.POSIXct(data$ts, format = "%Y-%m-%dT%H:%M:%SZ")
ts_data <- ts(data$rate, frequency = 144)
plot(ts_data, main = "Time Series Plot", ylab = "Rate", xlab = "Time", col = "blue", type = "l")

model <- auto.arima(ts_data)
summary(model)
## Series: ts_data
## ARIMA(1,0,2)(0,1,0)[144]
##
## Coefficients:
## ar1 ma1 ma2
## 0.9651 -0.4502 -0.1331
## s.e. 0.0053 0.0177 0.0175
##
## sigma^2 = 152: log likelihood = -13910.07
## AIC=27828.14 AICc=27828.16 BIC=27852.83
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1043893 12.07859 8.950397 -0.5056938 7.48755 0.5472135
## ACF1
## Training set -0.001208881
forecasted_values <- forecast(model, h = 10)
plot(forecasted_values)

Residual Model
residuals <- model$residuals
Uji asumsi white noise (Box-Ljung Test)
ljung_box_result <- Box.test(residuals, lag = 10, type = "Ljung-Box")
print("Hasil Box-Ljung Test untuk residual:")
## [1] "Hasil Box-Ljung Test untuk residual:"
print(ljung_box_result)
##
## Box-Ljung test
##
## data: residuals
## X-squared = 8.4247, df = 10, p-value = 0.5874
Uji normalitas residual (Shapiro-Wilk Test)
shapiro_test_result <- shapiro.test(residuals)
print("Hasil Shapiro-Wilk Test untuk normalitas residual:")
## [1] "Hasil Shapiro-Wilk Test untuk normalitas residual:"
print(shapiro_test_result)
##
## Shapiro-Wilk normality test
##
## data: residuals
## W = 0.98697, p-value < 2.2e-16
Visualisasi histogram dan QQ plot untuk cek normalitas
par(mfrow=c(1,2))
hist(residuals, main = "Histogram of Residuals", xlab = "Residuals", col = "lightblue")
qqnorm(residuals)
qqline(residuals, col = "red")

Perbandingan Model
sarima_model <- arima(data$ts,order = c(1, 0, 1),seasonal = list(order = c(0, 1, 1), period = 144))
summary(sarima_model)
##
## Call:
## arima(x = data$ts, order = c(1, 0, 1), seasonal = list(order = c(0, 1, 1), period = 144))
##
## Coefficients:
## ar1 ma1 sma1
## 0.9314 0.9983 0.0860
## s.e. 0.0008 0.0016 0.0071
##
## sigma^2 estimated as 11197152: log likelihood = -33747.67, aic = 67503.33
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 64259.86 312419.9 64386.24 0.004065593 0.004073589 107.3104
## ACF1
## Training set 0.9924547
forecast_values <- forecast(sarima_model, h = 114) # Forecast next 144 periods
print(forecast_values)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 3684 1582697071 1582692782 1582701359 1582690512 1582703629
## 3685 1582692404 1582683083 1582701724 1582678149 1582706658
## 3686 1582688098 1582676003 1582700193 1582669600 1582706596
## 3687 1582684128 1582670063 1582698194 1582662617 1582705640
## 3688 1582680472 1582664897 1582696046 1582656653 1582704291
## 3689 1582677107 1582660333 1582693881 1582651454 1582702761
## 3690 1582674015 1582656266 1582691764 1582646870 1582701160
## 3691 1582671175 1582652621 1582689729 1582642800 1582699550
## 3692 1582668571 1582649347 1582687796 1582639170 1582697972
## 3693 1582666187 1582646399 1582685975 1582635924 1582696450
## 3694 1582664007 1582643743 1582684272 1582633016 1582694999
## 3695 1582662018 1582641350 1582682687 1582630409 1582693628
## 3696 1582660207 1582639194 1582681220 1582628070 1582692343
## 3697 1582658561 1582637253 1582679868 1582625974 1582691147
## 3698 1582657068 1582635509 1582678628 1582624096 1582690041
## 3699 1582655720 1582633944 1582677495 1582622417 1582689023
## 3700 1582654504 1582632543 1582676466 1582620917 1582688092
## 3701 1582653414 1582631292 1582675535 1582619581 1582687246
## 3702 1582652439 1582630179 1582674698 1582618395 1582686482
## 3703 1582651572 1582629193 1582673951 1582617347 1582685797
## 3704 1582650805 1582628324 1582673287 1582616423 1582685188
## 3705 1582650133 1582627563 1582672703 1582615615 1582684651
## 3706 1582649547 1582626900 1582672194 1582614912 1582684183
## 3707 1582649043 1582626330 1582671757 1582614306 1582683780
## 3708 1582648615 1582625844 1582671385 1582613790 1582683440
## 3709 1582648257 1582625436 1582671077 1582613356 1582683158
## 3710 1582647964 1582625101 1582670828 1582612998 1582682931
## 3711 1582647733 1582624833 1582670634 1582612710 1582682757
## 3712 1582647559 1582624626 1582670492 1582612486 1582682632
## 3713 1582647438 1582624477 1582670399 1582612322 1582682554
## 3714 1582647366 1582624381 1582670352 1582612214 1582682519
## 3715 1582647341 1582624335 1582670347 1582612156 1582682526
## 3716 1582647358 1582624334 1582670383 1582612145 1582682571
## 3717 1582647415 1582624375 1582670456 1582612178 1582682652
## 3718 1582647510 1582624456 1582670564 1582612252 1582682768
## 3719 1582647639 1582624573 1582670705 1582612363 1582682915
## 3720 1582647800 1582624724 1582670876 1582612508 1582683092
## 3721 1582647992 1582624907 1582671077 1582612686 1582683297
## 3722 1582648211 1582625118 1582671304 1582612894 1582683528
## 3723 1582648457 1582625357 1582671556 1582613129 1582683784
## 3724 1582648727 1582625621 1582671832 1582613390 1582684063
## 3725 1582649019 1582625909 1582672129 1582613675 1582684363
## 3726 1582649333 1582626218 1582672447 1582613982 1582684683
## 3727 1582649666 1582626547 1582672784 1582614309 1582685022
## 3728 1582650017 1582626895 1582673139 1582614656 1582685379
## 3729 1582650386 1582627261 1582673510 1582615020 1582685752
## 3730 1582650770 1582627643 1582673897 1582615400 1582686140
## 3731 1582651169 1582628040 1582674299 1582615796 1582686543
## 3732 1582651582 1582628451 1582674713 1582616206 1582686958
## 3733 1582652008 1582628875 1582675141 1582616630 1582687387
## 3734 1582652446 1582629312 1582675580 1582617065 1582687826
## 3735 1582652895 1582629759 1582676030 1582617512 1582688277
## 3736 1582653354 1582630217 1582676490 1582617970 1582688738
## 3737 1582653823 1582630685 1582676960 1582618437 1582689208
## 3738 1582654300 1582631162 1582677439 1582618914 1582689687
## 3739 1582654787 1582631648 1582677926 1582619399 1582690174
## 3740 1582655281 1582632141 1582678420 1582619892 1582690669
## 3741 1582655782 1582632642 1582678922 1582620392 1582691171
## 3742 1582656290 1582633150 1582679430 1582620900 1582691680
## 3743 1582656804 1582633664 1582679945 1582621414 1582692195
## 3744 1582657325 1582634183 1582680466 1582621933 1582692716
## 3745 1582657850 1582634709 1582680992 1582622458 1582693242
## 3746 1582658381 1582635239 1582681523 1582622989 1582693773
## 3747 1582658917 1582635775 1582682058 1582623524 1582694309
## 3748 1582659457 1582636314 1582682599 1582624064 1582694849
## 3749 1582660001 1582636858 1582683143 1582624608 1582695394
## 3750 1582660548 1582637406 1582683691 1582625155 1582695942
## 3751 1582661100 1582637957 1582684243 1582625706 1582696493
## 3752 1582661655 1582638512 1582684797 1582626261 1582697048
## 3753 1582662213 1582639070 1582685355 1582626819 1582697606
## 3754 1582662773 1582639631 1582685916 1582627380 1582698167
## 3755 1582663337 1582640194 1582686480 1582627943 1582698731
## 3756 1582663903 1582640760 1582687046 1582628509 1582699297
## 3757 1582664471 1582641328 1582687614 1582629077 1582699865
## 3758 1582665042 1582641899 1582688185 1582629647 1582700436
## 3759 1582665614 1582642471 1582688757 1582630220 1582701009
## 3760 1582666189 1582643045 1582689332 1582630794 1582701583
## 3761 1582666765 1582643622 1582689908 1582631370 1582702159
## 3762 1582667342 1582644199 1582690486 1582631948 1582702737
## 3763 1582667922 1582644779 1582691065 1582632527 1582703316
## 3764 1582668503 1582645359 1582691646 1582633108 1582703897
## 3765 1582669085 1582645941 1582692228 1582633690 1582704479
## 3766 1582669668 1582646525 1582692811 1582634273 1582705062
## 3767 1582670252 1582647109 1582693396 1582634858 1582705647
## 3768 1582670838 1582647694 1582693981 1582635443 1582706232
## 3769 1582671424 1582648281 1582694568 1582636030 1582706819
## 3770 1582672012 1582648868 1582695155 1582636617 1582707406
## 3771 1582672600 1582649457 1582695743 1582637205 1582707995
## 3772 1582673189 1582650046 1582696332 1582637794 1582708584
## 3773 1582673779 1582650635 1582696922 1582638384 1582709174
## 3774 1582674369 1582651226 1582697513 1582638975 1582709764
## 3775 1582674961 1582651817 1582698104 1582639566 1582710355
## 3776 1582675552 1582652409 1582698696 1582640158 1582710947
## 3777 1582676145 1582653001 1582699288 1582640750 1582711539
## 3778 1582676738 1582653594 1582699881 1582641343 1582712132
## 3779 1582677331 1582654188 1582700474 1582641936 1582712726
## 3780 1582677925 1582654781 1582701068 1582642530 1582713319
## 3781 1582678519 1582655376 1582701662 1582643124 1582713914
## 3782 1582679114 1582655970 1582702257 1582643719 1582714508
## 3783 1582679709 1582656565 1582702852 1582644314 1582715103
## 3784 1582680304 1582657161 1582703447 1582644909 1582715699
## 3785 1582680900 1582657756 1582704043 1582645505 1582716294
## 3786 1582681496 1582658352 1582704639 1582646101 1582716890
## 3787 1582682092 1582658948 1582705235 1582646697 1582717486
## 3788 1582682688 1582659545 1582705832 1582647293 1582718083
## 3789 1582683285 1582660142 1582706428 1582647890 1582718680
## 3790 1582683882 1582660739 1582707025 1582648487 1582719277
## 3791 1582684479 1582661336 1582707622 1582649084 1582719874
## 3792 1582685076 1582661933 1582708220 1582649682 1582720471
## 3793 1582685674 1582662531 1582708817 1582650279 1582721069
## 3794 1582686272 1582663128 1582709415 1582650877 1582721666
## 3795 1582686870 1582663726 1582710013 1582651475 1582722264
## 3796 1582687468 1582664324 1582710611 1582652073 1582722862
## 3797 1582688066 1582664922 1582711209 1582652671 1582723460
sarima_model_new <- arima(data$ts,order = c(1, 0, 2),seasonal = list(order = c(0, 1, 0), period = 144))
summary(sarima_model_new)
##
## Call:
## arima(x = data$ts, order = c(1, 0, 2), seasonal = list(order = c(0, 1, 0), period = 144))
##
## Coefficients:
## ar1 ma1 ma2
## 0.8882 1.9931 0.9964
## s.e. 0.0011 0.0053 0.0033
##
## sigma^2 estimated as 9426951: log likelihood = -33448.01, aic = 66904.02
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 64063.01 312352 64139.37 0.004053151 0.004057982 106.8989
## ACF1
## Training set 0.9925044
forecast_values <- forecast(sarima_model_new, h = 144) # Forecast next 144 periods
print(forecast_values)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 3684 1582697378 1582693443 1582701313 1582691360 1582703396
## 3685 1582690999 1582678998 1582702999 1582672645 1582709352
## 3686 1582682986 1582664555 1582701418 1582654797 1582711175
## 3687 1582675937 1582653709 1582698166 1582641942 1582709933
## 3688 1582669744 1582644927 1582694561 1582631789 1582707698
## 3689 1582664310 1582637628 1582690993 1582623503 1582705117
## 3690 1582659552 1582631485 1582687618 1582616628 1582702475
## 3691 1582655392 1582626281 1582684504 1582610870 1582699915
## 3692 1582651765 1582621855 1582681676 1582606021 1582697509
## 3693 1582648611 1582618085 1582679137 1582601926 1582695296
## 3694 1582645877 1582614874 1582676879 1582598462 1582693291
## 3695 1582643515 1582612142 1582674889 1582595533 1582691497
## 3696 1582641485 1582609822 1582673148 1582593060 1582689910
## 3697 1582639749 1582607859 1582671639 1582590978 1582688520
## 3698 1582638274 1582606207 1582670342 1582589232 1582687317
## 3699 1582637032 1582604825 1582669238 1582587776 1582686288
## 3700 1582635995 1582603679 1582668311 1582586572 1582685419
## 3701 1582635142 1582602739 1582667544 1582585586 1582684697
## 3702 1582634451 1582601981 1582666921 1582584792 1582684110
## 3703 1582633904 1582601381 1582666428 1582584164 1582683645
## 3704 1582633486 1582600920 1582666051 1582583681 1582683291
## 3705 1582633181 1582600583 1582665780 1582583326 1582683037
## 3706 1582632978 1582600353 1582665603 1582583083 1582682874
## 3707 1582632865 1582600219 1582665510 1582582938 1582682792
## 3708 1582632831 1582600170 1582665493 1582582880 1582682783
## 3709 1582632868 1582600194 1582665543 1582582897 1582682840
## 3710 1582632969 1582600284 1582665653 1582582982 1582682955
## 3711 1582633125 1582600432 1582665817 1582583126 1582683124
## 3712 1582633331 1582600632 1582666029 1582583322 1582683339
## 3713 1582633580 1582600877 1582666284 1582583564 1582683596
## 3714 1582633869 1582601162 1582666577 1582583848 1582683891
## 3715 1582634193 1582601483 1582666904 1582584167 1582684220
## 3716 1582634548 1582601835 1582667261 1582584518 1582684578
## 3717 1582634930 1582602215 1582667645 1582584897 1582684963
## 3718 1582635337 1582602620 1582668053 1582585301 1582685372
## 3719 1582635765 1582603047 1582668482 1582585727 1582685802
## 3720 1582636212 1582603493 1582668931 1582586173 1582686251
## 3721 1582636676 1582603957 1582669396 1582586637 1582686716
## 3722 1582637156 1582604436 1582669876 1582587115 1582687197
## 3723 1582637649 1582604929 1582670370 1582587608 1582687691
## 3724 1582638154 1582605433 1582670875 1582588112 1582688196
## 3725 1582638670 1582605949 1582671391 1582588627 1582688712
## 3726 1582639195 1582606474 1582671916 1582589152 1582689238
## 3727 1582639728 1582607007 1582672450 1582589685 1582689771
## 3728 1582640269 1582607548 1582672991 1582590226 1582690313
## 3729 1582640817 1582608095 1582673538 1582590773 1582690860
## 3730 1582641370 1582608648 1582674092 1582591326 1582691414
## 3731 1582641929 1582609207 1582674651 1582591885 1582691973
## 3732 1582642492 1582609770 1582675214 1582592448 1582692536
## 3733 1582643059 1582610337 1582675781 1582593015 1582693103
## 3734 1582643630 1582610908 1582676352 1582593586 1582693674
## 3735 1582644205 1582611483 1582676927 1582594161 1582694249
## 3736 1582644782 1582612060 1582677504 1582594738 1582694826
## 3737 1582645361 1582612639 1582678083 1582595317 1582695405
## 3738 1582645943 1582613221 1582678665 1582595899 1582695987
## 3739 1582646527 1582613805 1582679249 1582596483 1582696571
## 3740 1582647113 1582614391 1582679835 1582597069 1582697157
## 3741 1582647700 1582614978 1582680422 1582597656 1582697745
## 3742 1582648289 1582615567 1582681011 1582598245 1582698333
## 3743 1582648879 1582616157 1582681601 1582598835 1582698923
## 3744 1582649470 1582616748 1582682192 1582599426 1582699514
## 3745 1582650062 1582617340 1582682785 1582600018 1582700107
## 3746 1582650655 1582617933 1582683378 1582600611 1582700700
## 3747 1582651249 1582618527 1582683971 1582601205 1582701293
## 3748 1582651844 1582619122 1582684566 1582601800 1582701888
## 3749 1582652439 1582619717 1582685161 1582602395 1582702483
## 3750 1582653035 1582620312 1582685757 1582602990 1582703079
## 3751 1582653631 1582620909 1582686353 1582603587 1582703675
## 3752 1582654227 1582621505 1582686949 1582604183 1582704271
## 3753 1582654824 1582622102 1582687546 1582604780 1582704868
## 3754 1582655421 1582622699 1582688144 1582605377 1582705466
## 3755 1582656019 1582623297 1582688741 1582605975 1582706063
## 3756 1582656617 1582623895 1582689339 1582606573 1582706661
## 3757 1582657215 1582624493 1582689937 1582607171 1582707259
## 3758 1582657813 1582625091 1582690535 1582607769 1582707858
## 3759 1582658412 1582625690 1582691134 1582608368 1582708456
## 3760 1582659011 1582626288 1582691733 1582608966 1582709055
## 3761 1582659609 1582626887 1582692331 1582609565 1582709654
## 3762 1582660208 1582627486 1582692930 1582610164 1582710252
## 3763 1582660807 1582628085 1582693530 1582610763 1582710852
## 3764 1582661407 1582628684 1582694129 1582611362 1582711451
## 3765 1582662006 1582629284 1582694728 1582611962 1582712050
## 3766 1582662605 1582629883 1582695327 1582612561 1582712649
## 3767 1582663205 1582630482 1582695927 1582613160 1582713249
## 3768 1582663804 1582631082 1582696526 1582613760 1582713848
## 3769 1582664404 1582631682 1582697126 1582614359 1582714448
## 3770 1582665003 1582632281 1582697725 1582614959 1582715047
## 3771 1582665603 1582632881 1582698325 1582615559 1582715647
## 3772 1582666203 1582633480 1582698925 1582616158 1582716247
## 3773 1582666802 1582634080 1582699524 1582616758 1582716846
## 3774 1582667402 1582634680 1582700124 1582617358 1582717446
## 3775 1582668002 1582635280 1582700724 1582617958 1582718046
## 3776 1582668602 1582635879 1582701324 1582618557 1582718646
## 3777 1582669201 1582636479 1582701924 1582619157 1582719246
## 3778 1582669801 1582637079 1582702523 1582619757 1582719845
## 3779 1582670401 1582637679 1582703123 1582620357 1582720445
## 3780 1582671001 1582638279 1582703723 1582620957 1582721045
## 3781 1582671601 1582638879 1582704323 1582621557 1582721645
## 3782 1582672201 1582639479 1582704923 1582622157 1582722245
## 3783 1582672801 1582640079 1582705523 1582622757 1582722845
## 3784 1582673401 1582640678 1582706123 1582623356 1582723445
## 3785 1582674001 1582641278 1582706723 1582623956 1582724045
## 3786 1582674600 1582641878 1582707323 1582624556 1582724645
## 3787 1582675200 1582642478 1582707923 1582625156 1582725245
## 3788 1582675800 1582643078 1582708522 1582625756 1582725845
## 3789 1582676400 1582643678 1582709122 1582626356 1582726444
## 3790 1582677000 1582644278 1582709722 1582626956 1582727044
## 3791 1582677600 1582644878 1582710322 1582627556 1582727644
## 3792 1582678200 1582645478 1582710922 1582628156 1582728244
## 3793 1582678800 1582646078 1582711522 1582628756 1582728844
## 3794 1582679400 1582646678 1582712122 1582629356 1582729444
## 3795 1582680000 1582647278 1582712722 1582629956 1582730044
## 3796 1582680600 1582647878 1582713322 1582630556 1582730644
## 3797 1582681200 1582648478 1582713922 1582631156 1582731244
## 3798 1582681800 1582649078 1582714522 1582631756 1582731844
## 3799 1582682400 1582649678 1582715122 1582632356 1582732444
## 3800 1582683000 1582650278 1582715722 1582632956 1582733044
## 3801 1582683600 1582650878 1582716322 1582633556 1582733644
## 3802 1582684200 1582651478 1582716922 1582634156 1582734244
## 3803 1582684800 1582652078 1582717522 1582634756 1582734844
## 3804 1582685400 1582652678 1582718122 1582635356 1582735444
## 3805 1582686000 1582653278 1582718722 1582635956 1582736044
## 3806 1582686600 1582653878 1582719322 1582636556 1582736644
## 3807 1582687200 1582654478 1582719922 1582637156 1582737244
## 3808 1582687800 1582655078 1582720522 1582637756 1582737844
## 3809 1582688400 1582655678 1582721122 1582638356 1582738444
## 3810 1582689000 1582656278 1582721722 1582638956 1582739044
## 3811 1582689600 1582656878 1582722322 1582639556 1582739644
## 3812 1582690200 1582657478 1582722922 1582640156 1582740244
## 3813 1582690800 1582658078 1582723522 1582640756 1582740844
## 3814 1582691400 1582658678 1582724122 1582641356 1582741444
## 3815 1582692000 1582659278 1582724722 1582641956 1582742044
## 3816 1582692600 1582659878 1582725322 1582642556 1582742644
## 3817 1582693200 1582660478 1582725922 1582643156 1582743244
## 3818 1582693800 1582661078 1582726522 1582643756 1582743844
## 3819 1582694400 1582661678 1582727122 1582644356 1582744444
## 3820 1582695000 1582662278 1582727722 1582644956 1582745044
## 3821 1582695600 1582662878 1582728322 1582645556 1582745644
## 3822 1582696200 1582663478 1582728922 1582646156 1582746244
## 3823 1582696800 1582664078 1582729522 1582646756 1582746844
## 3824 1582697400 1582664678 1582730122 1582647356 1582747444
## 3825 1582698000 1582665278 1582730722 1582647956 1582748044
## 3826 1582698600 1582665878 1582731322 1582648556 1582748644
## 3827 1582699200 1582666478 1582731922 1582649156 1582749244