Step 1: Input Data IPM

# impor data
library(rio)
## Warning: package 'rio' was built under R version 4.4.2
ipmJatim <- import("https://raw.githubusercontent.com/nida-kha44/MPDW/refs/heads/main/Pertemuan%202/Jatim.csv")
print(ipmJatim)
##    tahun   ipm
## 1   2010 65.36
## 2   2011 66.06
## 3   2012 66.74
## 4   2013 67.55
## 5   2014 68.14
## 6   2015 68.95
## 7   2016 69.74
## 8   2017 70.27
## 9   2018 70.77
## 10  2019 71.50
## 11  2020 71.71
## 12  2021 72.14
## 13  2022 72.75
## 14  2023 73.38
## 15  2024 74.09
summary(ipmJatim)
##      tahun           ipm       
##  Min.   :2010   Min.   :65.36  
##  1st Qu.:2014   1st Qu.:67.84  
##  Median :2017   Median :70.27  
##  Mean   :2017   Mean   :69.94  
##  3rd Qu.:2020   3rd Qu.:71.92  
##  Max.   :2024   Max.   :74.09

Step 2: Membuat Model Awal dengan OLS

# Membuat model regresi OLS (Ordinary Least Squares)
model_awal <- lm(ipm ~ tahun, data = ipmJatim)
summary(model_awal)
## 
## Call:
## lm(formula = ipm ~ tahun, data = ipmJatim)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.32633 -0.22312 -0.05776  0.22074  0.40481 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.157e+03  3.073e+01  -37.64 1.17e-14 ***
## tahun        6.081e-01  1.523e-02   39.92 5.50e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2549 on 13 degrees of freedom
## Multiple R-squared:  0.9919, Adjusted R-squared:  0.9913 
## F-statistic:  1594 on 1 and 13 DF,  p-value: 5.501e-15

Step 3: Identifikasi Lanjutan

3.1 Diagnosis Visual

# Ambil sisaan dari model
sisaan_awal <- residuals(model_awal)

# Plot sisaan terhadap waktu
plot(ipmJatim$tahun, sisaan_awal, type="o", pch=20, col="red",
     main="Plot Sisaan vs Waktu", xlab="Tahun", ylab="Sisaan")
abline(h=0, lty=2) # Garis referensi di y=0

Plot di atas menunjukkan pola yang tidak acak. Perhatikan bagaimana sisaan cenderung berkelompok: titik pertama di bawah nol, lalu naik ke atas nol, dan turun lagi. Ini adalah gejala visual yang kuat dari autokorelasi positif. Sisaan positif cenderung diikuti sisaan positif, dan sebaliknya.

3.2. Diagnosis Formal (Uji Durbin-Watson)

Visual saja tidak cukup, kita butuh bukti formal. Kita gunakan Uji Durbin-Watson.

  • H0 (Hipotesis Nol): Tidak ada autokorelasi. Sisaan saling bebas.

  • H1 (Hipotesis Alternatif): Ada autokorelasi.

library(lmtest)
## Warning: package 'lmtest' was built under R version 4.4.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.4.3
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
dwtest(model_awal)
## 
##  Durbin-Watson test
## 
## data:  model_awal
## DW = 0.42882, p-value = 3.91e-06
## alternative hypothesis: true autocorrelation is greater than 0

p-value yang dihasilkan sangat kecil (3.91e-06) dan berada di bawah tingkat signifikansi 5%, artinya Tolak H0. Berarti terbukti bahwa model berautokorelasi.

Step 4: Penanganan

4.1 Metode Cochrane-Orcutt

library(orcutt)
# Dengan fungsi R
model_co <- cochrane.orcutt(model_awal)
summary(model_co)
## Call:
## lm(formula = ipm ~ tahun, data = ipmJatim)
## 
##                Estimate  Std. Error t value  Pr(>|t|)    
## (Intercept) -1.0534e+03  7.4110e+01 -14.214 7.178e-09 ***
## tahun        5.5707e-01  3.6683e-02  15.186 3.375e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1456 on 12 degrees of freedom
## Multiple R-squared:  0.9505 ,  Adjusted R-squared:  0.9464
## F-statistic: 230.6 on 1 and 12 DF,  p-value: < 3.375e-09
## 
## Durbin-Watson statistic 
## (original):    0.42882 , p-value: 3.91e-06
## (transformed): 1.83151 , p-value: 2.555e-01
rho <- model_co$rho # rho paling optimum
cat("Rho optimum:", rho)
## Rho optimum: 0.7368492

