# Packages
#install.packages(c("forecast", "tseries", "ggplot2", "TSA"))
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(tseries)
## Warning: package 'tseries' was built under R version 4.3.3
library(ggplot2)
library(TSA)
## Warning: package 'TSA' was built under R version 4.3.3
## 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
\[ Y_t = \left(1 + \theta_1 B + \theta_2 B^2 + \theta_3 B^3 + \theta_4 B^4\right) \left(1 + \Theta_1 B^{12} + \Theta_2 B^{24} + \Theta_3 B^{36} + \Theta_4 B^{48}\right) \varepsilon_t \]
cat("Timeseries Dataset Generating Simulately")
## Timeseries Dataset Generating Simulately
# Simulating Dataset with SARIMA(0,0,4)(0,0,4)^[12] models
set.seed(258)
model <- Arima(ts(rnorm(1200), frequency=12), order = c(0,0,4), seasonal = list(order = c(0,0,4), period = 12))
sim_data <- simulate(model, nsim = 1200)
sim_data
## Jan Feb Mar Apr May
## 101 0.771562315 -0.462772723 0.241829100 -0.400908990 0.475397395
## 102 0.612083542 -0.477170037 -0.761621709 0.277801853 1.640914518
## 103 -1.219536508 0.896536407 0.079604621 -0.310731524 -0.118424944
## 104 1.354473123 -0.229056111 0.709629935 0.601214780 -0.393988234
## 105 1.126594576 0.425566185 -0.937610680 1.064672459 -0.383145606
## 106 0.864659771 -0.900034385 0.388829658 -0.852517347 0.235365862
## 107 1.496058670 -0.252899098 -1.885121446 -0.863241402 0.711620413
## 108 -1.121823399 -1.146601401 -1.871221478 0.044489709 0.156816312
## 109 -0.523031277 -0.084169902 0.107376506 -0.491937054 -0.418758555
## 110 0.602255852 0.339925319 1.324677303 0.757940478 -0.031764930
## 111 1.229373942 -2.527403112 1.031496550 -0.754924313 0.987342095
## 112 -0.375651815 0.432536047 0.331142655 1.235131343 -0.250312033
## 113 -1.077452365 -0.109376275 -0.611704198 -0.504199346 0.672237746
## 114 -0.254389024 0.144772735 -0.312156704 -0.102649259 -1.410208830
## 115 1.197747847 -1.853868456 -0.816543838 0.253944647 -0.474718983
## 116 0.081653599 -0.450856349 1.031779263 -0.292474002 -0.036872053
## 117 -1.059830698 -1.806434636 0.413797645 0.894540215 1.015938657
## 118 -1.134867774 -0.047300648 -0.131947500 -0.348170993 -0.468565860
## 119 -1.560899701 1.447492340 0.643698629 0.291811774 -0.311806417
## 120 -1.118977494 0.228654403 0.217824787 0.262483162 0.951891243
## 121 -2.360683564 0.583501751 0.164513396 -0.523124853 -0.925721258
## 122 0.040217983 0.400349234 -1.776108772 0.648448292 0.534345412
## 123 0.887677034 -0.822412977 -0.264709359 -1.429097681 0.069713128
## 124 0.297846322 0.012227014 0.845216102 -0.032607980 0.470895265
## 125 0.380053990 -0.689586192 -0.930609977 0.256888261 0.829598864
## 126 0.604803789 -0.916189655 1.336203119 -1.719405092 0.895135950
## 127 -0.731459362 -1.097222940 1.007354904 -0.186029750 0.169323207
## 128 -0.574006319 -0.489942247 0.096376277 0.310302877 0.004637524
## 129 -1.346796239 1.157995938 -1.100054973 1.183600946 -1.109391445
## 130 -0.421666297 0.397912321 0.181979538 0.289302058 1.084307968
## 131 1.620880261 -0.246780467 0.983861775 -1.405379918 1.219486563
## 132 -0.384609137 0.576249204 -0.209620701 0.512751000 0.590988190
## 133 -0.354717764 -0.600358697 -0.740596536 0.676806173 -0.194074959
## 134 0.543750720 -0.237889337 -1.487455953 -0.373108610 0.594568512
## 135 -0.656883350 -0.051668170 -0.922990861 -1.214177937 -0.632304997
## 136 1.672318554 -0.043717115 -0.564139195 0.501205372 0.622271634
## 137 -1.020565555 -0.120949497 0.346002830 1.119660875 1.765914750
## 138 1.155637323 0.787336284 1.385342307 -1.940394149 0.172664333
## 139 1.736446299 0.173703459 -1.335657061 -2.476418912 0.492162733
## 140 1.720936571 0.032824774 0.625054817 0.805718548 -1.696992562
## 141 -1.686413029 -0.974775143 0.943988755 0.853259539 0.130724314
## 142 -0.305839397 -1.714093557 1.679690730 -1.474957209 -0.647576929
## 143 0.363076400 -1.340956092 -1.694710818 1.575765301 1.207548563
## 144 0.303244259 1.892260920 -1.228983870 -0.943748437 0.100017704
## 145 -0.164054919 -0.568594551 0.138290768 0.587078552 -0.575869546
## 146 0.594823518 -2.303674004 2.004355201 -1.069416310 -1.040037563
## 147 -1.583068712 3.029274663 -0.649745291 -0.050205990 -0.041169938
## 148 0.331992263 1.586726109 -0.269484889 -0.684784083 0.540760760
## 149 -0.738181998 0.598120588 1.280518063 -0.560595150 -0.495476280
## 150 2.441198327 1.485502927 0.459927585 -0.644546464 1.437489247
## 151 0.470634323 0.093376694 0.025658516 -0.881038075 1.359741455
## 152 -0.051326415 1.220384649 -0.796082864 -0.893300488 -0.766298563
## 153 0.777087146 -0.472713002 0.069454289 -0.857842347 -0.247861120
## 154 0.827736379 1.660104655 0.849192853 -0.880377779 0.380001004
## 155 -0.093398189 0.927133777 0.579274708 -0.558860514 -0.853222163
## 156 2.516243018 0.372587919 0.109411848 0.180112928 -0.454697204
## 157 0.762439031 -0.700815648 -0.274972121 -1.956617491 0.418738679
## 158 -0.895870948 -1.060116507 -0.009495918 0.408786559 0.671412788
## 159 0.932243126 0.443591001 1.246952116 -1.264527221 1.115610202
## 160 -1.011992253 0.130323436 -0.634287920 -0.118485634 0.681699700
## 161 -0.286764200 0.840204097 -0.086419560 0.860023195 -0.299052959
## 162 -0.695381503 0.252330019 -1.113375358 -0.279487010 -2.225938226
## 163 0.467527618 0.026607804 0.262202171 -0.336838428 -0.635571985
## 164 0.093409726 -0.229092853 -0.762410615 0.307062650 0.440203220
## 165 0.589665508 -0.944692594 0.249619428 -0.496104423 -1.121369963
## 166 -1.395552342 -0.281083476 -0.663357353 0.385725422 0.618540554
## 167 -0.847542737 0.399353244 -0.636419654 2.319722201 0.091953336
## 168 -0.890804979 0.469850728 -0.554404476 -0.299347550 -1.473342139
## 169 0.046639722 -1.874380973 0.712008780 -0.003511828 0.015093840
## 170 -0.182445123 1.177600689 -0.255044036 1.294195192 -2.086443681
## 171 0.288459038 0.784457892 -0.875131356 -0.460456497 0.027737572
## 172 -1.325244744 0.017266072 -0.599201267 -0.860634452 -0.869527058
## 173 -0.179693667 -1.656481837 -0.802661871 -1.352315878 1.588224272
## 174 -0.416613029 0.851369446 -1.307992925 0.486169435 1.362545631
## 175 -1.317614898 1.217831300 -1.054416312 0.476448222 -1.367835239
## 176 0.190292116 0.108068999 1.914994580 -0.612324484 -0.216763623
## 177 -0.804834578 0.407279164 0.411018912 -0.289101261 0.471138184
## 178 0.611523170 1.805869493 0.153005686 0.259878894 -0.076128093
## 179 -0.583890994 -0.610104725 -0.863100868 0.043042012 0.384975560
## 180 0.795835522 -1.604430137 -1.877899311 2.367102654 -0.917520875
## 181 -1.298295139 1.000167843 1.132796418 0.291845442 0.980593120
## 182 -1.214429564 -0.425741037 0.467445138 -0.228323482 -1.281225065
## 183 -2.049739827 -0.191086333 0.341006261 0.777163500 -1.069488397
## 184 -0.579299137 0.383415702 -0.753669768 1.390183431 -0.968252531
## 185 -0.678879579 1.545129873 1.409710096 0.070779759 -0.795425267
## 186 -1.502828435 1.923359949 0.756408160 0.368888612 0.508064849
## 187 -1.281975322 -0.606266258 1.244540543 0.783046177 0.920445706
## 188 -1.253088846 0.135474047 -0.462959117 2.117112879 -0.528327181
## 189 -0.980952482 0.066456923 0.562487987 1.684618838 -0.115161221
## 190 -0.894124061 0.516890346 0.704918963 0.185876427 1.821041800
## 191 -0.600607249 -0.164460655 -0.671860632 0.645445811 -0.192760578
## 192 0.832705997 -0.443225995 0.452169526 -0.751985687 -0.245621303
## 193 -0.760623519 0.448446002 -0.178927832 0.580072718 0.535818731
## 194 -0.576295998 -0.158068903 0.861116773 -0.054611573 -0.682898013
## 195 -0.765354048 -1.595427636 -0.339901333 -1.780672182 -0.920384062
## 196 -1.274006642 -0.987044664 0.505867176 -0.811500245 -0.983508864
## 197 0.601930625 0.399153359 -0.935893469 0.025412531 -0.521328207
## 198 -0.016345419 -0.440438689 0.413029371 -0.350716865 1.649297174
## 199 0.373500343 -0.635466528 -0.089989469 0.970802983 -0.320117332
## 200 0.047923090 0.190229753 -0.565159867 -0.580028913 -1.351535966
## Jun Jul Aug Sep Oct
## 101 -0.104747253 1.075363727 0.921116942 -0.610520650 -0.323443680
## 102 0.339363114 0.676765657 -0.267981878 0.158528742 -0.257668907
## 103 -0.484652686 -1.309627006 0.013544395 -0.835022575 2.113119898
## 104 0.940653622 -1.939262802 -0.806912617 -1.050198325 -0.373192216
## 105 0.794701616 0.511788631 -0.665642905 0.928702787 1.407819605
## 106 1.414700531 -0.890036556 -0.077977143 -0.890669670 -0.613444884
## 107 -0.596719366 1.424675305 -0.211323738 -0.348367619 -1.873190084
## 108 1.059015137 0.477203958 -1.038999325 -0.825630283 0.191591558
## 109 -0.252583298 -1.480982461 -1.287226136 -0.855110450 1.296976053
## 110 0.609927119 0.109210408 -0.253713866 -0.275170295 -0.185659185
## 111 -0.960724519 2.637691971 1.302999273 0.724518217 0.770184316
## 112 0.534752451 -0.253219850 -0.233762403 -0.266500380 0.076416197
## 113 0.184334355 0.063404532 0.209363121 0.833768514 -0.523909230
## 114 -0.171274877 0.368778143 -1.727971166 0.914924509 -0.357703627
## 115 -1.845096286 0.885028472 -0.377133143 -0.101016030 1.070998881
## 116 2.509210320 0.714368619 0.066628102 -2.427844502 -0.417106749
## 117 -1.287222366 -0.584640259 -0.973361425 -0.332060121 -0.460494300
## 118 -1.132824794 1.104588897 1.267830375 -0.545508503 -1.096195030
## 119 0.261261910 0.511125121 0.616478747 0.960524817 -1.681867838
## 120 0.170077043 -0.368946173 0.950980777 -1.138106671 -0.272699231
## 121 0.161287422 -2.325980308 -0.267910485 -0.427984429 0.444073807
## 122 0.702228321 -0.464183771 0.890531936 -0.544599094 -1.054764250
## 123 -0.937244331 1.453739004 -0.846564903 -0.182681696 0.417097747
## 124 -0.141779517 -0.321382100 -0.033491204 0.708524760 0.008077054
## 125 0.310926081 -0.096435329 -1.074335598 0.233758815 -0.696268439
## 126 1.579178112 -0.032280693 -0.370299255 -1.022131060 -0.293584471
## 127 -2.193305439 0.808346132 -0.360822748 0.485065125 -0.456188952
## 128 -0.379169068 -0.411242685 -1.124425811 1.065693277 0.011297506
## 129 0.830529234 1.502850891 0.609641125 0.333599323 0.493484234
## 130 0.369226940 0.996052911 0.805100319 1.169929811 -0.475380908
## 131 0.795434386 -0.999983912 -1.366944696 -1.339926417 1.163576542
## 132 -0.380176846 -1.584218645 -0.892984389 2.555029754 0.716358801
## 133 -0.870538311 0.769454649 -0.172686544 0.479941551 0.406905045
## 134 -0.282781491 -0.817969228 0.913522467 2.360072156 1.271687578
## 135 -2.073567350 0.360811997 -0.784811272 1.924291552 -0.402596701
## 136 0.248697168 -1.045678527 1.323584365 -0.832284058 1.312098964
## 137 0.009660206 -0.090663982 -0.412794058 -0.324814933 -1.401456402
## 138 0.160102548 0.029913829 -0.721227082 0.808855798 0.208958507
## 139 0.530979776 0.399561562 -1.006408279 1.154514834 -1.428936254
## 140 -0.392418760 -0.376502261 0.835891812 -0.309538838 0.758886129
## 141 -1.353811658 0.106542982 -1.117028218 0.166376784 -0.608109606
## 142 0.644901649 -0.493944433 -0.812338632 0.586706870 -0.347209981
## 143 0.056452754 -1.139283804 -1.325647453 -0.023214741 0.567119267
## 144 0.350862821 0.013604623 -0.641697217 0.281235112 1.105023572
## 145 1.409941641 0.559507511 -0.825939266 -1.335074064 0.278599204
## 146 1.548169717 0.705118646 -0.526177126 0.651976604 -0.268013598
## 147 -0.094138864 -0.414592253 0.590059839 0.095461257 0.571099050
## 148 0.670145826 -0.796983041 -0.193144175 2.243897156 0.645358863
## 149 1.532246317 -0.340739116 1.883339862 -1.289314340 0.325085050
## 150 -0.732698308 -0.294724608 -0.676986592 0.404944618 0.834560540
## 151 0.762132182 -0.883486320 -0.081628044 -1.789614880 -0.090093914
## 152 0.264449534 -1.061488049 0.695750565 0.302473474 -1.682988040
## 153 0.484866062 -0.399538030 -1.208532787 -0.464756764 0.742071465
## 154 -1.437272388 1.831024701 0.033207934 0.489390634 0.513750909
## 155 -0.852919118 0.480895678 0.255206389 0.689366299 0.509866636
## 156 1.419549910 1.404643703 0.227508965 -2.155638583 -0.469072481
## 157 -0.864222863 0.997087568 0.540925860 -0.996112078 0.993258572
## 158 -0.248225419 0.056149104 0.763908696 0.775653683 0.008358857
## 159 -0.507021432 -0.819946073 0.740990799 0.629036429 0.477078728
## 160 -0.682843078 0.193787127 0.358570526 0.060976577 -0.619846489
## 161 2.406195660 0.180171714 0.339449576 -0.561417453 2.162753237
## 162 0.715667129 -0.495358191 -0.601225382 -0.427043046 -0.552511702
## 163 0.918840612 0.596210740 0.038845651 0.826224065 0.747705120
## 164 -0.488614177 1.108044608 0.996696627 -0.511102152 -0.485723692
## 165 0.826220067 0.104546258 0.862110948 -0.344687038 -1.739983012
## 166 2.501494904 -1.114195570 0.958541138 0.906812619 0.096619857
## 167 0.544818636 1.328343493 -0.838766119 -0.893532231 0.258279436
## 168 0.620496945 0.285710364 -0.251672500 1.567052070 0.396901032
## 169 1.614539762 -1.664579653 -0.180683732 0.946276783 0.491557605
## 170 0.558370564 -0.378317433 -1.135981489 -0.779508540 1.967779585
## 171 -0.226556708 -1.102533779 1.161807937 -0.022208986 0.441835303
## 172 -1.861410705 -0.033880038 -0.342243602 1.116345829 -0.626716251
## 173 0.322840668 1.096642316 0.227236874 0.846456800 -1.065946925
## 174 2.204287595 -0.860927136 -0.613880343 -0.909865926 0.803166474
## 175 -0.447287134 0.390654254 0.768626547 0.306729336 -0.344162042
## 176 -0.155973248 -1.029544486 0.876666277 -1.282275318 1.629192566
## 177 -0.772025841 0.085692907 -0.236339124 0.556366168 -0.906771634
## 178 0.715265292 -0.061711140 -1.212817906 -1.299379150 -0.316373020
## 179 -1.316324441 -0.731442544 1.374629060 -0.388150310 -1.109937177
## 180 -0.984029920 0.213187837 2.170339790 -0.236370380 1.253803809
## 181 -0.701027011 0.628945688 1.007428650 -1.610042093 1.563293128
## 182 0.346962188 -0.988915153 1.082802494 0.529980786 0.093444181
## 183 -0.244839754 0.270496191 -0.893747569 0.819611305 -0.177537153
## 184 0.734276018 0.414318043 -0.270059076 -0.102890882 0.636396859
## 185 0.969953142 0.055920399 -0.259264162 -0.889229869 -0.044929626
## 186 0.994285180 -0.589138787 -0.361853576 0.654549897 1.107726625
## 187 -1.479127744 0.730349952 0.052500925 -0.196528402 -0.767169628
## 188 -1.640145610 -0.115230146 1.023737453 1.360030243 0.748531796
## 189 -0.742069690 -0.112556494 -1.502956852 -0.616463047 0.887048762
## 190 1.070975255 0.777897134 0.055207003 -0.246948190 0.332232333
## 191 -2.024389905 0.674998474 -0.005336257 0.124733370 -0.868719432
## 192 -0.893540189 0.779314664 -0.826160544 0.083899890 -0.384717103
## 193 -0.008668004 0.180649053 0.213552297 -0.476685956 0.351440460
## 194 -0.500652968 1.779071458 0.619024106 -0.242499643 -0.333495040
## 195 -0.678627899 0.745377901 1.650335611 1.188821884 -3.102030247
## 196 -2.357332626 -0.513057934 -0.538631347 0.414105356 2.077908299
## 197 -0.676094098 0.844586913 -0.847054967 0.567177959 1.427929390
## 198 0.549864800 -0.118025113 -0.101289688 0.164575506 -0.262345849
## 199 -0.369476779 -0.590406674 1.905217627 -1.292119913 -0.923704237
## 200 1.132044228 0.852998966 -0.047071853 0.445788746 1.495631390
## Nov Dec
## 101 1.023051737 0.461014683
## 102 -1.126771420 -0.089679976
## 103 -0.238384217 0.086240934
## 104 -1.358427962 0.093466301
## 105 -0.839259954 0.163212582
## 106 -0.783607504 -1.006133958
## 107 -0.284717701 0.607242594
## 108 -0.631474708 0.182204264
## 109 1.661641446 -0.676712685
## 110 0.225411442 -0.806737488
## 111 -0.257254441 -0.660017940
## 112 -1.062958145 0.041916794
## 113 -1.225115720 -1.372935608
## 114 0.528552789 1.378584124
## 115 -0.334120968 -0.039062808
## 116 0.958219698 0.177428906
## 117 -1.092756772 0.019596010
## 118 0.321284476 -0.453569965
## 119 -0.242248898 -0.291559183
## 120 -0.307509431 1.235443347
## 121 0.174034820 0.059392147
## 122 0.405090756 -0.101834125
## 123 0.064798112 -0.101820025
## 124 -0.046139062 0.094931642
## 125 0.794582872 -1.114969878
## 126 -1.657177772 -0.594550063
## 127 -1.015289319 1.570678872
## 128 -0.203528030 0.162328917
## 129 -1.394646527 -1.226950898
## 130 0.336790655 1.330317984
## 131 0.277805008 1.938687957
## 132 0.753618506 0.966473845
## 133 0.424953233 -0.749208453
## 134 0.138557733 -1.713490669
## 135 0.254033042 -0.528544558
## 136 -1.144163663 -1.163345012
## 137 0.649207390 -0.822372924
## 138 -0.054652580 0.552046480
## 139 -0.470002442 0.800013457
## 140 0.161459430 -0.997251697
## 141 0.242242156 0.186594399
## 142 -1.151873824 -0.245559413
## 143 0.654203856 -0.379576578
## 144 0.004786473 -0.698059085
## 145 0.490773666 -1.262481895
## 146 -0.702319430 0.782874214
## 147 1.273111649 0.562486709
## 148 -1.141155097 -0.614169944
## 149 -0.721656339 -1.069007617
## 150 -1.566997226 0.712437978
## 151 -1.320426479 1.830825240
## 152 0.309299416 1.323857057
## 153 -0.275036651 -0.189651483
## 154 -0.324859301 -0.008541348
## 155 -0.259583674 0.581059598
## 156 -0.444356262 0.630898817
## 157 0.405278553 -0.732847037
## 158 0.242025812 -0.075541999
## 159 0.751025034 0.579767407
## 160 0.115784356 0.653389184
## 161 0.832224361 -0.992077728
## 162 0.267410235 -0.189493440
## 163 -0.035186530 -0.721378073
## 164 -0.173461123 1.159662406
## 165 1.379176239 -0.771372189
## 166 -1.097410823 -0.163931120
## 167 0.724174398 -0.560608300
## 168 -0.147101326 -0.156511323
## 169 -0.707566958 -0.772394199
## 170 1.641674120 -0.596230526
## 171 -0.471769025 -0.568277148
## 172 1.979679134 0.114636142
## 173 -1.343114845 -0.316052034
## 174 0.072864543 -0.291255339
## 175 1.107009864 0.600587230
## 176 1.092238443 -0.129195726
## 177 -0.339030186 -0.511472941
## 178 -1.149209176 -0.961500789
## 179 1.829792612 0.205582421
## 180 0.259451328 0.065962789
## 181 -0.348206224 -0.882158389
## 182 -0.055659941 0.940281437
## 183 -0.983288956 1.059068737
## 184 -0.391035088 -0.129223089
## 185 -0.108069546 -0.191300386
## 186 0.690161703 1.537417177
## 187 -0.345762466 -0.916599717
## 188 -0.190589984 -0.129226030
## 189 0.991849281 -0.748530502
## 190 -0.232622295 1.268910529
## 191 -1.470389310 2.655149392
## 192 -0.902783668 0.841285594
## 193 1.123553206 0.004236114
## 194 1.139118402 -1.674233092
## 195 -1.698349258 -0.183572306
## 196 -0.355592105 0.696597600
## 197 0.976438741 -0.061599360
## 198 -0.810432730 0.766231089
## 199 -0.716573116 0.278863492
## 200 0.085680422 0.029640556
sim_data_ts_m <- ts(sim_data, start = 1, frequency = 1)
plot(sim_data_ts_m, main="Simulasi Index Bulan SARIMA(0,0,4)(0,0,4)^[12]")
sim_data_ts_y <- ts(sim_data, start = 1, frequency = 12)
plot(sim_data_ts_y, main="Simulasi Index Tahun SARIMA(0,0,4)(0,0,4)^[12]")
# ACF dan PACF Plot
acf(sim_data_ts_m, lag.max=60, main="ACF")
pacf(sim_data_ts_m, , lag.max=60, main="PACF")
# Uji Stationeritas (ADF Test)
adf.test(sim_data)
## Warning in adf.test(sim_data): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: sim_data
## Dickey-Fuller = -10.616, Lag order = 10, p-value = 0.01
## alternative hypothesis: stationary
# Uji Asumsi White Noise (Ljung Box)
checkresiduals(model)
##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,0,4)(0,0,4)[12] with non-zero mean
## Q* = 8.9731, df = 16, p-value = 0.9145
##
## Model df: 8. Total lags used: 24
Box.test(residuals(model), lag = 35, type = "Ljung-Box")
##
## Box-Ljung test
##
## data: residuals(model)
## X-squared = 19.209, df = 35, p-value = 0.9861