Instalasi Paket &
Persiapan Data
Instalasi Paket R
(Jalankan Sekali Saja)
Petunjuk: Jalankan
chunk di bawah ini satu kali saja secara manual di RStudio (klik ikon
Run hijau di pojok kanan atas chunk ini). Parameter eval=FALSE sengaja
digunakan agar proses instalasi tidak dijalankan ulang saat Anda menekan
tombol Knit.
Memuat Paket &
Mengimpor Dataset
install.packages("collapse", repos = "https://cloud.r-project.org", dependencies = TRUE)
## package 'collapse' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Acer\AppData\Local\Temp\RtmpI5IHF7\downloaded_packages
install.packages("plm", repos = "https://cloud.r-project.org", dependencies = TRUE)
## package 'plm' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\Acer\AppData\Local\Temp\RtmpI5IHF7\downloaded_packages
library(knitr)
library(tidyverse)
library(readxl)
library(psych)
library(tseries)
library(forecast)
library(urca)
library(lmtest)
library(car)
library(sandwich)
library(plm)
OPSI 2: GUNAKAN DATASET
ASLI MAHASISWA
==============================================================================
kandidat_file <- c(
"Christomi_Sanda_Boro_240611010006_Data_Extract_From_World_Development_Indicators_2.xlsx",
"Christomi_Sanda_Boro_240611010006_Data_Extract_From_World_Development_Indicators.xlsx"
)
file_ditemukan <- kandidat_file[file.exists(kandidat_file)][1]
if (is.na(file_ditemukan)) {
stop(
"File Excel tidak ditemukan di folder kerja saat ini (", getwd(), "). ",
"Pindahkan file .xlsx ke folder yang sama dengan file .Rmd atau isi path lengkapnya."
)
}
data_panel <- readxl::read_excel(file_ditemukan, sheet = "Data") %>%
dplyr::rename(
Wilayah = `Nama negara`,
Tahun = Tahun,
Y = `GDP per kapita (constant 2015 US$)`,
X1 = `Emisi Karbon per Kapita`,
X2 = `Konsumsi energi per kapita`,
X3 = `Industrialisasi(% of GDP)`
) %>%
dplyr::mutate(
Wilayah = trimws(as.character(Wilayah)),
Tahun = as.integer(Tahun),
dplyr::across(
c(Y, X1, X2, X3),
~ as.numeric(dplyr::na_if(trimws(as.character(.x)), ".."))
)
) %>%
dplyr::select(Wilayah, Tahun, Y, X1, X2, X3)
dplyr::glimpse(data_panel)
## Rows: 210
## Columns: 6
## $ Wilayah <chr> "Brazil", "Russian Federation", "India", "China", "South Afric…
## $ Tahun <int> 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 20…
## $ Y <dbl> 7409.5691, 7323.3853, 947.7326, 3465.7277, 5406.0758, 2635.703…
## $ X1 <dbl> 1.99935674, 12.11898323, 1.05460489, 4.78299420, 8.81501534, 2…
## $ X2 <dbl> 1173.7159, 4541.2086, 424.9064, 1369.7906, 2382.7225, 778.7696…
## $ X3 <dbl> 24.17258, 32.62923, 29.53376, 46.38162, 26.01508, 34.14867, 11…
Analisis Deskriptif
& Plot Deret Waktu
Analisis Deskriptif
& Plot Deret Waktu
# 1. Pilih satu wilayah (ganti "Indonesia" dengan negara lain jika diinginkan:
# "Brazil", "Russian Federation", "India", "China", "South Africa",
# "Egypt, Arab Rep.", "Ethiopia", "Iran, Islamic Rep.", "United Arab Emirates", "Indonesia")
wilayah_pilihan <- "Indonesia"
data_wilayah <- data_panel %>%
dplyr::filter(Wilayah == wilayah_pilihan) %>%
dplyr::arrange(Tahun) %>%
tidyr::drop_na(Y)
# 2. Konversi variabel Y ke objek time series (ts)
# frequency = 1 (tahunan), 4 (kuartalan), 12 (bulanan)
tahun_awal <- min(data_wilayah$Tahun, na.rm = TRUE)
y_ts <- stats::ts(data_wilayah$Y, start = c(tahun_awal, 1), frequency = 1)
# 3. Statistik deskriptif
desc_ts <- psych::describe(as.numeric(y_ts))[, c("n", "mean", "sd", "median", "min", "max")]
knitr::kable(desc_ts, digits = 3, caption = paste("Statistik Deskriptif Variabel Y -", wilayah_pilihan))
Statistik Deskriptif Variabel Y - Indonesia
| X1 |
21 |
3282.572 |
725.054 |
3288.223 |
2155.448 |
4555.181 |
# 4. Plot deret waktu
forecast::autoplot(y_ts) +
ggplot2::labs(
title = paste("Plot Deret Waktu Variabel Y -", wilayah_pilihan),
x = "Tahun",
y = "Nilai Y"
) +
ggplot2::theme_minimal()
# Uji Asumsi Stasioneritas
# 1. Uji Augmented Dickey-Fuller (ADF) pada Level
# H0: Data tidak stasioner (ada akar unit) | Tolak H0 jika p-value < 0.05
adf_level <- tseries::adf.test(y_ts)
print(adf_level)
##
## Augmented Dickey-Fuller Test
##
## data: y_ts
## Dickey-Fuller = -2.6682, Lag order = 2, p-value = 0.3178
## alternative hypothesis: stationary
# 2. Uji ADF pada First Difference (d = 1)
y_diff1 <- diff(y_ts, differences = 1)
adf_diff1 <- tseries::adf.test(y_diff1)
print(adf_diff1)
##
## Augmented Dickey-Fuller Test
##
## data: y_diff1
## Dickey-Fuller = -2.3477, Lag order = 2, p-value = 0.4399
## alternative hypothesis: stationary
# Plot data First Difference
forecast::autoplot(y_diff1) +
ggplot2::labs(
title = paste("Plot First Difference (d = 1) -", wilayah_pilihan),
x = "Tahun",
y = "Delta Y"
) +
ggplot2::theme_minimal()

