suppressPackageStartupMessages({
library(sf)
library(sp)
library(readxl)
library(openxlsx)
library(tidyverse)
library(spdep)
library(spatialreg)
library(MuMIn)
library(patchwork)
library(corrplot)
library(DescTools)
library(nortest)
library(car)
library(lmtest)
library(RColorBrewer)
})
shp_china <- st_read(path_shp_china)
## Reading layer `China29' from data source
## `/Users/intanaisa/Documents/Kuliah/Semester 5/Regresi Spasial/Praktikum/Data Regspas Praktikum 10/CHINA/China29/China29.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 29 features and 12 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 73.5577 ymin: 20.22264 xmax: 134.7739 ymax: 53.56086
## Geodetic CRS: WGS 84
data_china <- read_excel(path_xlsx_china)
china_join <- shp_china %>%
left_join(data_china, by = c("NAME_1" = "Region"))
head(china_join)
Data spasial dan data GRP tergabung lewat nama provinsi; pastikan tidak ada NA hasil join.
GRP <- ggplot(data = china_join) +
geom_sf(aes(fill = GRP), color = "white", linewidth = 0.2) +
scale_fill_viridis_c(option = "magma", name = "GRP") +
labs(title = "Gross Regional Product", subtitle = "Data kontinu per provinsi",
x = "Longitude", y = "Latitude") +
theme_minimal() +
theme(legend.position = "bottom",
plot.title = element_text(face = "bold", size = 14),
plot.subtitle = element_text(size = 11))
Urbanization <- ggplot(data = china_join) +
geom_sf(aes(fill = `Level_of_Urbanization`), color = "white", linewidth = 0.2) +
scale_fill_viridis_c(option = "magma", name = "Level of Urbanization") +
labs(title = "Level of Urbanization", subtitle = "Data kontinu per provinsi",
x = "Longitude", y = "Latitude") +
theme_minimal() +
theme(legend.position = "bottom",
plot.title = element_text(face = "bold", size = 14),
plot.subtitle = element_text(size = 11))
GRP | Urbanization
Provinsi dengan GRP tinggi cenderung juga memiliki urbanisasi tinggi dan berkelompok, indikasi awal hubungan positif dan pola spasial.
str(china_join)
## Classes 'sf' and 'data.frame': 29 obs. of 17 variables:
## $ ID_0 : chr "49" "49" "49" "49" ...
## $ ISO : chr "CHN" "CHN" "CHN" "CHN" ...
## $ NAME_0 : chr "China" "China" "China" "China" ...
## $ ID_1 : chr "1" "2" "3" "4" ...
## $ NAME_1 : chr "Anhui" "Beijing" "Chongqing" "Fujian" ...
## $ HASC_1 : chr "CN.AH" "CN.BJ" "CN.CQ" "CN.FJ" ...
## $ CCN_1 : chr "0" "0" "0" "0" ...
## $ CCA_1 : chr NA NA NA NA ...
## $ TYPE_1 : chr "Sh?ng" "ZhÃxiáshì" "ZhÃxiáshì" "Sh?ng" ...
## $ ENGTYPE_1 : chr "Province" "Municipality" "Municipality" "Province" ...
## $ NL_NAME_1 : chr "??|??" "??|??" "??|??" "??" ...
## $ VARNAME_1 : chr "?nhu?" "B?ij?ng" "Chóngqìng" "Fújià n" ...
## $ Long : num 117 116 108 118 101 ...
## $ Lat : num 31.8 40.2 30.1 26.1 37.8 ...
## $ GRP : num 28792 87475 38914 52763 21978 ...
## $ Level_of_Urbanization: num 46.5 86.2 57 59.6 38.8 ...
## $ geometry :sfc_MULTIPOLYGON of length 29; first list element: List of 1
## ..$ :List of 1
## .. ..$ : num [1:7291, 1:2] 116 116 116 116 116 ...
## ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
## ..- attr(*, "names")= chr [1:16] "ID_0" "ISO" "NAME_0" "ID_1" ...
colSums(is.na(china_join))
## ID_0 ISO NAME_0
## 0 0 0
## ID_1 NAME_1 HASC_1
## 0 0 0
## CCN_1 CCA_1 TYPE_1
## 0 29 0
## ENGTYPE_1 NL_NAME_1 VARNAME_1
## 0 0 0
## Long Lat GRP
## 0 0 0
## Level_of_Urbanization geometry
## 0 0
Bila ada kolom dengan jumlah NA > 0, perlu ditangani sebelum pemodelan.
china.lm <- lm(GRP ~ Level_of_Urbanization, data = china_join)
summary(china.lm)
##
## Call:
## lm(formula = GRP ~ Level_of_Urbanization, data = china_join)
##
## Residuals:
## Min 1Q Median 3Q Max
## -12050.9 -4410.4 -374.8 2961.6 14948.1
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -31895.5 5197.6 -6.137 1.48e-06 ***
## Level_of_Urbanization 1400.0 92.6 15.118 1.06e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6595 on 27 degrees of freedom
## Multiple R-squared: 0.8944, Adjusted R-squared: 0.8904
## F-statistic: 228.6 on 1 and 27 DF, p-value: 1.064e-14
Bila koefisien Level_of_Urbanization signifikan (p < 0,05), urbanisasi berpengaruh terhadap GRP dengan arah sesuai tandanya; R² menunjukkan proporsi keragaman GRP yang dijelaskan.
rail <- read_excel(path_xlsx_china, sheet = "Railway Distance", skip = 1)
rail_matrix <- as.matrix(rail[, 3:31])
rownames(rail_matrix) <- colnames(rail_matrix)
# Inverse distance, diagonal = 0
W_rail <- 1 / rail_matrix
diag(W_rail) <- 0
# Row-standardize
W_rail_std <- W_rail / rowSums(W_rail)
W <- mat2listw(W_rail_std, style = "W")
Bobot invers jarak kereta api, distandarisasi baris: provinsi yang lebih dekat memiliki bobot lebih besar.
col.moran <- lm.morantest(china.lm, W)
col.moran
##
## Global Moran I for regression residuals
##
## data:
## model: lm(formula = GRP ~ Level_of_Urbanization, data = china_join)
## weights: W
##
## Moran I statistic standard deviate = 1.1234, p-value = 0.1306
## alternative hypothesis: greater
## sample estimates:
## Observed Moran I Expectation Variance
## 0.010629595 -0.033552435 0.001546711
p-value < 0,05 berarti sisaan OLS berautokorelasi spasial sehingga perlu model spasial; bila tidak signifikan, OLS sudah cukup.
china.lagrange1 <- lm.LMtests(china.lm, W,
test = c("LMerr", "RLMerr", "LMlag", "RLMlag", "SARMA"))
summary(china.lagrange1)
## Rao's score (a.k.a Lagrange multiplier) diagnostics for spatial
## dependence
## data:
## model: lm(formula = GRP ~ Level_of_Urbanization, data = china_join)
## test weights: listw
##
## statistic parameter p.value
## RSerr 0.0277967 1 0.8676
## adjRSerr 0.0726855 1 0.7875
## RSlag 0.0035418 1 0.9525
## adjRSlag 0.0484307 1 0.8258
## SARMA 0.0762273 2 0.9626
LMerr signifikan mengarah ke SEM, LMlag ke SAR; bila keduanya signifikan, pilih berdasarkan versi robust (RLMerr/RLMlag). SARMA signifikan menandakan dependensi gabungan.
china.SLX <- lmSLX(GRP ~ Level_of_Urbanization, data = china_join,
listw = W, Durbin = TRUE)
summary(china.SLX)
##
## Call:
## lm(formula = formula(paste("y ~ ", paste(colnames(x)[-1], collapse = "+"))),
## data = as.data.frame(x), weights = weights)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.335e+04 4.130e+04 -5.654e-01 5.766e-01
## Level_of_Urbanization 1.387e+03 1.139e+02 1.217e+01 3.074e-12
## lag.Level_of_Urbanization -1.418e+02 6.801e+02 -2.086e-01 8.364e-01
Koefisien lag.Level_of_Urbanization yang signifikan menunjukkan pengaruh urbanisasi provinsi tetangga terhadap GRP (efek spillover).
logLik(china.SLX)
## 'log Lik.' -295.1173 (df=4)
logLik(china.lm)
## 'log Lik.' -295.1415 (df=3)
LR <- 2 * (as.numeric(logLik(china.SLX)) - as.numeric(logLik(china.lm)))
df_lr <- attr(logLik(china.SLX), "df") - attr(logLik(china.lm), "df")
pchisq(LR, df = df_lr, lower.tail = FALSE)
## [1] 0.8257453
AICc(china.lm)
## [1] 597.2431
AICc(china.SLX)
## [1] 599.9012
p-value LR < 0,05 berarti SLX lebih baik daripada OLS; AICc yang lebih kecil juga menunjukkan model lebih baik.
shp_jabar <- st_read(path_shp_jabar)
## Reading layer `Jabar2' from data source
## `/Users/intanaisa/Documents/Kuliah/Semester 5/Regresi Spasial/Praktikum/Data Regspas Praktikum 10/JABAR/Jabar2/Jabar2.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 26 features and 7 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 106.3705 ymin: -7.823398 xmax: 108.8338 ymax: -5.91377
## CRS: NA
data_jabar <- read_excel(path_xlsx_jabar)
data_jabar$KABKOTNO <- as.character(data_jabar$KABKOTNO)
jabar <- shp_jabar %>%
left_join(data_jabar, by = "KABKOTNO") %>%
na.omit()
colnames(jabar)
## [1] "PROVNO.x" "KABKOTNO" "KODE2010.x" "PROVINSI.x" "KABKOT.x"
## [6] "SUMBER" "IDSP2010.x" "PROVNO.y" "KODE2010.y" "PROVINSI.y"
## [11] "KABKOT.y" "IDSP2010.y" "Long" "Lat" "p.miskin15"
## [16] "p.miskin16" "j.miskin15" "j.miskin16" "AHH2015" "AHH2016"
## [21] "EYS2015" "EYS2016" "MYS2015" "MYS2016" "EXP2015"
## [26] "EXP2016" "APM.SD15" "APM.SMP15" "APM.SMA15" "APM.PT15"
## [31] "APK.SD15" "APK.SMP15" "APK.SMA15" "APK.PT15" "APS.USIA15"
## [36] "APS.USIA2" "APS.USIA3" "APS.USIA4" "geometry"
Data spasial dan data sosial-ekonomi tergabung lewat KABKOTNO; baris NA dibuang, jadi cek jumlah kab/kota yang tersisa.
plot(jabar[, c("p.miskin15", "AHH2015", "EYS2015", "MYS2015", "EXP2015",
"APM.SD15", "APM.SMP15", "APM.SMA15", "APM.PT15",
"APK.SD15", "APK.SMP15", "APK.SMA15", "APK.PT15",
"APS.USIA15", "APS.USIA2", "APS.USIA3", "APS.USIA4")],
max.plot = 17)
Peta tematik menunjukkan variasi antarwilayah; warna serupa yang berkelompok mengindikasikan pola spasial.
nb_jabar <- suppressWarnings(poly2nb(jabar))
lw_jabar <- nb2listw(nb_jabar, style = "W", zero.policy = TRUE)
Ketetanggaan queen contiguity dengan bobot standarisasi baris; wilayah tanpa tetangga ditangani oleh zero.policy.
Loop kombinasi cukup lama, hasilnya di-cache.
variabel_list <- c("p.miskin15", "AHH2015", "EYS2015", "MYS2015", "EXP2015",
"APM.SD15", "APM.SMP15", "APM.SMA15", "APM.PT15",
"APK.SD15", "APK.SMP15", "APK.SMA15", "APK.PT15",
"APS.USIA15", "APS.USIA2", "APS.USIA3", "APS.USIA4")
variabel_Y <- "p.miskin15"
variabel_X <- setdiff(variabel_list, variabel_Y)
hasil_model <- data.frame(Formula = character(), Jumlah_X = numeric(),
Moran_I = numeric(), P_Value = numeric(),
stringsAsFactors = FALSE)
maksimum_X <- 6
for (k in 1:maksimum_X) {
kombinasi_x <- combn(variabel_X, k, simplify = FALSE)
for (x_set in kombinasi_x) {
tryCatch({
formula_text <- paste(variabel_Y, "~", paste(x_set, collapse = " + "))
rumus <- as.formula(formula_text)
model_ols <- lm(rumus, data = jabar)
uji_moran <- lm.morantest(model_ols, lw_jabar, zero.policy = TRUE)
moran_i <- as.numeric(uji_moran$estimate["Observed Moran I"])
p_val <- uji_moran$p.value
if (p_val < 0.05) {
hasil_model <- rbind(hasil_model,
data.frame(Formula = formula_text, Jumlah_X = k,
Moran_I = moran_i, P_Value = p_val))
}
}, error = function(e) NULL)
}
}
hasil_model <- hasil_model %>% arrange(P_Value)
Hanya kombinasi X dengan Moran’s I sisaan signifikan yang disimpan, artinya OLS-nya masih menyisakan dependensi spasial sehingga layak dilanjutkan ke model spasial.
if (nrow(hasil_model) == 0) {
cat("Tidak ada model signifikan.\n")
} else {
model_terbaik <- hasil_model %>% slice(1)
cat("Formula : ", as.character(model_terbaik$Formula), "\n", sep = "")
cat("Jumlah Variabel X : ", model_terbaik$Jumlah_X, "\n", sep = "")
cat("Moran's I : ", round(model_terbaik$Moran_I, 5), "\n", sep = "")
cat("P-Value : ", format(model_terbaik$P_Value, scientific = FALSE), "\n", sep = "")
}
## Formula : p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 + APK.PT15 + APS.USIA15
## Jumlah Variabel X : 5
## Moran's I : 0.5012
## P-Value : 0.005018003
Kombinasi dengan p-value Moran terkecil dipilih; Moran’s I positif berarti sisaan wilayah berdekatan cenderung mirip.
jabar.lm <- lm(p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 + APK.PT15 + APS.USIA15,
data = jabar)
summary(jabar.lm)
##
## Call:
## lm(formula = p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 + APK.PT15 +
## APS.USIA15, data = jabar)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.2541 -1.5129 0.7468 1.7253 2.9766
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -263.5186 236.1804 -1.116 0.2883
## EYS2015 2.7220 2.1113 1.289 0.2238
## APM.SD15 -0.5289 0.6939 -0.762 0.4619
## APK.SD15 0.4526 0.2946 1.536 0.1527
## APK.PT15 -0.3228 0.1731 -1.865 0.0891 .
## APS.USIA15 2.4849 2.5164 0.987 0.3446
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.114 on 11 degrees of freedom
## Multiple R-squared: 0.5749, Adjusted R-squared: 0.3816
## F-statistic: 2.975 on 5 and 11 DF, p-value: 0.06127
Variabel dengan p < 0,05 berpengaruh signifikan terhadap persentase penduduk miskin; Adjusted R² menunjukkan kemampuan model dan uji F kelayakan model secara simultan.
jabar.lagrange <- lm.LMtests(jabar.lm, lw_jabar,
test = c("LMerr", "RLMerr", "LMlag", "RLMlag", "SARMA"))
summary(jabar.lagrange)
## Rao's score (a.k.a Lagrange multiplier) diagnostics for spatial
## dependence
## data:
## model: lm(formula = p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 +
## APK.PT15 + APS.USIA15, data = jabar)
## test weights: listw
##
## statistic parameter p.value
## RSerr 7.23955 1 0.007132 **
## adjRSerr 5.48939 1 0.019132 *
## RSlag 2.01129 1 0.156133
## adjRSlag 0.26113 1 0.609346
## SARMA 7.50067 2 0.023510 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
LMerr/RLMerr signifikan mengarah ke SEM, LMlag/RLMlag ke SAR, dan SARMA signifikan ke dependensi gabungan.
jabar.err <- errorsarlm(p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 + APK.PT15 + APS.USIA15,
lw_jabar, data = jabar, zero.policy = TRUE)
summary(jabar.err)
##
## Call:errorsarlm(formula = p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 +
## APK.PT15 + APS.USIA15, data = jabar, listw = lw_jabar, zero.policy = TRUE)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.96720 -0.97705 0.17825 0.76731 1.45103
##
## Type: error
## Regions with no neighbours included:
## 18 19 21 25 26
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -425.458865 84.564211 -5.0312 4.874e-07
## EYS2015 4.311729 1.035451 4.1641 3.126e-05
## APM.SD15 -1.521207 0.226462 -6.7173 1.852e-11
## APK.SD15 0.640932 0.101930 6.2880 3.216e-10
## APK.PT15 -0.358322 0.069408 -5.1626 2.436e-07
## APS.USIA15 4.680477 0.828208 5.6513 1.592e-08
##
## Lambda: 0.9059, LR test value: 23.088, p-value: 1.5476e-06
## Asymptotic standard error: 0.060606
## z-value: 14.947, p-value: < 2.22e-16
## Wald statistic: 223.43, p-value: < 2.22e-16
##
## Log likelihood: -28.18863 for error model
## ML residual variance (sigma squared): 1.0473, (sigma: 1.0234)
## Number of observations: 17
## Number of parameters estimated: 8
## AIC: 72.377, (AIC for lm: 93.465)
Lambda signifikan menandakan dependensi spasial pada galat; koefisien X dibaca seperti regresi biasa setelah mengontrol dependensi tersebut.
jabar.SLX <- lmSLX(p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 + APK.PT15 + APS.USIA15,
lw_jabar, data = jabar, zero.policy = TRUE, Durbin = TRUE)
summary(jabar.SLX)
##
## Call:
## lm(formula = formula(paste("y ~ ", paste(colnames(x)[-1], collapse = "+"))),
## data = as.data.frame(x), weights = weights)
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -145.59982 307.35728 -0.47372 0.65245
## EYS2015 2.63817 4.59362 0.57431 0.58663
## APM.SD15 0.26488 0.97666 0.27122 0.79532
## APK.SD15 0.59059 0.23882 2.47293 0.04827
## APK.PT15 -0.20577 0.38277 -0.53759 0.61021
## APS.USIA15 0.36388 3.17195 0.11472 0.91241
## lag.EYS2015 -4.02200 9.31944 -0.43157 0.68113
## lag.APM.SD15 3.42980 1.21392 2.82538 0.03014
## lag.APK.SD15 -0.41090 0.69159 -0.59414 0.57412
## lag.APK.PT15 0.38003 0.82137 0.46268 0.65990
## lag.APS.USIA15 -2.48727 1.03245 -2.40910 0.05264
Koefisien lag.X yang signifikan menunjukkan pengaruh variabel penjelas wilayah tetangga terhadap kemiskinan wilayah ini.
jabar.sarma <- sacsarlm(p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 + APK.PT15 + APS.USIA15,
lw_jabar, data = jabar, zero.policy = TRUE)
summary(jabar.sarma)
##
## Call:sacsarlm(formula = p.miskin15 ~ EYS2015 + APM.SD15 + APK.SD15 +
## APK.PT15 + APS.USIA15, data = jabar, listw = lw_jabar, zero.policy = TRUE)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.837342 -0.900247 -0.050073 0.685523 1.606525
##
## Type: sac
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -442.074285 83.148799 -5.3167 1.057e-07
## EYS2015 4.793132 1.140231 4.2037 2.626e-05
## APM.SD15 -1.707710 0.293038 -5.8276 5.623e-09
## APK.SD15 0.672837 0.103147 6.5231 6.886e-11
## APK.PT15 -0.392055 0.076727 -5.1097 3.226e-07
## APS.USIA15 4.939024 0.838588 5.8897 3.869e-09
##
## Rho: 0.20377
## Asymptotic standard error: 0.19972
## z-value: 1.0202, p-value: 0.30761
## Lambda: 0.91256
## Asymptotic standard error: 0.065071
## z-value: 14.024, p-value: < 2.22e-16
##
## LR test value: 23.918, p-value: 6.4015e-06
##
## Log likelihood: -27.77358 for sac model
## ML residual variance (sigma squared): 0.97176, (sigma: 0.98578)
## Number of observations: 17
## Number of parameters estimated: 9
## AIC: 73.547, (AIC for lm: 93.465)
Rho dan lambda yang signifikan menunjukkan dependensi spasial pada respon sekaligus galat.
anova(jabar.err, jabar.sarma)
p-value < 0,05 berarti SARMA lebih baik daripada SEM; bila tidak signifikan, SEM yang lebih sederhana sudah cukup.
AICc(jabar.lm)
## [1] 105.9096
AICc(jabar.err)
## [1] 90.37725
AICc(jabar.sarma)
## [1] 99.26145
Model dengan AICc terkecil adalah yang terbaik di antara OLS, SEM, dan SARMA.
data <- read.csv(path_csv_jawa)
head(data)
dim(data)
## [1] 119 8
Data terbaca; dim() menunjukkan jumlah kabupaten/kota dan jumlah peubah.
peta <- st_read(dsn = dir_peta_jawa, layer = "jawa")
## Reading layer `jawa' from data source
## `/Users/intanaisa/Documents/Kuliah/Semester 5/Regresi Spasial/Praktikum/Data Regspas Praktikum 10/Dataset 06/Jawamap/jawa.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 119 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 105.0998 ymin: -8.78036 xmax: 116.2702 ymax: -5.048857
## Geodetic CRS: WGS 84
peta
plot(peta, main = "Peta Pulau Jawa")
plot(peta[4], main = "Peta Pulau Jawa (Kabupaten)")
Jumlah poligon peta harus sama dengan jumlah baris data dan urutannya sama, karena penggabungan nanti dilakukan berdasarkan urutan baris.
# Missing value
data[!complete.cases(data), ]
# Statistik deskriptif
summary(data[, -c(1, 2)])
## KAB long lat y
## Length :119 Min. :105.8 Min. :-8.365 Min. :13.72
## N.unique :100 1st Qu.:107.9 1st Qu.:-7.653 1st Qu.:22.07
## N.blank : 0 Median :110.2 Median :-7.258 Median :25.40
## Min.nchar: 4 Mean :110.0 Mean :-7.199 Mean :25.53
## Max.nchar: 17 3rd Qu.:111.8 3rd Qu.:-6.820 3rd Qu.:29.20
## Max. :114.2 Max. :-5.797 Max. :36.22
## x1 x2
## Min. : 80.10 Min. :25.10
## 1st Qu.: 87.25 1st Qu.:33.20
## Median : 92.20 Median :41.20
## Mean : 93.04 Mean :40.78
## 3rd Qu.: 99.85 3rd Qu.:49.25
## Max. :105.00 Max. :55.00
# Y tertinggi dan terendah
kab_max <- data %>% arrange(desc(y)) %>% slice(1)
print(paste("Kabupaten/kota dengan Y tertinggi adalah", kab_max$KAB))
## [1] "Kabupaten/kota dengan Y tertinggi adalah JAKARTA SELATAN"
kab_min <- data %>% arrange(y) %>% slice(1)
print(paste("Kabupaten/kota dengan Y terendah adalah", kab_min$KAB))
## [1] "Kabupaten/kota dengan Y terendah adalah KLATEN"
Tidak ada baris tercetak pada pengecekan missing value berarti data lengkap; ringkasan dan kabupaten/kota dengan Y tertinggi serta terendah menggambarkan rentang sebaran Y.
par(mfrow = c(1, 3))
boxplot(data$y, main = "Sebaran Y", col = "dodgerblue")
boxplot(data$x1, main = "Sebaran X1", col = "dodgerblue")
boxplot(data$x2, main = "Sebaran X2", col = "dodgerblue")
par(mfrow = c(1, 1))
Titik di luar whisker menandakan potensi pencilan pada peubah tersebut.
pairs(data[, 6:8], pch = 19, lower.panel = NULL)
Plot pasangan menunjukkan pola hubungan antarpeubah, apakah mendekati linier atau tidak.
corrplot(cor(data[, 6:8]), method = "number")
cor(data[, 4:7])
## long lat y x1
## long 1.00000000 -0.74541782 -0.1306153 -0.08974212
## lat -0.74541782 1.00000000 0.1679668 0.07479095
## y -0.13061532 0.16796681 1.0000000 0.80963262
## x1 -0.08974212 0.07479095 0.8096326 1.00000000
Korelasi mendekati ±1 berarti hubungan kuat; korelasi antar X yang sangat tinggi mengindikasikan potensi multikolinearitas.
cor.test(data$y, data$x1)
##
## Pearson's product-moment correlation
##
## data: data$y and data$x1
## t = 14.921, df = 117, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.7370471 0.8637532
## sample estimates:
## cor
## 0.8096326
cor.test(data$y, data$x2)
##
## Pearson's product-moment correlation
##
## data: data$y and data$x2
## t = 6.5822, df = 117, p-value = 1.374e-09
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3749256 0.6399554
## sample estimates:
## cor
## 0.5198398
p-value < 0,05 berarti Y berkorelasi signifikan dengan peubah tersebut.
k <- 101
colfunc <- colorRampPalette(c("green", "yellow", "red"))
peta$y <- data$y
peta$x1 <- data$x1
peta$x2 <- data$x2
ggplot(peta) +
geom_sf(aes(fill = y)) +
scale_fill_gradientn(colors = colfunc(k)) +
labs(title = "Peta Sebaran Spasial Peubah Respon Y") +
theme_minimal()
ggplot(peta) +
geom_sf(aes(fill = x1)) +
scale_fill_gradientn(colors = colfunc(k)) +
labs(title = "Sebaran Spasial Peubah Penjelas X1") +
theme_minimal()
ggplot(peta) +
geom_sf(aes(fill = x2)) +
scale_fill_gradientn(colors = colfunc(k)) +
labs(title = "Sebaran Spasial Peubah Penjelas X2") +
theme_minimal()
Wilayah berwarna serupa yang saling berdekatan mengindikasikan autokorelasi spasial positif.
peta <- st_make_valid(peta)
sp.peta <- as(peta, "Spatial")
sp.polygons <- SpatialPolygons(sp.peta@polygons)
queen <- poly2nb(sp.peta, queen = TRUE)
queen
## Neighbour list object:
## Number of regions: 119
## Number of nonzero links: 522
## Percentage nonzero weights: 3.68618
## Average number of links: 4.386555
## 1 region with no links:
## 1
## 3 disjoint connected subgraphs
W.queen <- nb2listw(queen, style = "W", zero.policy = TRUE)
qc <- moran.test(data$y, W.queen, randomisation = TRUE,
alternative = "greater", zero.policy = TRUE)
qc
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.queen
## n reduced by no-neighbour observations
##
## Moran I statistic standard deviate = 1.3921, p-value = 0.08195
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.085984133 -0.008547009 0.004611252
moran.mc(data$y, listw = W.queen, zero.policy = TRUE, nsim = 99)
##
## Monte-Carlo simulation of Moran I
##
## data: data$y
## weights: W.queen
## number of simulations + 1: 100
##
## statistic = 0.085984, observed rank = 94, p-value = 0.06
## alternative hypothesis: greater
Moran’s I positif dengan p < 0,05 berarti Y berautokorelasi spasial positif (wilayah berdekatan bernilai mirip); uji Monte Carlo menguatkan hasil ini.
rook <- poly2nb(sp.peta, queen = FALSE)
rook
## Neighbour list object:
## Number of regions: 119
## Number of nonzero links: 518
## Percentage nonzero weights: 3.657934
## Average number of links: 4.352941
## 1 region with no links:
## 1
## 3 disjoint connected subgraphs
W.rook <- nb2listw(rook, style = "W", zero.policy = TRUE)
rc <- moran.test(data$y, W.rook, randomisation = TRUE,
alternative = "greater", zero.policy = TRUE)
rc
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.rook
## n reduced by no-neighbour observations
##
## Moran I statistic standard deviate = 1.5987, p-value = 0.05495
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.100243070 -0.008547009 0.004630949
moran.mc(data$y, listw = W.rook, zero.policy = TRUE, nsim = 99)
##
## Monte-Carlo simulation of Moran I
##
## data: data$y
## weights: W.rook
## number of simulations + 1: 100
##
## statistic = 0.10024, observed rank = 94, p-value = 0.06
## alternative hypothesis: greater
Serupa Queen, tetapi ketetanggaan hanya lewat sisi bersama; bandingkan nilai Moran-nya dengan Queen.
centroids <- st_centroid(peta)
longlat <- st_coordinates(centroids)
peta$long <- longlat[, 1]
peta$lat <- longlat[, 2]
coords <- peta[c("long", "lat")]
koord <- as.data.frame(coords)
jarak <- dist(longlat, method = "euclidean")
m.jarak <- as.matrix(jarak)
Centroid dan matriks jarak Euclidean menjadi dasar matriks bobot berbasis jarak.
W.knn <- knn2nb(knearneigh(longlat, k = 5, longlat = TRUE))
W.knn.s <- nb2listw(W.knn, style = "W")
MI.knn <- moran(data$y, W.knn.s, n = length(W.knn.s$neighbours), S0 = Szero(W.knn.s))
mt1 <- moran.test(data$y, W.knn.s, randomisation = TRUE, alternative = "greater")
mt1
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.knn.s
##
## Moran I statistic standard deviate = 2.1802, p-value = 0.01462
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.107628130 -0.008474576 0.002835976
Setiap wilayah memiliki tepat 5 tetangga terdekat; Moran’s I signifikan berarti ada autokorelasi spasial Y menurut bobot ini.
W.rdw <- dnearneigh(longlat, 0, 105, longlat = TRUE)
W.rdw.s <- nb2listw(W.rdw, style = "W")
MI.rdw <- moran(data$y, W.rdw.s, n = length(W.rdw.s$neighbours), S0 = Szero(W.rdw.s))
mt2 <- moran.test(data$y, W.rdw.s, randomisation = TRUE, alternative = "greater")
mt2
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.rdw.s
##
## Moran I statistic standard deviate = 0.82869, p-value = 0.2036
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.0148447999 -0.0084745763 0.0007918598
Tetangga ditentukan berdasarkan radius 105 km; Moran’s I signifikan berarti ada autokorelasi spasial pada jarak tersebut.
# alpha = 1
alpha1 <- 1
W.idw <- 1 / (m.jarak^alpha1)
diag(W.idw) <- 0
rtot <- rowSums(W.idw, na.rm = TRUE)
W.idw.sd <- W.idw / rtot
W.idw.s <- mat2listw(W.idw.sd, style = "W")
MI.idw <- moran(data$y, W.idw.s, n = length(W.idw.s$neighbours), S0 = Szero(W.idw.s))
mt3 <- moran.test(data$y, W.idw.s, randomisation = TRUE, alternative = "greater")
mt3
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.idw.s
##
## Moran I statistic standard deviate = 2.3687, p-value = 0.008925
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.040533196 -0.008474576 0.000428063
# alpha = 2
alpha2 <- 2
W.idw2 <- 1 / (m.jarak^alpha2)
diag(W.idw2) <- 0
rtot <- rowSums(W.idw2, na.rm = TRUE)
W.idw2.sd <- W.idw2 / rtot
W.idw2.s <- mat2listw(W.idw2.sd, style = "W")
MI.idw2 <- moran(data$y, W.idw2.s, n = length(W.idw2.s$neighbours), S0 = Szero(W.idw2.s))
mt4 <- moran.test(data$y, W.idw2.s, randomisation = TRUE, alternative = "greater")
mt4
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.idw2.s
##
## Moran I statistic standard deviate = 1.9574, p-value = 0.02515
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.088273381 -0.008474576 0.002442892
Bobot mengecil seiring jarak; alpha = 2 menurunkan bobot lebih tajam sehingga lebih menekankan tetangga dekat.
# alpha = 1
alpha <- 1
W.edw <- exp((-alpha) * m.jarak)
diag(W.edw) <- 0
rtot <- rowSums(W.edw, na.rm = TRUE)
W.edw.sd <- W.edw / rtot
W.edw.s <- mat2listw(W.edw.sd, style = "W")
MI.edw <- moran(data$y, W.edw.s, n = length(W.edw.s$neighbours), S0 = Szero(W.edw.s))
mt5 <- moran.test(data$y, W.edw.s, randomisation = TRUE, alternative = "greater")
mt5
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.edw.s
##
## Moran I statistic standard deviate = 1.3022, p-value = 0.09643
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.0099060556 -0.0084745763 0.0001992396
# alpha = 2
alpha2 <- 2
W.edw2 <- exp((-alpha2) * m.jarak)
diag(W.edw2) <- 0
rtot <- rowSums(W.edw2, na.rm = TRUE)
W.edw2.sd <- W.edw2 / rtot
W.edw2.s <- mat2listw(W.edw2.sd, style = "W")
MI.edw2 <- moran(data$y, W.edw2.s, n = length(W.edw2.s$neighbours), S0 = Szero(W.edw2.s))
mt6 <- moran.test(data$y, W.edw2.s, randomisation = TRUE, alternative = "greater")
mt6
##
## Moran I test under randomisation
##
## data: data$y
## weights: W.edw2.s
##
## Moran I statistic standard deviate = 1.875, p-value = 0.03039
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.0328701345 -0.0084745763 0.0004862084
Bobot meluruh eksponensial terhadap jarak; alpha lebih besar berarti peluruhan lebih cepat.
MatriksBobot <- c("K-Nearest Neighbor (k=5)",
"Radial Distance Weight (dmax=105)",
"Invers Distance Weight (alpha=1)",
"Invers Distance Weight (alpha=2)",
"Exponential Distance Weight (alpha=1)",
"Exponential Distance Weight (alpha=2)",
"Rook Contiguity",
"Queen Contiguity")
IndeksMoran <- c(MI.knn$I, MI.rdw$I, MI.idw$I, MI.idw2$I, MI.edw$I, MI.edw2$I,
rc$estimate[1], qc$estimate[1])
pv <- c(mt1$p.value, mt2$p.value, mt3$p.value, mt4$p.value, mt5$p.value, mt6$p.value,
rc$p.value, qc$p.value)
Matriks <- cbind.data.frame(MatriksBobot, IndeksMoran, "p-value" = pv)
colnames(Matriks) <- c("Matriks Bobot", "Indeks Moran", "p-value")
Matriks
Matriks[Matriks$`p-value` < 0.05, ]
Matriks bobot dengan Indeks Moran terbesar dan p-value < 0,05 dipilih sebagai bobot terbaik. Bagian selanjutnya memakai KNN (ww <- W.knn.s), sesuaikan bila hasilnya menunjukkan bobot lain lebih baik.
ols <- lm(y ~ x1 + x2, data = data)
summary(ols)
##
## Call:
## lm(formula = y ~ x1 + x2, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.5977 -0.8358 0.0369 0.9222 3.5927
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -36.66154 1.72709 -21.23 <2e-16 ***
## x1 0.54223 0.01742 31.13 <2e-16 ***
## x2 0.28804 0.01447 19.90 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.392 on 116 degrees of freedom
## Multiple R-squared: 0.922, Adjusted R-squared: 0.9206
## F-statistic: 685.3 on 2 and 116 DF, p-value: < 2.2e-16
print(paste("Nilai AIC OLS", AIC(ols)))
## [1] "Nilai AIC OLS 421.320527312512"
Koefisien x1 dan x2 yang signifikan (p < 0,05) berpengaruh terhadap Y; Adjusted R² menunjukkan proporsi keragaman Y yang dijelaskan, dan AIC menjadi pembanding dengan model spasial.
# Normalitas
err.ols <- residuals(ols)
ad.test(err.ols)
##
## Anderson-Darling normality test
##
## data: err.ols
## A = 0.48312, p-value = 0.2255
hist(err.ols)
qqnorm(err.ols, datax = TRUE)
qqline(rnorm(length(err.ols), mean(err.ols), sd(err.ols)), datax = TRUE, col = "red")
# Homogenitas ragam
lmtest::bptest(ols)
##
## studentized Breusch-Pagan test
##
## data: ols
## BP = 1.557, df = 2, p-value = 0.4591
# Multikolinearitas
car::vif(ols)
## x1 x2
## 1.00002 1.00002
Normalitas terpenuhi bila p Anderson-Darling > 0,05, homogenitas ragam bila p Breusch-Pagan > 0,05, dan tidak ada multikolinearitas bila VIF < 10.
ww <- W.knn.s
# Galat OLS
lm.morantest(ols, listw = ww, alternative = "two.sided", zero.policy = TRUE)
##
## Global Moran I for regression residuals
##
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## weights: ww
##
## Moran I statistic standard deviate = 7.7062, p-value = 1.296e-14
## alternative hypothesis: two.sided
## sample estimates:
## Observed Moran I Expectation Variance
## 0.401296232 -0.008385587 0.002826244
err.ols <- residuals(ols)
merr <- moran.test(err.ols, ww, randomisation = TRUE, alternative = "two.sided")
merr
##
## Moran I test under randomisation
##
## data: err.ols
## weights: ww
##
## Moran I statistic standard deviate = 7.7459, p-value = 9.488e-15
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## 0.401296232 -0.008474576 0.002798555
# Y
my <- moran.test(data$y, ww, randomisation = TRUE, alternative = "two.sided")
my
##
## Moran I test under randomisation
##
## data: data$y
## weights: ww
##
## Moran I statistic standard deviate = 2.1802, p-value = 0.02924
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## 0.107628130 -0.008474576 0.002835976
# X1 dan X2
mx1 <- moran.test(data$x1, ww, randomisation = TRUE, alternative = "two.sided")
mx1
##
## Moran I test under randomisation
##
## data: data$x1
## weights: ww
##
## Moran I statistic standard deviate = 0.89468, p-value = 0.371
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## 0.039254520 -0.008474576 0.002846002
mx2 <- moran.test(data$x2, ww, randomisation = TRUE, alternative = "two.sided")
mx2
##
## Moran I test under randomisation
##
## data: data$x2
## weights: ww
##
## Moran I statistic standard deviate = -1.0874, p-value = 0.2768
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## -0.066483348 -0.008474576 0.002845675
Moran’s I sisaan yang signifikan berarti asumsi independensi galat dilanggar sehingga model spasial diperlukan; Moran’s I Y, X1, dan X2 menunjukkan pola spasial masing-masing peubah.
moran.plot(data$y, ww, labels = data$KAB)
Titik di kuadran HH dan LL menunjukkan pengelompokan nilai serupa (autokorelasi positif), sedangkan HL dan LH menunjukkan pencilan spasial.
Peubah <- c("Y", "X1", "X2", "Sisaan")
Indeks_Moran <- c(my$estimate[1], mx1$estimate[1], mx2$estimate[1], merr$estimate[1])
p_value <- c(my$p.value, mx1$p.value, mx2$p.value, merr$p.value)
df1 <- cbind.data.frame(Peubah, Indeks_Moran, p_value)
colnames(df1) <- c("Peubah", "Indeks Moran", "p-value")
df1
Peubah dengan p-value < 0,05 memiliki autokorelasi spasial; Indeks Moran positif berarti mengelompok, negatif berarti menyebar.
model_lm <- lm.LMtests(ols, listw = ww, zero.policy = TRUE,
test = c("LMerr", "RLMerr", "LMlag", "RLMlag", "SARMA"))
summary(model_lm)
## Rao's score (a.k.a Lagrange multiplier) diagnostics for spatial
## dependence
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## test weights: listw
##
## statistic parameter p.value
## RSerr 54.2452 1 1.770e-13 ***
## adjRSerr 31.9386 1 1.591e-08 ***
## RSlag 32.0571 1 1.497e-08 ***
## adjRSlag 9.7505 1 0.001793 **
## SARMA 63.9957 2 1.266e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
LMerr/RLMerr signifikan mengarah ke SEM, LMlag/RLMlag ke SAR, dan SARMA signifikan ke dependensi gabungan.
lmtest::bptest(ols)
##
## studentized Breusch-Pagan test
##
## data: ols
## BP = 1.557, df = 2, p-value = 0.4591
p-value < 0,05 berarti ragam galat tidak homogen (heterogenitas spasial), sehingga model seperti GWR layak dipertimbangkan.
sar <- lagsarlm(y ~ x1 + x2, data = data, listw = ww)
summary(sar, Nagelkerke = TRUE)
##
## Call:lagsarlm(formula = y ~ x1 + x2, data = data, listw = ww)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.278572 -0.761564 0.016699 0.849727 2.695114
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -41.792688 1.851270 -22.575 < 2.2e-16
## x1 0.532067 0.015553 34.209 < 2.2e-16
## x2 0.290320 0.012806 22.671 < 2.2e-16
##
## Rho: 0.23233, LR test value: 25.223, p-value: 5.1057e-07
## Asymptotic standard error: 0.047605
## z-value: 4.8803, p-value: 1.0593e-06
## Wald statistic: 23.817, p-value: 1.0593e-06
##
## Log likelihood: -194.0485 for lag model
## ML residual variance (sigma squared): 1.5135, (sigma: 1.2303)
## Nagelkerke pseudo-R-squared: 0.93687
## Number of observations: 119
## Number of parameters estimated: 5
## AIC: 398.1, (AIC for lm: 421.32)
## LM test for residual autocorrelation
## test value: 7.358, p-value: 0.0066764
err.sar <- residuals(sar)
ad.test(err.sar)
##
## Anderson-Darling normality test
##
## data: err.sar
## A = 0.28212, p-value = 0.6317
bptest.Sarlm(sar)
##
## studentized Breusch-Pagan test
##
## data:
## BP = 2.6875, df = 2, p-value = 0.2609
moran.test(err.sar, ww, alternative = "two.sided")
##
## Moran I test under randomisation
##
## data: err.sar
## weights: ww
##
## Moran I statistic standard deviate = 2.776, p-value = 0.005504
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## 0.138466721 -0.008474576 0.002801958
Rho signifikan berarti Y wilayah tetangga memengaruhi Y wilayah ini; uji sisaan memeriksa normalitas, homogenitas, dan ada tidaknya autokorelasi sisa.
sem <- errorsarlm(y ~ x1 + x2, data = data, listw = ww)
summary(sem)
##
## Call:errorsarlm(formula = y ~ x1 + x2, data = data, listw = ww)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.61465 -0.56031 0.16416 0.76534 2.46897
##
## Type: error
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -34.736068 1.427157 -24.339 < 2.2e-16
## x1 0.523408 0.014286 36.637 < 2.2e-16
## x2 0.283754 0.011367 24.963 < 2.2e-16
##
## Lambda: 0.57406, LR test value: 33.057, p-value: 8.9503e-09
## Asymptotic standard error: 0.093935
## z-value: 6.1113, p-value: 9.8842e-10
## Wald statistic: 37.348, p-value: 9.8842e-10
##
## Log likelihood: -190.1318 for error model
## ML residual variance (sigma squared): 1.3381, (sigma: 1.1568)
## Number of observations: 119
## Number of parameters estimated: 5
## AIC: 390.26, (AIC for lm: 421.32)
err.sem <- residuals(sem)
ad.test(err.sem)
##
## Anderson-Darling normality test
##
## data: err.sem
## A = 0.75876, p-value = 0.04711
bptest.Sarlm(sem)
##
## studentized Breusch-Pagan test
##
## data:
## BP = 0.89877, df = 2, p-value = 0.638
moran.test(err.sem, ww, alternative = "two.sided")
##
## Moran I test under randomisation
##
## data: err.sem
## weights: ww
##
## Moran I statistic standard deviate = -0.55031, p-value = 0.5821
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## -0.037483141 -0.008474576 0.002778668
Lambda signifikan menunjukkan dependensi spasial pada galat; model memadai bila sisaan tidak lagi berautokorelasi (Moran p > 0,05).
SARMA <- sacsarlm(y ~ x1 + x2, data = data, ww, zero.policy = TRUE)
summary(SARMA)
##
## Call:
## sacsarlm(formula = y ~ x1 + x2, data = data, listw = ww, zero.policy = TRUE)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.53574 -0.59853 0.10686 0.78564 2.55146
##
## Type: sac
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -37.670168 2.567539 -14.672 < 2.2e-16
## x1 0.530517 0.015036 35.282 < 2.2e-16
## x2 0.286556 0.011748 24.392 < 2.2e-16
##
## Rho: 0.083991
## Asymptotic standard error: 0.064873
## z-value: 1.2947, p-value: 0.19543
## Lambda: 0.47951
## Asymptotic standard error: 0.11669
## z-value: 4.1093, p-value: 3.9689e-05
##
## LR test value: 34.119, p-value: 3.9012e-08
##
## Log likelihood: -189.6009 for sac model
## ML residual variance (sigma squared): 1.3555, (sigma: 1.1642)
## Number of observations: 119
## Number of parameters estimated: 6
## AIC: 391.2, (AIC for lm: 421.32)
err.SARMA <- residuals(SARMA)
ad.test(err.SARMA)
##
## Anderson-Darling normality test
##
## data: err.SARMA
## A = 0.70442, p-value = 0.06428
bptest.Sarlm(SARMA)
##
## studentized Breusch-Pagan test
##
## data:
## BP = 1.2851, df = 2, p-value = 0.5259
moran.test(err.SARMA, ww, alternative = "two.sided")
##
## Moran I test under randomisation
##
## data: err.SARMA
## weights: ww
##
## Moran I statistic standard deviate = -0.36979, p-value = 0.7115
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## -0.027983676 -0.008474576 0.002783258
Rho dan lambda signifikan menunjukkan dependensi pada respon sekaligus galat.
sdm <- lagsarlm(y ~ x1 + x2, data = data, ww, zero.policy = TRUE, type = "mixed")
summary(sdm)
##
## Call:lagsarlm(formula = y ~ x1 + x2, data = data, listw = ww, type = "mixed",
## zero.policy = TRUE)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.460816 -0.587583 0.063713 0.803323 2.489449
##
## Type: mixed
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -23.011393 5.406184 -4.2565 2.077e-05
## x1 0.528068 0.014497 36.4268 < 2.2e-16
## x2 0.287681 0.012170 23.6394 < 2.2e-16
## lag.x1 -0.226018 0.064788 -3.4886 0.0004856
## lag.x2 -0.113673 0.045416 -2.5029 0.0123175
##
## Rho: 0.52166, LR test value: 25.205, p-value: 5.1548e-07
## Asymptotic standard error: 0.10037
## z-value: 5.1973, p-value: 2.0223e-07
## Wald statistic: 27.012, p-value: 2.0223e-07
##
## Log likelihood: -188.6373 for mixed model
## ML residual variance (sigma squared): 1.3227, (sigma: 1.1501)
## Number of observations: 119
## Number of parameters estimated: 7
## AIC: 391.27, (AIC for lm: 414.48)
## LM test for residual autocorrelation
## test value: 5.7604, p-value: 0.016392
err.sdm <- sdm$residuals
ad.test(err.sdm)
##
## Anderson-Darling normality test
##
## data: err.sdm
## A = 0.64985, p-value = 0.08783
hist(err.sdm)
qqnorm(err.sdm, datax = TRUE)
qqline(rnorm(length(err.sdm), mean(err.sdm), sd(err.sdm)), datax = TRUE, col = "blue")
bptest.Sarlm(sdm)
##
## studentized Breusch-Pagan test
##
## data:
## BP = 2.774, df = 4, p-value = 0.5963
moran.test(err.sdm, listw = ww, alternative = "two.sided", zero.policy = TRUE)
##
## Moran I test under randomisation
##
## data: err.sdm
## weights: ww
##
## Moran I statistic standard deviate = -0.59546, p-value = 0.5515
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## -0.039895232 -0.008474576 0.002784333
Koefisien lag.x1 dan lag.x2 menunjukkan pengaruh peubah penjelas wilayah tetangga; rho signifikan menunjukkan dependensi lag pada respon.
df_aic <- data.frame(
"Model" = c("OLS (Regresi Klasik)", "SAR", "SEM", "SARMA", "SDM"),
"AIC" = c(AIC(ols), AIC(sar), AIC(sem), AIC(SARMA), AIC(sdm))
)
df_aic
Model dengan AIC terkecil adalah yang terbaik.
sum.sarma <- summary(SARMA)
sum.sarma
##
## Call:
## sacsarlm(formula = y ~ x1 + x2, data = data, listw = ww, zero.policy = TRUE)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.53574 -0.59853 0.10686 0.78564 2.55146
##
## Type: sac
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -37.670168 2.567539 -14.672 < 2.2e-16
## x1 0.530517 0.015036 35.282 < 2.2e-16
## x2 0.286556 0.011748 24.392 < 2.2e-16
##
## Rho: 0.083991
## Asymptotic standard error: 0.064873
## z-value: 1.2947, p-value: 0.19543
## Lambda: 0.47951
## Asymptotic standard error: 0.11669
## z-value: 4.1093, p-value: 3.9689e-05
##
## LR test value: 34.119, p-value: 3.9012e-08
##
## Log likelihood: -189.6009 for sac model
## ML residual variance (sigma squared): 1.3555, (sigma: 1.1642)
## Number of observations: 119
## Number of parameters estimated: 6
## AIC: 391.2, (AIC for lm: 421.32)
# Spillover SARMA
Im <- impacts(SARMA, listw = ww)
Im
## Impact measures (sac, exact):
## Direct Indirect Total
## x1 dy/dx 0.5311153 0.04804610 0.5791614
## x2 dy/dx 0.2868790 0.02595184 0.3128308
# Efek umpan balik
koef <- sum.sarma$coefficients[-1]
diref <- Im$direct
umbal <- diref - koef
cbind.data.frame(Koefisien = koef, EfekLangsung = diref, UmpanBalik = umbal)
# Spillover model lain
impacts(sar, listw = ww)
## Impact measures (lag, exact):
## Direct Indirect Total
## x1 dy/dx 0.5370876 0.15600347 0.6930911
## x2 dy/dx 0.2930588 0.08512239 0.3781812
impacts(sdm, listw = ww)
## Impact measures (mixed, exact):
## Direct Indirect Total
## x1 dy/dx 0.5339407 0.09751864 0.6314593
## x2 dy/dx 0.2920035 0.07177460 0.3637781
Efek langsung adalah pengaruh X terhadap Y wilayah sendiri (termasuk umpan balik), efek tidak langsung adalah spillover ke wilayah tetangga, dan total adalah jumlah keduanya; umpan balik = efek langsung dikurangi koefisien.