Setelah dilakukan koreksi menggunakan metode Cochrane-Orcutt, diperoleh model baru dengan koefisien regresi yang tetap signifikan dan residual standard error yang lebih kecil. Nilai R2 model sedikit menurun menjadi 95,05%, tetapi autokorelasi berhasil diatasi (DW = 1,8315; p > 0,05).

# Dengan Perhitungan Manual
ipm.trans <- ipmJatim$ipm[-1] - ipmJatim$ipm[-12]*rho

tahun.trans <- ipmJatim$tahun[-1] - ipmJatim$tahun[-12]*rho
model_co_manual <- lm(ipm.trans~tahun.trans)

b0_co_manual <- coef(model_co_manual)[1]/(1-rho)
b1_co_manual <- coef(model_co_manual)[2]
cat("Koefisien manual Cochrane-Orcutt:\n")
## Koefisien manual Cochrane-Orcutt:
cat("b0:", b0_co_manual, "\n")
## b0: -999.8072
cat("b1:", b1_co_manual, "\n")
## b1: 0.5304916

4.2 Metode hildreth-Lu

#Penanganan Autokorelasi Hildreth lu
# Hildreth-Lu
hildreth.lu.func<- function(r, model){
  x <- model.matrix(model)[,-1]
  y <- model.response(model.frame(model))
  n <- length(y)
  t <- 2:n
  y <- y[t]-r*y[t-1]
  x <- x[t]-r*x[t-1]
  
  return(lm(y~x))
}

#Pencariab rho yang meminimumkan SSE
r <- c(seq(0.1,0.9, by= 0.1))
tab <- data.frame("rho" = r, "SSE" = sapply(r, function(i){deviance(hildreth.lu.func(i, model_awal))}))
round(tab, 4)
##   rho    SSE
## 1 0.1 0.5905
## 2 0.2 0.4932
## 3 0.3 0.4125
## 4 0.4 0.3484
## 5 0.5 0.3009
## 6 0.6 0.2699
## 7 0.7 0.2555
## 8 0.8 0.2577
## 9 0.9 0.2764

Pertama-tama akan dicari di mana kira-kira ρ yang menghasilkan SSE minimum. Pada hasil di atas terlihat ρminimum ketika 0.7. Namun, hasil tersebut masih kurang teliti sehingga akan dicari kembali ρ yang lebih optimum dengan ketelitian yang lebih. Jika sebelumnya jarak antar ρ yang dicari adalah 0.1, kali ini jarak antar ρ adalah 0.001 dan dilakukan pada selang 0.2 sampai dengan 0.5.