Identifikasi, Estimasi,
& Pemilihan Model Terbaik (AR, MA, ARIMA)
# 1. Plot ACF & PACF data stasioner untuk identifikasi orde AR (p) dan MA (q)
forecast::ggtsdisplay(y_diff1, main = "Plot ACF dan PACF Data Stasioner (d = 1)")

# 2. Estimasi kandidat model AR, MA, dan ARIMA (sesuaikan orde d jika data stasioner di level)
model_ar <- forecast::Arima(y_ts, order = c(1, 1, 0))
model_ma <- forecast::Arima(y_ts, order = c(0, 1, 1))
model_arima <- forecast::Arima(y_ts, order = c(1, 1, 1))
model_auto <- forecast::auto.arima(y_ts, trace = TRUE)
##
## ARIMA(2,1,2) with drift : Inf
## ARIMA(0,1,0) with drift : 225.0588
## ARIMA(1,1,0) with drift : 227.7145
## ARIMA(0,1,1) with drift : 227.6462
## ARIMA(0,1,0) : 254.9032
## ARIMA(1,1,1) with drift : 230.6409
##
## Best model: ARIMA(0,1,0) with drift
# 3. Tabel perbandingan AIC & BIC (Catatan: perbandingan AIC/BIC valid untuk orde d yang sama)
tabel_arima <- tibble::tibble(
Kandidat = c("AR(1) / ARIMA(1,1,0)", "MA(1) / ARIMA(0,1,1)", "ARIMA(1,1,1)", "Auto ARIMA"),
Orde_pdq = c(
paste(forecast::arimaorder(model_ar), collapse = ","),
paste(forecast::arimaorder(model_ma), collapse = ","),
paste(forecast::arimaorder(model_arima), collapse = ","),
paste(forecast::arimaorder(model_auto), collapse = ",")
),
AIC = c(stats::AIC(model_ar), stats::AIC(model_ma), stats::AIC(model_arima), stats::AIC(model_auto)),
BIC = c(stats::BIC(model_ar), stats::BIC(model_ma), stats::BIC(model_arima), stats::BIC(model_auto))
)
knitr::kable(tabel_arima, digits = 2, caption = "Perbandingan Model AR, MA, dan ARIMA")
Perbandingan Model AR, MA, dan ARIMA
| AR(1) / ARIMA(1,1,0) |
1,1,0 |
236.02 |
238.01 |
| MA(1) / ARIMA(0,1,1) |
0,1,1 |
246.16 |
248.15 |
| ARIMA(1,1,1) |
1,1,1 |
231.72 |
234.71 |
| Auto ARIMA |
0,1,0 |
224.35 |
226.34 |
Uji Diagnostik Residual
& Hasil Peramalan (Forecasting)
# Pilih model terbaik (ganti model_auto jika kandidat manual lebih baik)
model_ts_terbaik <- model_auto
summary(model_ts_terbaik)
## Series: y_ts
## ARIMA(0,1,0) with drift
##
## Coefficients:
## drift
## 119.9866
## s.e. 13.3567
##
## sigma^2 = 3756: log likelihood = -110.18
## AIC=224.35 AICc=225.06 BIC=226.34
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.09692667 58.2951 32.13078 -0.08397544 0.9011873 0.2450261
## ACF1
## Training set 0.08104743
# 1. Uji Diagnostik Residual: Ljung-Box Test (Autokorelasi) & Plot Residual
forecast::checkresiduals(model_ts_terbaik)

