REGRESSION WITH DISTRIBUTION LAG
Daily Climate Data In The City Of Delhi From 2013 to 2017
Package
library(rmarkdown)
library(bookdown)
library(dLagM)
library(dynlm)
library(MLmetrics)
library(lmtest)
library(car)
library(readxl)
library(readr)
library(dplyr)Pendahuluan
Data yang digunakan adalah data Prakiraan Cuaca di India.
Dataset ini menyediakan data dari 1 Januari 2013 hingga 24 April 2017 di kota Delhi, India yang berasal dari web https://www.kaggle.com/datasets/sumanthvrao/daily-climate-time-series-data?datasetId=312121 dengan jumlah amatan 1575. Variabel yang digunakan untuk analisis yaitu date, meantemp (rata-rata temperatur), dan humidity (kelembapan).
Model regresi yang memuat variabel tak bebas yang dipengaruhi oleh variabel bebas pada waktu t, serta dipengaruhi juga oleh variabel bebas pada waktu t-1,t-2 dan seterusnya disebut model dinamis distribusi lag, sebab pengaruh dari suatu atau beberapa variabel X terhadap variabel Y menyebar ke beberapa periode waktu. Model regresi yang memuat variabel tak bebas yang dipengaruhi oleh variabel bebas pada waktu t, serta dipengaruhi juga oleh variabel tak bebas itu sendiri pada waktu t-1 disebut model dinamis autoregressive (Jatinigrum, 2008). Metode Koyck didasari asumsi bahwa semakin jauh jarak lag pada variabel bebas dari periode sekarang maka semakin kecil pengaruh variabel lag terhadap variabel tak bebas (Gujarati 2004).
Tujuan
- Melihat hubungan antara meantemp (rata-rata temperatur) dengan humidity (kelembapan).
- Melakukan handling autokorelasi dengan model koyck, distibute lag, dan autoregressive.
- Membandingkan keakuratan ramalan antara model koyck, distibute lag, dan model autoregressive.
Input Data
web <- read_excel("C:/Users/hi/Downloads/DailyDelhiClimate.xlsx")
head(web)## # A tibble: 6 x 5
## date meantemp humidity wind_speed meanpressure
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 2013-01-01 10 84.5 0 1016.
## 2 2013-01-02 7.4 92 2.98 1018.
## 3 2013-01-03 7.17 87 4.63 1019.
## 4 2013-01-04 8.67 71.3 1.23 1017.
## 5 2013-01-05 6 86.8 3.7 1016.
## 6 2013-01-06 7 82.8 1.48 1018
dim(web)## [1] 1575 5
web$date <- as.Date(web$date,"%y/%m/%d")
t<-web$date
Xt<-web$humidity
Yt<-web$meantemp
datareg1<-cbind(t, Xt, Yt)
datareg <- as.data.frame(datareg1)Plot Data Time Series
data.y<-ts(Yt)
plot(data.y, main = "Time Series Plot of Mean Temperature In The City Of Delhi From 2013 to 2017", xlab = "Periode", ylab="Mean Temperature")
points(data.y)Scatter Plot
Scatter Plot antara Peubah Humidity (Kelembapan) sebagai X dan Meantemp (Rata-rata suhu) sebagai Y
plot(Xt, Yt, pch = 20, col = "red", main = "Scatter Plot Humidity and Mean Temperature")Korelasi Peubah X dan Y
cor(Xt, Yt)## [1] -0.5735528
Interpretasi : Berdasarkan scatter plot terlihat bahwa hubungan antara Peubah Humidity (Kelembapan) sebagai X dan Meantemp (Rata-rata suhu) sebagai Y memiliki hubungan linier negatif dengan nilai korelasi -0.5735528.
Model Regresi Awal
model_awal <- lm(web$meantemp~web$humidity, data = web)
summary(model_awal)##
## Call:
## lm(formula = web$meantemp ~ web$humidity, data = web)
##
## Residuals:
## Min 1Q Median 3Q Max
## -15.5569 -4.7598 -0.2826 5.5499 12.8759
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 40.227280 0.560859 71.72 <2e-16 ***
## web$humidity -0.248190 0.008938 -27.77 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.012 on 1573 degrees of freedom
## Multiple R-squared: 0.329, Adjusted R-squared: 0.3285
## F-statistic: 771.1 on 1 and 1573 DF, p-value: < 2.2e-16
Diperoleh model regresi linier data deret waktu yaitu: Yt^ = 40.227280 - 0.248190 (Xt)
P-Value<0.05 sehingga dapat disimpulkan bahwa peubah penjelas unique visits berpengaruh signifikan pada taraf nyata 5%. Didapatkan Adj R-squared rendah yaitu 0.3285 sehingga hanya 32.85% Y yang mampu dijelaskan oleh peubah penjelas X.
SPLIT DATA
Dilakukan splitting data dengan data train dengan jumlah amatan 80% dari jumlah seluruh amatan yaitu 1260 dan data test yaitu 20% dari jumlah seluruh amatan yaitu 315 amatan.
train<-datareg[1:1260, ]
test<-datareg[1261:1575, ]train.ts<-ts(train)
test.ts<-ts(test)
data.ts<-ts(datareg)Model KOYCK
1. Modelling
model.koyck <- dLagM :: koyckDlm(x=train$Xt , y=train$Yt)
summary(model.koyck)##
## Call:
## "Y ~ (Intercept) + Y.1 + X.t"
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.67645 -0.90790 0.05933 1.07491 6.81971
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.160809 0.430093 -0.374 0.7085
## Y.1 0.986097 0.008568 115.096 <2e-16 ***
## X.t 0.008824 0.004209 2.096 0.0362 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.714 on 1256 degrees of freedom
## Multiple R-Squared: 0.948, Adjusted R-squared: 0.9479
## Wald test: 1.149e+04 on 2 and 1256 DF, p-value: < 2.2e-16
##
## Diagnostic tests:
## NULL
##
## alpha beta phi
## Geometric coefficients: -11.56636 0.008823593 0.9860969
Didapatkan Adj-R-Square tinggi yaitu 0.9479.
AIC(model.koyck)## [1] 4934.807
BIC(model.koyck)## [1] 4955.359
2. Forecasting Koyck
(fore.koyck <- forecast(model = model.koyck, x=test$Xt, h=315))## $forecasts
## [1] 35.82508 35.59737 35.39417 35.20230 34.99829 34.82076 34.82822 34.73191
## [9] 34.62480 34.43804 34.20928 34.06635 33.93897 33.84675 33.87776 33.76544
## [17] 33.66636 33.68514 33.76189 33.82103 33.86335 33.83781 33.77184 33.69739
## [25] 33.73750 33.69054 33.64093 33.64715 33.72608 33.76973 33.84916 33.90653
## [33] 34.10263 34.23148 34.40005 34.37090 34.25779 34.12245 33.98246 33.93155
## [41] 33.93649 33.91379 34.00500 34.15010 34.23215 34.41104 34.58593 34.67781
## [49] 34.77826 34.77032 34.68695 34.60761 34.50977 34.53976 34.47383 34.38415
## [57] 34.37754 34.36754 34.51831 34.62759 34.66540 34.76117 34.71392 34.65652
## [65] 34.65358 34.71523 34.67430 34.61802 34.57657 34.51347 34.49117 34.55041
## [73] 34.54843 34.55860 34.53749 34.48098 34.56715 34.60340 34.75170 34.87750
## [81] 34.86478 34.77234 34.65140 34.54096 34.38522 34.25547 34.13017 33.99485
## [89] 33.87521 33.74108 33.60087 33.47644 33.47101 33.37105 33.25805 33.14662
## [97] 33.04409 32.94850 32.80673 32.71005 32.69120 32.65918 32.63090 32.56617
## [105] 32.48977 32.38739 32.26406 32.19573 32.11104 32.05011 31.98914 31.90926
## [113] 31.92083 31.95042 31.91730 31.84180 31.74971 31.66984 31.51970 31.37198
## [121] 31.19223 30.98599 30.81681 30.70533 30.55754 30.40636 30.25039 30.10299
## [129] 29.94482 29.81247 29.67378 29.58537 29.46697 29.37789 29.30446 29.26008
## [137] 29.21110 29.19809 29.25820 29.28009 29.23041 29.24476 29.20466 29.15220
## [145] 29.17353 29.17052 29.05696 28.95337 28.82859 28.70946 28.62632 28.57963
## [153] 28.51396 28.49258 28.42729 28.34094 28.24255 28.16216 28.14511 28.12153
## [161] 28.10323 27.99427 27.89809 27.80360 27.52579 27.27035 27.02719 26.81990
## [169] 26.76024 26.93403 27.13994 27.27129 27.19162 27.14027 27.10146 27.18083
## [177] 27.29815 27.40459 27.46387 27.65212 27.72083 27.73813 27.74182 27.71248
## [185] 27.66601 27.67890 27.69258 27.71625 27.66506 27.54786 27.48317 27.45077
## [193] 27.56743 27.71720 28.00310 28.11347 28.15783 28.20593 28.42818 28.66332
## [201] 28.87165 29.06711 29.18356 29.33956 29.38893 29.48081 29.60999 29.88311
## [209] 30.04383 30.17835 30.23278 30.28792 30.36406 30.37280 30.44513 30.50133
## [217] 30.60866 30.76740 30.87001 30.94304 30.93857 30.97294 31.05422 31.13225
## [225] 31.13976 31.16331 31.37786 31.46058 31.59272 31.71425 31.79683 31.86454
## [233] 31.95447 31.93657 32.02158 32.10029 32.17817 32.18470 32.13892 32.13482
## [241] 32.13055 32.15636 32.11319 32.12686 32.11057 32.08127 32.07192 31.96595
## [249] 31.92895 31.94850 31.92666 31.85249 31.86134 31.76161 31.53752 31.29450
## [257] 31.14356 31.07035 30.99264 30.85682 30.68986 30.58105 30.37007 30.16754
## [265] 29.95128 29.74857 29.54034 29.43407 29.47350 29.50071 29.46270 29.39190
## [273] 29.25775 29.18723 29.10372 28.97240 28.93555 28.78104 28.68137 28.60415
## [281] 28.47801 28.31833 28.20279 27.98222 27.77980 27.56012 27.35696 27.17463
## [289] 26.94042 26.73027 26.52981 26.31008 26.08128 25.82036 25.58174 25.47116
## [297] 25.18563 24.93827 24.68993 24.37225 24.04402 23.70555 23.44457 23.21467
## [305] 23.06310 22.85027 22.67398 22.53715 22.30418 22.04614 21.82147 21.70470
## [313] 21.60302 21.38451 21.16589
##
## $call
## forecast.koyckDlm(model = model.koyck, x = test$Xt, h = 315)
##
## attr(,"class")
## [1] "forecast.koyckDlm" "dLagM"
3. Akurasi Koyck
#mape data testing
mape.koyck <- MAPE(fore.koyck$forecasts, test$Yt)
#akurasi data training
mape_train <- dLagM::GoF(model.koyck)["MAPE"]
c("MAPE_testing" = mape.koyck, "MAPE_training" = mape_train)## $MAPE_testing
## [1] 0.329901
##
## $MAPE_training.MAPE
## [1] 0.05627624
Regression with Distributed Lag Model (DLM)
1. Modelling
lag_maks <- finiteDLMauto(formula = Yt ~ Xt,
data = data.frame(train),
model.type = "dlm", error.type = "AIC")
lag_maks## q - k MASE AIC BIC GMRAE MBRAE R.Adj.Sq Ljung-Box
## 10 10 3.68224 7810.885 7877.587 7.55843 1.08523 0.45345 0
Interpretasi : Didapatkan bahwa lag optimum untuk peubah humadity (kelembapan) berdasarkan AIC adalah 10 hari sebelumnya.
#model dlm dengan lag optimum
model.dlm2 = dLagM::dlm(x = train$Xt,y = train$Yt , q = 10)
summary(model.dlm2)##
## Call:
## lm(formula = model.formula, data = design)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.5838 -4.1883 -0.8187 4.1811 12.7323
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 45.1256107 0.6380213 70.727 < 2e-16 ***
## x.t -0.1415861 0.0198849 -7.120 1.82e-12 ***
## x.1 -0.0004205 0.0251396 -0.017 0.98666
## x.2 -0.0167603 0.0251177 -0.667 0.50472
## x.3 -0.0163930 0.0251270 -0.652 0.51426
## x.4 -0.0135291 0.0251681 -0.538 0.59099
## x.5 -0.0047920 0.0251377 -0.191 0.84885
## x.6 -0.0147046 0.0251528 -0.585 0.55892
## x.7 -0.0196327 0.0251136 -0.782 0.43451
## x.8 -0.0255408 0.0251385 -1.016 0.30983
## x.9 -0.0190720 0.0251406 -0.759 0.44823
## x.10 -0.0575160 0.0198315 -2.900 0.00379 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.473 on 1238 degrees of freedom
## Multiple R-squared: 0.4583, Adjusted R-squared: 0.4534
## F-statistic: 95.2 on 11 and 1238 DF, p-value: < 2.2e-16
##
## AIC and BIC values for the model:
## AIC BIC
## 1 7810.885 7877.587
Didapatkan Adj-R Square kecil yaitu 0.4534.
AIC(model.dlm2)## [1] 7810.885
BIC(model.dlm2)## [1] 7877.587
2. Forecasting
#ramalan
(fore.dlm2 <- forecast(model = model.dlm2, x=test$Xt, h=315))## $forecasts
## [1] 28.69309 29.09328 29.09564 28.29069 29.33206 28.96810 26.03300 27.12816
## [9] 27.35975 28.00912 28.03527 27.23056 26.84778 26.04310 23.78569 25.79567
## [17] 24.57973 23.59498 22.87019 23.34313 23.12841 23.24921 23.60010 23.61667
## [25] 21.15523 23.21056 22.73561 21.15133 19.89875 20.85987 20.28822 20.91519
## [33] 18.68567 19.68126 17.96747 21.28258 22.19137 22.43032 22.33925 21.42230
## [41] 20.30391 20.92770 18.54757 18.60088 19.74090 19.26222 19.47057 20.38505
## [49] 19.68197 20.48499 21.13282 21.14657 20.93345 18.82505 20.91062 20.89802
## [57] 20.08068 21.15067 18.95340 20.20732 21.34183 20.05507 22.33683 21.78641
## [65] 21.39379 20.28989 21.23623 21.21545 20.33415 21.35315 21.51175 20.03153
## [73] 21.76695 21.39371 21.62455 21.99282 20.44249 21.27088 19.06594 19.22662
## [81] 20.86480 21.67546 22.60959 22.70253 23.66969 23.37564 22.62164 23.42562
## [89] 23.15629 24.13285 25.44859 25.87296 24.27415 25.78071 26.03872 25.85359
## [97] 25.76886 25.87645 26.43982 25.71318 24.46932 24.63752 23.89941 24.95584
## [105] 25.17700 25.65652 25.96554 25.03524 25.46185 24.73552 24.35553 24.85227
## [113] 23.55304 23.57758 24.54596 25.13600 25.40995 25.01504 26.31851 26.10878
## [121] 26.67163 27.35409 26.65135 26.07937 27.36962 27.79706 28.19445 28.27526
## [129] 29.10280 28.74088 29.02287 28.26840 28.54561 27.73850 27.76091 27.26700
## [137] 27.32170 26.50525 25.25468 25.48981 26.37748 24.84214 25.83188 25.73159
## [145] 24.33530 24.41093 26.06928 25.67259 25.94632 26.42775 26.47824 25.61157
## [153] 26.29026 25.69858 26.23778 26.88897 27.81903 27.46851 26.57341 26.49914
## [161] 26.03697 27.19638 27.15170 27.16386 30.50323 30.32672 30.44494 30.14163
## [169] 27.82766 24.35276 23.86743 25.19806 28.22539 27.70523 28.69004 26.28672
## [177] 24.81974 23.63766 23.00702 19.72154 22.02671 23.29179 24.50822 24.56221
## [185] 24.72515 23.07329 23.00088 22.94417 24.56354 25.17365 25.46207 25.59958
## [193] 23.42628 22.91437 20.39866 22.58989 23.31170 23.30243 20.87254 20.75305
## [201] 19.84440 19.03080 19.04552 18.43930 19.65993 19.89296 19.42447 16.79115
## [209] 17.55432 17.66297 19.25046 19.50469 19.98601 20.79164 20.19385 20.05425
## [217] 19.12132 17.79621 19.47328 20.10244 21.74911 21.19358 20.44708 20.75461
## [225] 21.27868 20.92119 17.78593 19.87882 19.25621 19.43157 20.26902 20.28588
## [233] 19.53631 21.23296 19.70021 19.73467 18.67198 20.63121 21.17087 20.90364
## [241] 21.40883 21.18175 22.11711 21.73079 21.84298 22.31559 22.25397 24.23956
## [249] 23.46345 22.45017 23.19557 23.82623 22.84506 24.48904 26.75543 27.35263
## [257] 26.10366 25.78484 25.53229 26.15033 27.02441 26.88512 28.65140 29.33611
## [265] 30.22874 30.01894 29.76298 27.90305 25.91091 26.42840 27.42874 27.43665
## [273] 29.04278 28.00082 28.16034 28.39643 26.49740 27.72446 26.24190 26.38898
## [281] 27.76115 28.61294 28.26220 29.83016 29.74842 30.58441 30.02924 30.65584
## [289] 31.33910 31.12859 31.57204 32.40034 32.55407 33.80851 33.50962 31.76340
## [297] 34.62314 33.83370 34.35633 35.58563 36.06304 36.51410 35.61652 35.50690
## [305] 34.30267 34.75992 35.20296 34.56200 36.19832 36.92293 36.27942 34.55577
## [313] 33.79483 35.23943 34.67622
##
## $call
## forecast.dlm(model = model.dlm2, x = test$Xt, h = 315)
##
## attr(,"class")
## [1] "forecast.dlm" "dLagM"
3. Akurasi
#akurasi testing
mape.dlm2 <- MAPE(fore.dlm2$forecasts, test$Yt)
#akurasi data training
mape_train <- GoF(model.dlm2)["MAPE"]
c("MAPE_testing" = mape.dlm2, "MAPE_training" = mape_train)## $MAPE_testing
## [1] 0.2386126
##
## $MAPE_training.MAPE
## [1] 0.2132919
Model Autoregressive istributed Lag Model (ARDLM)
1. Modelling
#Lag optimum
plag <- ardlBoundOrders(data.frame(train),Yt~Xt);c(p=plag$p$Xt,q=plag$q)## p q
## 3 15
Interpretasi: Didapatkan lag optimum berdasarkan AIC untuk peubah humidity (Kelembapan) adalah 3 hari sebelumnya, sedangkan lag optimum untuk meantemp (rata-rata suhu) adalah 15 hari sebelumnya.
model.ardl = ardlDlm(x = train$Xt, y = train$Yt, p = 3 , q = 15) #p:lag x, q:lag y
summary(model.ardl)##
## Time series regression with "ts" data:
## Start = 16, End = 1260
##
## Call:
## dynlm(formula = as.formula(model.text), data = data, start = 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.6718 -0.6581 0.0685 0.7829 6.0004
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.782939 0.308280 5.784 9.28e-09 ***
## X.t -0.128166 0.004507 -28.438 < 2e-16 ***
## X.1 0.133579 0.007036 18.986 < 2e-16 ***
## X.2 -0.042135 0.007930 -5.313 1.28e-07 ***
## X.3 0.019692 0.005782 3.406 0.000682 ***
## Y.1 0.946507 0.028625 33.066 < 2e-16 ***
## Y.2 -0.159351 0.039054 -4.080 4.79e-05 ***
## Y.3 0.039568 0.034473 1.148 0.251272
## Y.4 0.069365 0.028368 2.445 0.014620 *
## Y.5 -0.025410 0.028281 -0.898 0.369106
## Y.6 0.035764 0.028187 1.269 0.204737
## Y.7 0.015024 0.028096 0.535 0.592937
## Y.8 0.013144 0.028074 0.468 0.639733
## Y.9 -0.014955 0.028067 -0.533 0.594250
## Y.10 0.004941 0.028066 0.176 0.860292
## Y.11 0.035778 0.028066 1.275 0.202637
## Y.12 0.008939 0.027970 0.320 0.749339
## Y.13 -0.021188 0.027955 -0.758 0.448638
## Y.14 0.013580 0.027932 0.486 0.626935
## Y.15 0.009420 0.022088 0.426 0.669832
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.244 on 1225 degrees of freedom
## Multiple R-squared: 0.9721, Adjusted R-squared: 0.9717
## F-statistic: 2246 on 19 and 1225 DF, p-value: < 2.2e-16
Didapatkan Adj-R-Squared = 0.9537 dan hanya X.4 yang signifikan pada taraf 5%.
AIC(model.ardl)## [1] 4097.741
BIC(model.ardl)## [1] 4205.406
2. Forecasting ADRLM
(fore.ardl <- forecast(model = model.ardl, x=test$Xt, h=315))## $forecasts
## [1] 34.79788 35.42211 34.93637 34.84388 34.94824 34.60025 32.01973 33.69565
## [9] 33.38199 34.65499 35.12803 33.91057 33.66110 33.01486 31.20208 33.38594
## [17] 32.87255 31.25801 30.33455 30.49789 30.51998 31.39699 31.76441 31.78481
## [25] 29.94386 31.11396 30.76761 30.05602 28.83628 29.23161 28.41908 28.68770
## [33] 26.40943 27.49362 26.43616 29.23337 29.86121 30.25285 30.05690 28.59340
## [41] 27.68874 27.99503 26.20500 25.51650 26.21944 24.58142 24.65908 25.60895
## [49] 25.26562 26.71554 27.43275 27.21929 27.38658 25.33619 26.73298 26.72265
## [57] 25.57255 25.56736 23.12383 23.83509 24.50536 23.64619 25.75542 25.56023
## [65] 24.75795 23.68485 25.18445 25.10683 24.92398 25.10990 24.42455 23.23993
## [73] 24.05864 23.68022 24.26809 24.60148 22.43311 23.29100 21.40190 21.88275
## [81] 23.60250 24.62394 24.90286 24.67642 25.26900 24.75242 24.76453 24.86835
## [89] 24.69312 24.94823 24.98485 24.85114 23.25120 24.80591 24.77842 24.97446
## [97] 24.87572 24.88250 25.56669 24.89172 23.91715 24.23275 24.14375 24.67833
## [105] 24.80689 25.30639 25.57312 24.76145 25.08185 24.72426 24.84918 25.07422
## [113] 23.77617 23.67933 24.51379 25.06025 25.31702 25.18583 26.22879 26.06976
## [121] 26.64117 27.01462 26.61121 25.87541 26.47481 26.54056 26.81131 26.77041
## [129] 27.05838 26.76312 27.02288 26.35683 27.03404 26.61510 26.56028 26.18139
## [137] 26.40423 25.88898 24.94436 25.57494 26.53594 25.57784 26.49370 26.51387
## [145] 25.51610 25.87955 27.37386 27.15719 27.59274 27.40450 26.95039 26.48794
## [153] 26.80801 26.16164 26.99494 27.19509 27.43215 27.22227 26.41823 26.58294
## [161] 26.49009 27.87839 27.60547 27.76641 30.39065 29.89168 30.01029 29.53214
## [169] 27.60689 24.43776 24.22825 25.24800 28.36730 27.77428 27.82136 25.99980
## [177] 25.59181 25.52985 26.27518 24.37066 26.21903 26.43481 26.65438 27.03504
## [185] 27.25195 26.26460 26.25077 25.96056 27.11258 27.96235 27.16453 26.76584
## [193] 24.61815 24.28288 22.16438 24.93640 25.46971 25.52819 22.83795 22.79378
## [201] 22.83826 22.91767 23.90198 23.16540 24.63570 23.53068 22.99330 20.77844
## [209] 22.48074 22.30341 23.44451 23.16935 22.88799 23.64860 22.48068 22.76400
## [217] 21.89453 21.17996 21.81954 22.06236 23.16874 22.44120 21.80116 21.71112
## [225] 22.64156 22.26413 19.55658 21.62109 20.42821 20.73849 21.06522 21.29557
## [233] 20.84126 22.29086 20.49980 20.85838 20.63084 21.59632 22.13153 21.57702
## [241] 21.56328 21.03584 22.03109 21.04629 21.69342 21.75644 21.48477 22.86619
## [249] 21.77418 21.20211 21.77001 22.45929 21.24977 23.04213 24.64783 24.95696
## [257] 23.71192 22.79387 22.97652 23.86984 24.33292 23.69822 25.46023 25.18498
## [265] 25.59217 25.53068 25.92443 24.53268 22.68900 23.07744 24.09505 24.66368
## [273] 25.66420 24.78708 25.20686 25.79063 24.47997 26.47761 25.54671 25.48169
## [281] 26.11507 26.69984 26.14574 27.86846 27.49994 28.03731 27.84552 27.76919
## [289] 28.67195 28.47118 28.55833 29.01443 29.34721 29.98334 29.83576 28.28885
## [297] 31.15773 30.45245 30.96560 32.07808 32.47966 32.83471 31.93419 31.86870
## [305] 30.99080 32.22610 31.71797 31.59065 33.22485 33.62216 33.39194 32.10095
## [313] 32.21185 33.98595 34.02079
##
## $call
## forecast.ardlDlm(model = model.ardl, x = test$Xt, h = 315)
##
## attr(,"class")
## [1] "forecast.ardlDlm" "dLagM"
3. Akurasi
#akurasi testing
mape.ardl <- MAPE(fore.ardl$forecasts, test$Yt) #data testing
#akurasi data training
mape_train <- GoF(model.ardl)["MAPE"]
c("MAPE_testing" = mape.ardl, "MAPE_training" = mape_train)## $MAPE_testing
## [1] 0.2075079
##
## $MAPE_training.MAPE
## [1] 0.04218636
Grafik Perbandingan Trend Aktual dengan 3 Metode Penanganan
par(mfrow=c(1,1))
plot(test$Xt, test$Yt, col="black")
points(test$Xt, fore.koyck$forecasts,col="red")
points(test$Xt, fore.dlm2$forecasts,col="blue")
points(test$Xt, fore.ardl$forecasts,col="green")
legend("topleft",c("aktual", "koyck","DLM 1", "autoregressive"), lty=1, col=c("black","red","blue","orange","green"), cex=0.8)Perbandingan Keakuratan Ramalan
#PERBANDINGAN
akurasi <- matrix(c(mape.koyck, mape.dlm2, mape.ardl))
row.names(akurasi) <- c("Koyck","DLM","Autoregressive")
colnames(akurasi) <- c("MAPE")
akurasi## MAPE
## Koyck 0.3299010
## DLM 0.2386126
## Autoregressive 0.2075079
Diagnostik Model
Uji Non Autokorelasi
#durbin watson
bgtest(model.ardl$model)##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: model.ardl$model
## LM test = 14.427, df = 1, p-value = 0.0001457
Uji Heterogenitas
bptest(model.ardl$model)##
## studentized Breusch-Pagan test
##
## data: model.ardl$model
## BP = 41.133, df = 19, p-value = 0.002317
Daftar Pustaka :
https://www.kaggle.com/datasets/sumanthvrao/daily-climate-time-series-data?datasetId=312121
Gujarati DN. 2004. Basic Econometrics 4th Edition. McGraw-Hill.
Nurahman MC, Wahyuningsih S, Yuniarti D. 2016. Model dinamis : autoregressive dan distribusi lag (studi kasus : pengaruh kurs dollar amerika terhadap produk domestik regional bruto (PDRB)). Jurnal Eksponensial. 7 (2) : 139-145.