#Rho optimal di sekitar 0.4
rOpt <- seq(0.2,0.8, by= 0.001)
tabOpt <- data.frame("rho" = rOpt, "SSE" = sapply(rOpt, function(i){deviance(hildreth.lu.func(i, model_awal))}))
print(tabOpt[order(tabOpt$SSE),])
##       rho       SSE
## 538 0.737 0.2543887
## 537 0.736 0.2543893
## 539 0.738 0.2543898
## 536 0.735 0.2543915
## 540 0.739 0.2543925
## 535 0.734 0.2543954
## 541 0.740 0.2543969
## 534 0.733 0.2544010
## 542 0.741 0.2544030
## 533 0.732 0.2544082
## 543 0.742 0.2544107
## 532 0.731 0.2544171
## 544 0.743 0.2544201
## 531 0.730 0.2544276
## 545 0.744 0.2544311
## 530 0.729 0.2544398
## 546 0.745 0.2544438
## 529 0.728 0.2544536
## 547 0.746 0.2544581
## 528 0.727 0.2544691
## 548 0.747 0.2544741
## 527 0.726 0.2544863
## 549 0.748 0.2544918
## 526 0.725 0.2545051
## 550 0.749 0.2545111
## 525 0.724 0.2545255
## 551 0.750 0.2545320
## 524 0.723 0.2545477
## 552 0.751 0.2545547
## 523 0.722 0.2545714
## 553 0.752 0.2545789
## 522 0.721 0.2545969
## 554 0.753 0.2546049
## 521 0.720 0.2546240
## 555 0.754 0.2546325
## 520 0.719 0.2546527
## 556 0.755 0.2546617
## 519 0.718 0.2546831
## 557 0.756 0.2546926
## 518 0.717 0.2547152
## 558 0.757 0.2547252
## 517 0.716 0.2547489
## 559 0.758 0.2547594
## 516 0.715 0.2547843
## 560 0.759 0.2547953
## 515 0.714 0.2548214
## 561 0.760 0.2548329
## 514 0.713 0.2548601
## 562 0.761 0.2548721
## 513 0.712 0.2549004
## 563 0.762 0.2549129
## 512 0.711 0.2549424
## 564 0.763 0.2549554
## 511 0.710 0.2549861
## 565 0.764 0.2549996
## 510 0.709 0.2550314
## 566 0.765 0.2550454
## 509 0.708 0.2550784
## 567 0.766 0.2550929
## 508 0.707 0.2551271
## 568 0.767 0.2551421
## 507 0.706 0.2551774
## 569 0.768 0.2551929
## 506 0.705 0.2552293
## 570 0.769 0.2552453
## 505 0.704 0.2552830
## 571 0.770 0.2552994
## 504 0.703 0.2553382
## 572 0.771 0.2553552
## 503 0.702 0.2553952
## 573 0.772 0.2554127
## 502 0.701 0.2554537
## 574 0.773 0.2554717
## 501 0.700 0.2555140
## 575 0.774 0.2555325
## 500 0.699 0.2555759
## 576 0.775 0.2555949
## 499 0.698 0.2556395
## 577 0.776 0.2556590
## 498 0.697 0.2557047
## 578 0.777 0.2557247
## 497 0.696 0.2557716
## 579 0.778 0.2557920
## 496 0.695 0.2558401
## 580 0.779 0.2558611
## 495 0.694 0.2559103
## 581 0.780 0.2559318
## 494 0.693 0.2559821
## 582 0.781 0.2560041
## 493 0.692 0.2560556
## 583 0.782 0.2560781
## 492 0.691 0.2561308
## 584 0.783 0.2561538
## 491 0.690 0.2562076
## 585 0.784 0.2562311
## 490 0.689 0.2562861
## 586 0.785 0.2563101
## 489 0.688 0.2563662
## 587 0.786 0.2563907
## 488 0.687 0.2564480
## 588 0.787 0.2564730
## 487 0.686 0.2565315
## 589 0.788 0.2565570
## 486 0.685 0.2566166
## 590 0.789 0.2566426
## 485 0.684 0.2567033
## 591 0.790 0.2567298
## 484 0.683 0.2567918
## 592 0.791 0.2568188
## 483 0.682 0.2568818
## 593 0.792 0.2569093
## 482 0.681 0.2569736
## 594 0.793 0.2570016
## 481 0.680 0.2570670
## 595 0.794 0.2570955
## 480 0.679 0.2571620
## 596 0.795 0.2571910
## 479 0.678 0.2572587
## 597 0.796 0.2572882
## 478 0.677 0.2573571
## 598 0.797 0.2573871
## 477 0.676 0.2574571
## 599 0.798 0.2574876
## 476 0.675 0.2575588
## 600 0.799 0.2575898
## 475 0.674 0.2576622
## 601 0.800 0.2576936
## 474 0.673 0.2577672
## 473 0.672 0.2578738
## 472 0.671 0.2579821
## 471 0.670 0.2580921
## 470 0.669 0.2582037
## 469 0.668 0.2583170
## 468 0.667 0.2584319
## 467 0.666 0.2585485
## 466 0.665 0.2586668
## 465 0.664 0.2587867
## 464 0.663 0.2589083
## 463 0.662 0.2590315
## 462 0.661 0.2591564
## 461 0.660 0.2592829
## 460 0.659 0.2594111
## 459 0.658 0.2595410
## 458 0.657 0.2596725
## 457 0.656 0.2598057
## 456 0.655 0.2599405
## 455 0.654 0.2600770
## 454 0.653 0.2602152
## 453 0.652 0.2603550
## 452 0.651 0.2604964
## 451 0.650 0.2606395
## 450 0.649 0.2607843
## 449 0.648 0.2609307
## 448 0.647 0.2610788
## 447 0.646 0.2612286
## 446 0.645 0.2613800
## 445 0.644 0.2615330
## 444 0.643 0.2616878
## 443 0.642 0.2618441
## 442 0.641 0.2620022
## 441 0.640 0.2621619
## 440 0.639 0.2623232
## 439 0.638 0.2624862
## 438 0.637 0.2626509
## 437 0.636 0.2628172
## 436 0.635 0.2629852
## 435 0.634 0.2631548
## 434 0.633 0.2633261
## 433 0.632 0.2634991
## 432 0.631 0.2636737
## 431 0.630 0.2638499
## 430 0.629 0.2640279
## 429 0.628 0.2642075
## 428 0.627 0.2643887
## 427 0.626 0.2645716
## 426 0.625 0.2647561
## 425 0.624 0.2649424
## 424 0.623 0.2651302
## 423 0.622 0.2653197
## 422 0.621 0.2655109
## 421 0.620 0.2657038
## 420 0.619 0.2658983
## 419 0.618 0.2660944
## 418 0.617 0.2662922
## 417 0.616 0.2664917
## 416 0.615 0.2666928
## 415 0.614 0.2668956
## 414 0.613 0.2671001
## 413 0.612 0.2673062
## 412 0.611 0.2675139
## 411 0.610 0.2677233
## 410 0.609 0.2679344
## 409 0.608 0.2681471
## 408 0.607 0.2683615
## 407 0.606 0.2685776
## 406 0.605 0.2687953
## 405 0.604 0.2690146
## 404 0.603 0.2692356
## 403 0.602 0.2694583
## 402 0.601 0.2696827
## 401 0.600 0.2699086
## 400 0.599 0.2701363
## 399 0.598 0.2703656
## 398 0.597 0.2705966
## 397 0.596 0.2708292
## 396 0.595 0.2710634
## 395 0.594 0.2712994
## 394 0.593 0.2715370
## 393 0.592 0.2717762
## 392 0.591 0.2720171
## 391 0.590 0.2722597
## 390 0.589 0.2725039
## 389 0.588 0.2727498
## 388 0.587 0.2729973
## 387 0.586 0.2732465
## 386 0.585 0.2734974
## 385 0.584 0.2737499
## 384 0.583 0.2740040
## 383 0.582 0.2742599
## 382 0.581 0.2745173
## 381 0.580 0.2747765
## 380 0.579 0.2750373
## 379 0.578 0.2752997
## 378 0.577 0.2755638
## 377 0.576 0.2758296
## 376 0.575 0.2760970
## 375 0.574 0.2763661
## 374 0.573 0.2766369
## 373 0.572 0.2769093
## 372 0.571 0.2771833
## 371 0.570 0.2774590
## 370 0.569 0.2777364
## 369 0.568 0.2780154
## 368 0.567 0.2782961
## 367 0.566 0.2785784
## 366 0.565 0.2788624
## 365 0.564 0.2791481
## 364 0.563 0.2794354
## 363 0.562 0.2797244
## 362 0.561 0.2800150
## 361 0.560 0.2803073
## 360 0.559 0.2806012
## 359 0.558 0.2808968
## 358 0.557 0.2811941
## 357 0.556 0.2814930
## 356 0.555 0.2817936
## 355 0.554 0.2820958
## 354 0.553 0.2823997
## 353 0.552 0.2827053
## 352 0.551 0.2830125
## 351 0.550 0.2833213
## 350 0.549 0.2836318
## 349 0.548 0.2839440
## 348 0.547 0.2842579
## 347 0.546 0.2845733
## 346 0.545 0.2848905
## 345 0.544 0.2852093
## 344 0.543 0.2855298
## 343 0.542 0.2858519
## 342 0.541 0.2861757
## 341 0.540 0.2865011
## 340 0.539 0.2868282
## 339 0.538 0.2871569
## 338 0.537 0.2874873
## 337 0.536 0.2878194
## 336 0.535 0.2881531
## 335 0.534 0.2884885
## 334 0.533 0.2888255
## 333 0.532 0.2891642
## 332 0.531 0.2895046
## 331 0.530 0.2898466
## 330 0.529 0.2901903
## 329 0.528 0.2905356
## 328 0.527 0.2908826
## 327 0.526 0.2912312
## 326 0.525 0.2915815
## 325 0.524 0.2919335
## 324 0.523 0.2922871
## 323 0.522 0.2926423
## 322 0.521 0.2929993
## 321 0.520 0.2933579
## 320 0.519 0.2937181
## 319 0.518 0.2940800
## 318 0.517 0.2944435
## 317 0.516 0.2948088
## 316 0.515 0.2951756
## 315 0.514 0.2955442
## 314 0.513 0.2959143
## 313 0.512 0.2962862
## 312 0.511 0.2966597
## 311 0.510 0.2970348
## 310 0.509 0.2974117
## 309 0.508 0.2977901
## 308 0.507 0.2981703
## 307 0.506 0.2985521
## 306 0.505 0.2989355
## 305 0.504 0.2993206
## 304 0.503 0.2997074
## 303 0.502 0.3000958
## 302 0.501 0.3004859
## 301 0.500 0.3008776
## 300 0.499 0.3012710
## 299 0.498 0.3016660
## 298 0.497 0.3020627
## 297 0.496 0.3024611
## 296 0.495 0.3028611
## 295 0.494 0.3032628
## 294 0.493 0.3036661
## 293 0.492 0.3040711
## 292 0.491 0.3044778
## 291 0.490 0.3048861
## 290 0.489 0.3052960
## 289 0.488 0.3057076
## 288 0.487 0.3061209
## 287 0.486 0.3065359
## 286 0.485 0.3069525
## 285 0.484 0.3073707
## 284 0.483 0.3077906
## 283 0.482 0.3082122
## 282 0.481 0.3086354
## 281 0.480 0.3090603
## 280 0.479 0.3094868
## 279 0.478 0.3099150
## 278 0.477 0.3103449
## 277 0.476 0.3107764
## 276 0.475 0.3112096
## 275 0.474 0.3116444
## 274 0.473 0.3120809
## 273 0.472 0.3125190
## 272 0.471 0.3129588
## 271 0.470 0.3134003
## 270 0.469 0.3138434
## 269 0.468 0.3142881
## 268 0.467 0.3147346
## 267 0.466 0.3151826
## 266 0.465 0.3156324
## 265 0.464 0.3160838
## 264 0.463 0.3165368
## 263 0.462 0.3169916
## 262 0.461 0.3174479
## 261 0.460 0.3179060
## 260 0.459 0.3183656
## 259 0.458 0.3188270
## 258 0.457 0.3192900
## 257 0.456 0.3197547
## 256 0.455 0.3202210
## 255 0.454 0.3206889
## 254 0.453 0.3211586
## 253 0.452 0.3216299
## 252 0.451 0.3221028
## 251 0.450 0.3225774
## 250 0.449 0.3230537
## 249 0.448 0.3235316
## 248 0.447 0.3240112
## 247 0.446 0.3244924
## 246 0.445 0.3249753
## 245 0.444 0.3254598
## 244 0.443 0.3259460
## 243 0.442 0.3264339
## 242 0.441 0.3269234
## 241 0.440 0.3274146
## 240 0.439 0.3279074
## 239 0.438 0.3284019
## 238 0.437 0.3288981
## 237 0.436 0.3293959
## 236 0.435 0.3298954
## 235 0.434 0.3303965
## 234 0.433 0.3308993
## 233 0.432 0.3314037
## 232 0.431 0.3319098
## 231 0.430 0.3324175
## 230 0.429 0.3329270
## 229 0.428 0.3334380
## 228 0.427 0.3339507
## 227 0.426 0.3344651
## 226 0.425 0.3349812
## 225 0.424 0.3354989
## 224 0.423 0.3360182
## 223 0.422 0.3365392
## 222 0.421 0.3370619
## 221 0.420 0.3375862
## 220 0.419 0.3381122
## 219 0.418 0.3386399
## 218 0.417 0.3391692
## 217 0.416 0.3397001
## 216 0.415 0.3402327
## 215 0.414 0.3407670
## 214 0.413 0.3413029
## 213 0.412 0.3418405
## 212 0.411 0.3423797
## 211 0.410 0.3429207
## 210 0.409 0.3434632
## 209 0.408 0.3440074
## 208 0.407 0.3445533
## 207 0.406 0.3451008
## 206 0.405 0.3456500
## 205 0.404 0.3462009
## 204 0.403 0.3467534
## 203 0.402 0.3473075
## 202 0.401 0.3478633
## 201 0.400 0.3484208
## 200 0.399 0.3489800
## 199 0.398 0.3495407
## 198 0.397 0.3501032
## 197 0.396 0.3506673
## 196 0.395 0.3512331
## 195 0.394 0.3518005
## 194 0.393 0.3523696
## 193 0.392 0.3529403
## 192 0.391 0.3535127
## 191 0.390 0.3540867
## 190 0.389 0.3546624
## 189 0.388 0.3552398
## 188 0.387 0.3558188
## 187 0.386 0.3563995
## 186 0.385 0.3569818
## 185 0.384 0.3575658
## 184 0.383 0.3581515
## 183 0.382 0.3587388
## 182 0.381 0.3593278
## 181 0.380 0.3599184
## 180 0.379 0.3605107
## 179 0.378 0.3611046
## 178 0.377 0.3617002
## 177 0.376 0.3622974
## 176 0.375 0.3628964
## 175 0.374 0.3634969
## 174 0.373 0.3640992
## 173 0.372 0.3647030
## 172 0.371 0.3653086
## 171 0.370 0.3659158
## 170 0.369 0.3665246
## 169 0.368 0.3671351
## 168 0.367 0.3677473
## 167 0.366 0.3683611
## 166 0.365 0.3689766
## 165 0.364 0.3695938
## 164 0.363 0.3702126
## 163 0.362 0.3708330
## 162 0.361 0.3714551
## 161 0.360 0.3720789
## 160 0.359 0.3727043
## 159 0.358 0.3733314
## 158 0.357 0.3739602
## 157 0.356 0.3745906
## 156 0.355 0.3752226
## 155 0.354 0.3758564
## 154 0.353 0.3764917
## 153 0.352 0.3771288
## 152 0.351 0.3777674
## 151 0.350 0.3784078
## 150 0.349 0.3790498
## 149 0.348 0.3796935
## 148 0.347 0.3803388
## 147 0.346 0.3809858
## 146 0.345 0.3816344
## 145 0.344 0.3822847
## 144 0.343 0.3829366
## 143 0.342 0.3835902
## 142 0.341 0.3842455
## 141 0.340 0.3849024
## 140 0.339 0.3855610
## 139 0.338 0.3862212
## 138 0.337 0.3868831
## 137 0.336 0.3875467
## 136 0.335 0.3882119
## 135 0.334 0.3888788
## 134 0.333 0.3895473
## 133 0.332 0.3902175
## 132 0.331 0.3908893
## 131 0.330 0.3915628
## 130 0.329 0.3922379
## 129 0.328 0.3929148
## 128 0.327 0.3935932
## 127 0.326 0.3942733
## 126 0.325 0.3949551
## 125 0.324 0.3956386
## 124 0.323 0.3963237
## 123 0.322 0.3970104
## 122 0.321 0.3976988
## 121 0.320 0.3983889
## 120 0.319 0.3990806
## 119 0.318 0.3997740
## 118 0.317 0.4004691
## 117 0.316 0.4011657
## 116 0.315 0.4018641
## 115 0.314 0.4025641
## 114 0.313 0.4032658
## 113 0.312 0.4039691
## 112 0.311 0.4046741
## 111 0.310 0.4053808
## 110 0.309 0.4060891
## 109 0.308 0.4067990
## 108 0.307 0.4075106
## 107 0.306 0.4082239
## 106 0.305 0.4089388
## 105 0.304 0.4096554
## 104 0.303 0.4103737
## 103 0.302 0.4110936
## 102 0.301 0.4118151
## 101 0.300 0.4125383
## 100 0.299 0.4132632
## 99  0.298 0.4139898
## 98  0.297 0.4147179
## 97  0.296 0.4154478
## 96  0.295 0.4161793
## 95  0.294 0.4169125
## 94  0.293 0.4176473
## 93  0.292 0.4183838
## 92  0.291 0.4191219
## 91  0.290 0.4198617
## 90  0.289 0.4206031
## 89  0.288 0.4213462
## 88  0.287 0.4220910
## 87  0.286 0.4228374
## 86  0.285 0.4235855
## 85  0.284 0.4243352
## 84  0.283 0.4250866
## 83  0.282 0.4258397
## 82  0.281 0.4265944
## 81  0.280 0.4273508
## 80  0.279 0.4281088
## 79  0.278 0.4288685
## 78  0.277 0.4296298
## 77  0.276 0.4303928
## 76  0.275 0.4311575
## 75  0.274 0.4319238
## 74  0.273 0.4326917
## 73  0.272 0.4334614
## 72  0.271 0.4342327
## 71  0.270 0.4350056
## 70  0.269 0.4357802
## 69  0.268 0.4365564
## 68  0.267 0.4373344
## 67  0.266 0.4381139
## 66  0.265 0.4388952
## 65  0.264 0.4396780
## 64  0.263 0.4404626
## 63  0.262 0.4412488
## 62  0.261 0.4420366
## 61  0.260 0.4428262
## 60  0.259 0.4436173
## 59  0.258 0.4444102
## 58  0.257 0.4452047
## 57  0.256 0.4460008
## 56  0.255 0.4467986
## 55  0.254 0.4475981
## 54  0.253 0.4483992
## 53  0.252 0.4492020
## 52  0.251 0.4500064
## 51  0.250 0.4508125
## 50  0.249 0.4516202
## 49  0.248 0.4524296
## 48  0.247 0.4532407
## 47  0.246 0.4540534
## 46  0.245 0.4548678
## 45  0.244 0.4556838
## 44  0.243 0.4565015
## 43  0.242 0.4573209
## 42  0.241 0.4581419
## 41  0.240 0.4589645
## 40  0.239 0.4597888
## 39  0.238 0.4606148
## 38  0.237 0.4614425
## 37  0.236 0.4622718
## 36  0.235 0.4631027
## 35  0.234 0.4639353
## 34  0.233 0.4647696
## 33  0.232 0.4656055
## 32  0.231 0.4664431
## 31  0.230 0.4672823
## 30  0.229 0.4681232
## 29  0.228 0.4689658
## 28  0.227 0.4698100
## 27  0.226 0.4706559
## 26  0.225 0.4715034
## 25  0.224 0.4723526
## 24  0.223 0.4732034
## 23  0.222 0.4740559
## 22  0.221 0.4749101
## 21  0.220 0.4757659
## 20  0.219 0.4766233
## 19  0.218 0.4774825
## 18  0.217 0.4783432
## 17  0.216 0.4792057
## 16  0.215 0.4800698
## 15  0.214 0.4809355
## 14  0.213 0.4818030
## 13  0.212 0.4826720
## 12  0.211 0.4835428
## 11  0.210 0.4844151
## 10  0.209 0.4852892
## 9   0.208 0.4861649
## 8   0.207 0.4870423
## 7   0.206 0.4879213
## 6   0.205 0.4888019
## 5   0.204 0.4896843
## 4   0.203 0.4905683
## 3   0.202 0.4914539
## 2   0.201 0.4923412
## 1   0.200 0.4932302
#Grafik SSE optimum
par(mfrow = c(1,1))
plot(tab$SSE ~ tab$rho , type = "l", xlab = "Rho", ylab = "SSE")
abline(v = tabOpt[tabOpt$SSE==min(tabOpt$SSE),"rho"], lty = 2, col="red",lwd=2)
text(x=0.737, y=0.2543887, labels = "rho=0.737", cex = 0.8)