##
## Ljung-Box test
##
## data: Residuals from ARIMA(0,1,0) with drift
## Q* = 2.4086, df = 4, p-value = 0.6611
##
## Model df: 0. Total lags used: 4
# 2. Uji Normalitas Residual (Jarque-Bera)
tseries::jarque.bera.test(stats::na.omit(as.numeric(stats::residuals(model_ts_terbaik))))
##
## Jarque Bera Test
##
## data: stats::na.omit(as.numeric(stats::residuals(model_ts_terbaik)))
## X-squared = 99.379, df = 2, p-value < 2.2e-16
# 3. Hasil Utama: Peramalan 5 periode ke depan
hasil_ramalan <- forecast::forecast(model_ts_terbaik, h = 5)
print(hasil_ramalan)
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## 2026 4675.167 4596.625 4753.709 4555.048 4795.287
## 2027 4795.154 4684.079 4906.229 4625.279 4965.028
## 2028 4915.140 4779.102 5051.179 4707.088 5123.193
## 2029 5035.127 4878.043 5192.211 4794.888 5275.366
## 2030 5155.114 4979.489 5330.739 4886.519 5423.709
forecast::autoplot(hasil_ramalan) +
ggplot2::labs(
title = paste("Peramalan 5 Periode Ke Depan -", wilayah_pilihan),
x = "Tahun",
y = "Nilai Prediksi Y"
) +
ggplot2::theme_minimal()

Regresi Linear Berganda
(OLS)
Instruksi: Gunakan data cross-section (satu irisan waktu tertentu)
atau data agregat dengan minimal 1 variabel dependen (\(Y\)) dan 2 variabel independen (\(X\)).
Analisis Deskriptif
& Matriks Korelasi
# Ambil irisan tahun lengkap terbaru (2024; tahun 2025 memiliki nilai "..")
tahun_ols <- data_panel %>%
tidyr::drop_na(Y, X1, X2, X3) %>%
dplyr::summarise(max_thn = max(Tahun, na.rm = TRUE)) %>%
dplyr::pull(max_thn)
data_ols <- data_panel %>%
dplyr::filter(Tahun == tahun_ols) %>%
dplyr::select(Wilayah, Y, X1, X2, X3) %>%
tidyr::drop_na()
# Statistik deskriptif
desc_ols <- psych::describe(data_ols %>% dplyr::select(Y, X1, X2, X3))[, c("n", "mean", "sd", "min", "max")]
knitr::kable(desc_ols, digits = 3, caption = paste("Statistik Deskriptif Data Cross-Section Tahun", tahun_ols))
Statistik Deskriptif Data Cross-Section Tahun 2024
| Y |
10 |
9868.967 |
11799.313 |
883.459 |
41605.414 |
| X1 |
10 |
6.749 |
5.906 |
0.147 |
18.255 |
| X2 |
10 |
2747.571 |
2678.990 |
393.245 |
8837.831 |
| X3 |
10 |
31.582 |
7.545 |
20.941 |
44.329 |
# Matriks korelasi
matriks_cor <- stats::cor(data_ols %>% dplyr::select(Y, X1, X2, X3))
knitr::kable(matriks_cor, digits = 3, caption = "Matriks Korelasi Antarvariabel")
Matriks Korelasi Antarvariabel
| Y |
1.000 |
0.818 |
0.895 |
0.613 |
| X1 |
0.818 |
1.000 |
0.971 |
0.624 |
| X2 |
0.895 |
0.971 |
1.000 |
0.618 |
| X3 |
0.613 |
0.624 |
0.618 |
1.000 |
Interpretasi Analisis Deskriptif: (Jelaskan sebaran masing-masing
variabel dan arah hubungan korelasi awal antara variabel \(X\) dan \(Y\)).
Estimasi Model &
Uji Asumsi Klasik
# Estimasi model OLS
model_ols <- stats::lm(Y ~ X1 + X2 + X3, data = data_ols)
# 1. Uji Normalitas Residual (Shapiro-Wilk & Jarque-Bera; normal jika p-value > 0.05)
stats::shapiro.test(stats::residuals(model_ols))
##
## Shapiro-Wilk normality test
##
## data: stats::residuals(model_ols)
## W = 0.93932, p-value = 0.5455
tseries::jarque.bera.test(stats::residuals(model_ols))
##
## Jarque Bera Test
##
## data: stats::residuals(model_ols)
## X-squared = 0.70787, df = 2, p-value = 0.7019
# 2. Uji Multikolinearitas (Bebas multikolinearitas jika VIF < 10)
car::vif(model_ols)
## X1 X2 X3
## 17.764022 17.532802 1.644771
# 3. Uji Heteroskedastisitas / Heterogenitas Varians (Breusch-Pagan; homoskedastis jika p-value > 0.05)
lmtest::bptest(model_ols)
##
## studentized Breusch-Pagan test
##
## data: model_ols
## BP = 6.8636, df = 3, p-value = 0.07637
# 4. Uji Autokorelasi (Durbin-Watson; wajib diperhatikan jika memakai data deret waktu)
lmtest::dwtest(model_ols)
##
## Durbin-Watson test
##
## data: model_ols
## DW = 2.1504, p-value = 0.5324
## alternative hypothesis: true autocorrelation is greater than 0
Interpretasi Uji Asumsi Klasik: (Jelaskan apakah model memenuhi
asumsi normalitas, bebas multikolinearitas, homoskedastisitas, dan bebas
autokorelasi).
Hasil Uji Utama
Regresi Linear Berganda
# Output standar OLS
summary(model_ols)
##
## Call:
## stats::lm(formula = Y ~ X1 + X2 + X3, data = data_ols)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7774 -1984 235 3734 5585
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4943.060 8583.842 -0.576 0.5856
## X1 -1893.891 1295.590 -1.462 0.1941
## X2 7.632 2.838 2.690 0.0361 *
## X3 209.731 308.579 0.680 0.5221
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5446 on 6 degrees of freedom
## Multiple R-squared: 0.858, Adjusted R-squared: 0.7869
## F-statistic: 12.08 on 3 and 6 DF, p-value: 0.005925
# Jika terdapat indikasi heteroskedastisitas (p-value bptest < 0.05),
# gunakan estimasi Robust Standard Errors (HC1):
lmtest::coeftest(model_ols, vcov. = sandwich::vcovHC(model_ols, type = "HC1"))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -4943.0600 7236.2891 -0.6831 0.52004
## X1 -1893.8913 1381.0343 -1.3714 0.21934
## X2 7.6323 2.9483 2.5887 0.04128 *
## X3 209.7311 271.3476 0.7729 0.46891
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Interpretasi Hasil Uji Utama: (Tuliskan persamaan regresi yang
terbentuk, interpretasikan arah dan besar koefisien parsial beserta
signifikansi uji-\(t\), hasil uji
simultan uji-\(F\), dan persentase
variasi \(Y\) yang dijelaskan oleh
model melalui Adjusted \(R^2\)).
Analisis Data
Panel
Analisis Deskriptif
& Visualisasi Heterogenitas
library(dplyr)
library(tidyr)
library(psych)
library(plm)
library(ggplot2)
# Bersihkan NA dan deklarasikan struktur data panel
data_panel_clean <- data_panel |>
dplyr::select(Wilayah, Tahun, Y, X1, X2, X3) |>
tidyr::drop_na()
pdata <- plm::pdata.frame(data_panel_clean, index = c("Wilayah", "Tahun"))
# 1. Statistik deskriptif keseluruhan (Overall)
desc_panel <- psych::describe(data_panel_clean[, c("Y", "X1", "X2", "X3")])[, c("n", "mean", "sd", "min", "max")]
knitr::kable(desc_panel, digits = 3, caption = "Statistik Deskriptif Data Panel (Overall)")
Statistik Deskriptif Data Panel (Overall)
| Y |
200 |
9093.794 |
12444.744 |
290.833 |
56629.971 |
| X1 |
200 |
6.759 |
6.679 |
0.070 |
26.252 |
| X2 |
200 |
2534.600 |
2544.012 |
365.389 |
10191.701 |
| X3 |
200 |
33.061 |
10.650 |
9.435 |
58.018 |
# 2. Ringkasan antarwilayah (Between)
ringkasan_wilayah <- data_panel_clean |>
dplyr::group_by(Wilayah) |>
dplyr::summarise(
Mean_Y = mean(Y),
SD_Y = stats::sd(Y),
Min_Y = min(Y),
Max_Y = max(Y),
.groups = "drop"
)
knitr::kable(ringkasan_wilayah, digits = 3, caption = "Ringkasan Variabel Y Antarwilayah (Between)")
Ringkasan Variabel Y Antarwilayah (Between)
| Brazil |
8705.105 |
572.985 |
7409.569 |
9566.745 |
| China |
8058.123 |
2981.354 |
3465.728 |
13119.108 |
| Egypt, Arab Rep. |
3395.692 |
428.507 |
2635.703 |
4137.609 |
| Ethiopia |
579.395 |
192.271 |
290.833 |
883.459 |
| India |
1567.679 |
429.458 |
947.733 |
2366.833 |
| Indonesia |
3218.942 |
681.081 |
2155.448 |
4367.947 |
| Iran, Islamic Rep. |
5168.733 |
286.904 |
4650.358 |
5834.443 |
| Russian Federation |
9349.163 |
871.547 |
7323.385 |
11092.634 |
| South Africa |
5916.826 |
221.403 |
5406.076 |
6170.877 |
| United Arab Emirates |
44978.281 |
4581.543 |
39878.466 |
56629.971 |
# 3. Visualisasi heterogenitas antarwilayah (Boxplot)
ggplot2::ggplot(data_panel_clean, ggplot2::aes(x = stats::reorder(Wilayah, Y, stats::median), y = Y)) +
ggplot2::geom_boxplot(fill = "steelblue", alpha = 0.7) +
ggplot2::coord_flip() +
ggplot2::labs(
title = "Heterogenitas Variabel Y Antarwilayah",
x = "Wilayah",
y = "Variabel Y"
) +
ggplot2::theme_minimal()
Interpretasi Deskriptif & Heterogenitas Awal: (Jelaskan perbedaan
nilai rata-rata dan rentang sebaran variabel \(Y\) antarwilayah berdasarkan tabel dan
boxplot).
Pemilihan Model
Terbaik (CEM, FEM, REM)
library(plm)
# 1. Estimasi ketiga model data panel
cem <- plm::plm(Y ~ X1 + X2 + X3, data = pdata, model = "pooling")
fem <- plm::plm(Y ~ X1 + X2 + X3, data = pdata, model = "within")
# Catatan: Jika jumlah wilayah (N) <= jumlah variabel dan REM error, tambahkan random.method = "walhus"
rem <- plm::plm(Y ~ X1 + X2 + X3, data = pdata, model = "random")
# 2. Uji Chow (CEM vs FEM -> jika p-value < 0.05 pilih FEM)
plm::pFtest(fem, cem)
##
## F test for individual effects
##
## data: Y ~ X1 + X2 + X3
## F = 299.67, df1 = 9, df2 = 187, p-value < 2.2e-16
## alternative hypothesis: significant effects
# 3. Uji Hausman (REM vs FEM -> jika p-value < 0.05 pilih FEM)
plm::phtest(fem, rem)
##
## Hausman Test
##
## data: Y ~ X1 + X2 + X3
## chisq = 0.8314, df = 3, p-value = 0.8419
## alternative hypothesis: one model is inconsistent
# 4. Uji Lagrange Multiplier / Breusch-Pagan (CEM vs REM -> jika p-value < 0.05 pilih REM)
plm::plmtest(cem, type = "bp")
##
## Lagrange Multiplier Test - (Breusch-Pagan)
##
## data: Y ~ X1 + X2 + X3
## chisq = 1529.9, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
Uji Diagnostik
Panel: Heterogenitas, Cross-Sectional Dependence, &
Autokorelasi
library(plm)
library(lmtest)
# Tentukan model panel terbaik hasil seleksi di atas (ganti fem jika cem/rem terpilih)
model_panel_terbaik <- fem
# 1. Uji Heterogenitas Koefisien/Slope Antarwilayah (Poolability Test)
# Catatan: Membutuhkan jumlah periode waktu (T) > jumlah variabel + 1 per wilayah.
# H0: Slope homogen antarwilayah | Tolak H0 jika p-value < 0.05
plm::pooltest(Y ~ X1 + X2 + X3, data = pdata, model = "within")
##
## F statistic
##
## data: Y ~ X1 + X2 + X3
## F = 3.8242, df1 = 27, df2 = 160, p-value = 5.301e-08
## alternative hypothesis: unstability
# 2. Uji Heteroskedastisitas Lintas Unit (Breusch-Pagan pada spesifikasi Fixed Effect / LSDV)
# H0: Homoskedastisitas | Tolak H0 jika p-value < 0.05
lmtest::bptest(Y ~ X1 + X2 + X3 + factor(Wilayah), data = data_panel_clean, studentize = FALSE)
##
## Breusch-Pagan test
##
## data: Y ~ X1 + X2 + X3 + factor(Wilayah)
## BP = 756.84, df = 12, p-value < 2.2e-16
# 3. Uji Cross-Sectional Dependence (Pesaran CD Test)
# H0: Tidak ada ketergantungan lintas wilayah | Tolak H0 jika p-value < 0.05
plm::pcdtest(model_panel_terbaik, test = "cd")
##
## Pesaran CD test for cross-sectional dependence in panels
##
## data: Y ~ X1 + X2 + X3
## z = 0.69051, p-value = 0.4899
## alternative hypothesis: cross-sectional dependence
# 4. Uji Autokorelasi Serial (Breusch-Godfrey / Wooldridge Test)
# H0: Tidak ada autokorelasi serial | Tolak H0 jika p-value < 0.05
plm::pbgtest(model_panel_terbaik)
##
## Breusch-Godfrey/Wooldridge test for serial correlation in panel models
##
## data: Y ~ X1 + X2 + X3
## chisq = 156.99, df = 20, p-value < 2.2e-16
## alternative hypothesis: serial correlation in idiosyncratic errors
Hasil Uji Utama Data
Panel
library(plm)
library(lmtest)
# Output standar model panel terpilih
summary(model_panel_terbaik)
## Oneway (individual) effect Within Model
##
## Call:
## plm::plm(formula = Y ~ X1 + X2 + X3, data = pdata, model = "within")
##
## Balanced Panel: n = 10, T = 20, N = 200
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -4551.5 -385.0 24.5 393.4 8983.8
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## X1 822.77198 126.41816 6.5083 6.787e-10 ***
## X2 1.68062 0.45371 3.7042 0.0002791 ***
## X3 30.00077 26.39952 1.1364 0.2572378
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Total Sum of Squares: 607380000
## Residual Sum of Squares: 326740000
## R-Squared: 0.46205
## Adj. R-Squared: 0.42753
## F-statistic: 53.5383 on 3 and 187 DF, p-value: < 2.22e-16
# Jika ditemukan heteroskedastisitas, autokorelasi, atau cross-sectional dependence,
# interpretasikan hasil dengan Driscoll-Kraay Robust Standard Errors (vcovSCC):
lmtest::coeftest(model_panel_terbaik, vcov. = plm::vcovSCC(model_panel_terbaik, type = "HC1"))
##
## t test of coefficients:
##
## Estimate Std. Error t value Pr(>|t|)
## X1 822.77198 288.25298 2.8543 0.004799 **
## X2 1.68062 0.74067 2.2690 0.024408 *
## X3 30.00077 43.83159 0.6845 0.494535
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Analisis Error
Correction Model (ECM)
Analisis Deskriptif
& Uji Derajat Integrasi (Stasioneritas)
library(dplyr)
library(tidyr)
library(psych)
library(tseries)
library(knitr)
# Pastikan wilayah_pilihan sudah terdefinisi (default: "Indonesia")
if (!exists("wilayah_pilihan")) {
wilayah_pilihan <- "Indonesia"
}
# Siapkan data bersih tanpa NA dari wilayah pilihan
data_ecm <- data_panel |>
dplyr::filter(Wilayah == wilayah_pilihan) |>
dplyr::arrange(Tahun) |>
dplyr::select(Tahun, Y, X1, X2, X3) |>
tidyr::drop_na()
# Statistik deskriptif
desc_ecm <- psych::describe(data_ecm[, c("Y", "X1", "X2", "X3")])[, c("n", "mean", "sd", "min", "max")]
knitr::kable(desc_ecm, digits = 3, caption = paste("Statistik Deskriptif Variabel ECM -", wilayah_pilihan))
Statistik Deskriptif Variabel ECM - Indonesia
| Y |
20 |
3218.942 |
681.081 |
2155.448 |
4367.947 |
| X1 |
20 |
2.045 |
0.367 |
1.571 |
2.865 |
| X2 |
20 |
763.533 |
127.576 |
628.601 |
1019.844 |
| X3 |
20 |
42.365 |
3.270 |
38.238 |
48.061 |
# 1. Uji ADF pada tingkat Level (harapan: tidak stasioner / p-value > 0.05)
tseries::adf.test(data_ecm$Y)
##
## Augmented Dickey-Fuller Test
##
## data: data_ecm$Y
## Dickey-Fuller = -2.7768, Lag order = 2, p-value = 0.2764
## alternative hypothesis: stationary
tseries::adf.test(data_ecm$X1)
##
## Augmented Dickey-Fuller Test
##
## data: data_ecm$X1
## Dickey-Fuller = 0.16049, Lag order = 2, p-value = 0.99
## alternative hypothesis: stationary
tseries::adf.test(data_ecm$X2)
##
## Augmented Dickey-Fuller Test
##
## data: data_ecm$X2
## Dickey-Fuller = 0.22047, Lag order = 2, p-value = 0.99
## alternative hypothesis: stationary
tseries::adf.test(data_ecm$X3)
##
## Augmented Dickey-Fuller Test
##
## data: data_ecm$X3
## Dickey-Fuller = -0.89209, Lag order = 2, p-value = 0.9365
## alternative hypothesis: stationary
# 2. Uji ADF pada tingkat First Difference (harapan: stasioner di I(1) / p-value < 0.05)
tseries::adf.test(diff(data_ecm$Y))
##
## Augmented Dickey-Fuller Test
##
## data: diff(data_ecm$Y)
## Dickey-Fuller = -2.6316, Lag order = 2, p-value = 0.3318
## alternative hypothesis: stationary
tseries::adf.test(diff(data_ecm$X1))
##
## Augmented Dickey-Fuller Test
##
## data: diff(data_ecm$X1)
## Dickey-Fuller = -1.8595, Lag order = 2, p-value = 0.6259
## alternative hypothesis: stationary
tseries::adf.test(diff(data_ecm$X2))
##
## Augmented Dickey-Fuller Test
##
## data: diff(data_ecm$X2)
## Dickey-Fuller = -2.9478, Lag order = 2, p-value = 0.2113
## alternative hypothesis: stationary
tseries::adf.test(diff(data_ecm$X3))
##
## Augmented Dickey-Fuller Test
##
## data: diff(data_ecm$X3)
## Dickey-Fuller = -3.6779, Lag order = 2, p-value = 0.04443
## alternative hypothesis: stationary
Uji Kointegrasi
Engle-Granger & Estimasi Jangka Panjang
library(urca)
library(tseries)
# 1. Estimasi Regresi Keseimbangan Jangka Panjang (pada tingkat Level)
model_jangka_panjang <- stats::lm(Y ~ X1 + X2 + X3, data = data_ecm)
summary(model_jangka_panjang)
##
## Call:
## stats::lm(formula = Y ~ X1 + X2 + X3, data = data_ecm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -209.59 -52.28 14.67 72.42 206.46
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4360.6938 663.8528 6.569 6.46e-06 ***
## X1 480.3794 266.2439 1.804 0.0900 .
## X2 2.0852 0.7677 2.716 0.0153 *
## X3 -87.7232 11.5140 -7.619 1.04e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 115.8 on 16 degrees of freedom
## Multiple R-squared: 0.9757, Adjusted R-squared: 0.9711
## F-statistic: 213.8 on 3 and 16 DF, p-value: 4.061e-13
# 2. Simpan residual (ECT) ke dalam dataframe
data_ecm$ECT <- stats::residuals(model_jangka_panjang)
# 3. Uji Kointegrasi Engle-Granger (uji stasioneritas residual pada Level)
# Menggunakan ur.df tanpa konstanta & tren (type = "none")
uji_koint_urdf <- urca::ur.df(data_ecm$ECT, type = "none", lags = 1)
summary(uji_koint_urdf)
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -164.50 -28.21 46.22 62.19 156.33
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 -1.1190 0.2366 -4.730 0.000226 ***
## z.diff.lag 0.4584 0.1884 2.434 0.027030 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 82.66 on 16 degrees of freedom
## Multiple R-squared: 0.5832, Adjusted R-squared: 0.531
## F-statistic: 11.19 on 2 and 16 DF, p-value: 0.0009116
##
##
## Value of test-statistic is: -4.7303
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.66 -1.95 -1.6
# Pembanding dengan fungsi adf.test standar
tseries::adf.test(data_ecm$ECT)
##
## Augmented Dickey-Fuller Test
##
## data: data_ecm$ECT
## Dickey-Fuller = -4.2123, Lag order = 2, p-value = 0.01585
## alternative hypothesis: stationary
Estimasi Model
Jangka Pendek (ECM) & Uji Asumsi Klasik
library(dplyr)
library(tidyr)
library(tseries)
library(lmtest)
library(car)
# Membentuk variabel first difference (Delta) dan lag residual (ECT_{t-1})
# Menggunakan dplyr::lag secara eksplisit agar tidak bentrok dengan plm::lag
df_ecm <- data_ecm |>
dplyr::mutate(
dY = c(NA, diff(Y)),
dX1 = c(NA, diff(X1)),
dX2 = c(NA, diff(X2)),
dX3 = c(NA, diff(X3)),
ECT_lag1 = dplyr::lag(ECT, 1)
) |>
tidyr::drop_na()
# 1. Estimasi Persamaan Jangka Pendek (ECM)
model_ecm <- stats::lm(dY ~ dX1 + dX2 + dX3 + ECT_lag1, data = df_ecm)
# 2. Uji Asumsi Klasik pada Model ECM
tseries::jarque.bera.test(stats::residuals(model_ecm)) # Normalitas
##
## Jarque Bera Test
##
## data: stats::residuals(model_ecm)
## X-squared = 21.862, df = 2, p-value = 1.79e-05
lmtest::bgtest(model_ecm) # Autokorelasi (Breusch-Godfrey)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: model_ecm
## LM test = 0.087261, df = 1, p-value = 0.7677
lmtest::bptest(model_ecm) # Heteroskedastisitas (Breusch-Pagan)
##
## studentized Breusch-Pagan test
##
## data: model_ecm
## BP = 6.9961, df = 4, p-value = 0.1361
car::vif(model_ecm) # Multikolinearitas
## dX1 dX2 dX3 ECT_lag1
## 1.403365 2.945968 2.721958 2.761942
# 3. Hasil Uji Utama Model ECM
summary(model_ecm)
##
## Call:
## stats::lm(formula = dY ~ dX1 + dX2 + dX3 + ECT_lag1, data = df_ecm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -151.496 -21.907 2.216 27.508 70.760
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 87.34116 22.94570 3.806 0.00193 **
## dX1 315.07623 121.80132 2.587 0.02152 *
## dX2 0.24376 0.89931 0.271 0.79030
## dX3 -7.51183 14.02731 -0.536 0.60070
## ECT_lag1 -0.05041 0.19028 -0.265 0.79493
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 52.74 on 14 degrees of freedom
## Multiple R-squared: 0.4152, Adjusted R-squared: 0.2482
## F-statistic: 2.485 on 4 and 14 DF, p-value: 0.09134