Dari tabel dan plot di atas, dapat diketahui rho optimum adalah 0.737

library(HoRM)
## Warning: package 'HoRM' was built under R version 4.4.3
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
model_hl <- hildreth.lu(ipmJatim$ipm, ipmJatim$tahun, rho = 0.737)
summary(model_hl)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.292526 -0.079010 -0.006555  0.107205  0.202834 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -277.0387    19.5023  -14.21 7.23e-09 ***
## x              0.5570     0.0367   15.18 3.40e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1456 on 12 degrees of freedom
## Multiple R-squared:  0.9505, Adjusted R-squared:  0.9464 
## F-statistic: 230.3 on 1 and 12 DF,  p-value: 3.399e-09
#Transformasi Balik
cat("y = ", coef(model_hl)[1]/(1-0.341), "+", coef(model_hl)[2],"x", sep = "")
## y = -420.3926+0.5570441x
#Deteksi autokorelasi
dwtest(model_hl)
## 
##  Durbin-Watson test
## 
## data:  model_hl
## DW = 1.8317, p-value = 0.2556
## alternative hypothesis: true autocorrelation is greater than 0

Hasil estimasi regresi Hildreth-Lu menunjukkan bahwa variabel x berpengaruh positif dan signifikan terhadap y, dengan koefisien sebesar 0.5570. Hal ini berarti setiap peningkatan 1 unit pada x akan meningkatkan nilai y sebesar 0.5570 unit. Model memiliki tingkat kecocokan yang sangat tinggi, ditunjukkan dengan nilai R2 sebesar 95,05%. Selain itu, hasil uji Durbin-Watson menghasilkan nilai DW = 1,83 dengan p-value = 0,2556, yang mengindikasikan bahwa tidak terdapat autokorelasi pada residual model.

Tahap 5: Evaluasi Akhir

# Menghitung SSE untuk setiap model secara manual
sse_awal <- sum(residuals(model_awal)^2)
sse_co <- sum(residuals(model_co)^2)
sse_hl <- sum(residuals(model_hl)^2)

# Membuat tabel perbandingan
data.frame(
  Metode = c("Model Awal (Sakit)", "Cochrane-Orcutt (Sehat)", "Hildreth-Lu (Sehat)"),
  SSE = c(sse_awal, sse_co, sse_hl),
  DW_Statistic = c(dwtest(model_awal)$statistic, model_co$DW[3], dwtest(model_hl)$statistic)
)
##                    Metode       SSE DW_Statistic
## 1      Model Awal (Sakit) 0.8447676    0.4288209
## 2 Cochrane-Orcutt (Sehat) 2.4036228    1.8315093
## 3     Hildreth-Lu (Sehat) 0.2543887    1.8317495

Hasil perbandingan tiga metode menunjukkan bahwa model awal memiliki nilai SSE yang relatif kecil (0.8448), tetapi bermasalah karena uji Durbin-Watson menunjukkan adanya autokorelasi positif yang cukup kuat (DW = 0.4288). Setelah dilakukan perbaikan menggunakan metode Cochrane-Orcutt, nilai Durbin-Watson meningkat menjadi 1.8315 sehingga masalah autokorelasi berhasil diatasi, meskipun SSE meningkat menjadi 2.4036. Sementara itu, metode Hildreth-Lu menghasilkan performa terbaik dengan nilai SSE paling kecil (0.2544) dan statistik Durbin-Watson sebesar 1.8317 yang mengindikasikan tidak adanya autokorelasi. Dengan demikian, model Hildreth-Lu dapat dikatakan sebagai metode yang paling optimal karena mampu menghasilkan model yang sehat sekaligus meminimalkan error.