# ============================================================
# A. PERSIAPAN PACKAGE DAN MEMBACA DATA
# ============================================================
rm(list = ls())
library(sf)
## Linking to GEOS 3.14.1, GDAL 3.12.1, PROJ 9.7.1; sf_use_s2() is TRUE
library(spdep)
## Loading required package: spData
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source')`
library(spatialreg)
## Loading required package: Matrix
##
## Attaching package: 'spatialreg'
## The following objects are masked from 'package:spdep':
##
## get.ClusterOption, get.coresOption, get.mcOption,
## get.VerboseOption, get.ZeroPolicyOption, set.ClusterOption,
## set.coresOption, set.mcOption, set.VerboseOption,
## set.ZeroPolicyOption
library(readxl)
library(ggplot2)
library(car)
## Warning: package 'car' was built under R version 4.6.2
## Loading required package: carData
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(corrplot)
## corrplot 0.95 loaded
dataset <- as.data.frame(
read_excel(
"C:/Users/LENOVO/OneDrive/Documents/SEMESTER 5/ANALISIS DATA SPASIAL/Data Project Spasial 1.xlsx"))
koordinat_data <- as.data.frame(
read_excel(
"C:/Users/LENOVO/OneDrive/Documents/SEMESTER 5/ANALISIS DATA SPASIAL/Koordinat Provinsi.xlsx"))
str(dataset)
## 'data.frame': 38 obs. of 6 variables:
## $ Provinsi : chr "Aceh" "Sumatera Utara" "Sumatera Barat" "Riau" ...
## $ TPT Agustus 2025 (%) : num 5.64 5.32 5.62 4.16 4.26 3.69 3.41 4.21 4.45 6.45 ...
## $ IPM 2025 : num 76.2 76.5 77.3 76.3 75.1 ...
## $ RLS 2025 (tahun) : num 10.42 10.29 10.03 9.8 9.32 ...
## $ PPM September 2025 (%): num 12.22 7.24 5.31 6.3 6.89 ...
## $ TPAK Agustus 2025 (%) : num 65.3 72.3 71.3 66.5 68.4 ...
summary(dataset)
## Provinsi TPT Agustus 2025 (%) IPM 2025 RLS 2025 (tahun)
## Length :38 Min. :1.490 Min. :54.91 Min. : 4.760
## N.unique :38 1st Qu.:3.500 1st Qu.:72.67 1st Qu.: 8.932
## N.blank : 0 Median :4.210 Median :74.81 Median : 9.575
## Min.nchar: 4 Mean :4.468 Mean :74.25 Mean : 9.457
## Max.nchar:25 3rd Qu.:5.545 3rd Qu.:76.29 3rd Qu.:10.092
## Max. :6.960 Max. :85.05 Max. :11.580
## PPM September 2025 (%) TPAK Agustus 2025 (%)
## Min. : 3.420 Min. :63.98
## 1st Qu.: 5.530 1st Qu.:67.44
## Median : 9.345 Median :69.56
## Mean :10.269 Mean :70.52
## 3rd Qu.:12.135 3rd Qu.:72.37
## Max. :29.450 Max. :90.66
str(koordinat_data)
## 'data.frame': 38 obs. of 3 variables:
## $ Provinsi : chr "ACEH" "SUMATERA UTARA" "SUMATERA BARAT" "RIAU" ...
## $ Latitude : num 4.695 2.115 -0.74 0.533 -1.61 ...
## $ Longitude: num 96.9 99.8 100.4 101.4 103.6 ...
# Memeriksa dimensi data
dim(dataset)
## [1] 38 6
dim(koordinat_data)
## [1] 38 3
# Memeriksa jumlah provinsi
length(unique(dataset$Provinsi))
## [1] 38
length(unique(koordinat_data$Provinsi))
## [1] 38
# ============================================================
# B. MENYESUAIKAN NAMA VARIABEL
# ============================================================
# Mengganti nama kolom berdasarkan urutan data Excel
names(dataset) <- c(
"provinsi",
"tpt",
"ipm",
"rls",
"kemiskinan",
"tpak"
)
# Membentuk dataset penelitian
# RLS tidak dimasukkan sebagai prediktor
data_model <- dataset[, c(
"provinsi",
"tpt",
"ipm",
"rls",
"kemiskinan",
"tpak"
)]
# Memastikan variabel numerik
variabel <- c(
"tpt",
"ipm",
"rls",
"kemiskinan",
"tpak"
)
data_model[variabel] <- lapply(
data_model[variabel],
as.numeric
)
# Memeriksa struktur data
str(data_model)
## 'data.frame': 38 obs. of 6 variables:
## $ provinsi : chr "Aceh" "Sumatera Utara" "Sumatera Barat" "Riau" ...
## $ tpt : num 5.64 5.32 5.62 4.16 4.26 3.69 3.41 4.21 4.45 6.45 ...
## $ ipm : num 76.2 76.5 77.3 76.3 75.1 ...
## $ rls : num 10.42 10.29 10.03 9.8 9.32 ...
## $ kemiskinan: num 12.22 7.24 5.31 6.3 6.89 ...
## $ tpak : num 65.3 72.3 71.3 66.5 68.4 ...
# Statistik deskriptif awal
summary(data_model)
## provinsi tpt ipm rls
## Length :38 Min. :1.490 Min. :54.91 Min. : 4.760
## N.unique :38 1st Qu.:3.500 1st Qu.:72.67 1st Qu.: 8.932
## N.blank : 0 Median :4.210 Median :74.81 Median : 9.575
## Min.nchar: 4 Mean :4.468 Mean :74.25 Mean : 9.457
## Max.nchar:25 3rd Qu.:5.545 3rd Qu.:76.29 3rd Qu.:10.092
## Max. :6.960 Max. :85.05 Max. :11.580
## kemiskinan tpak
## Min. : 3.420 Min. :63.98
## 1st Qu.: 5.530 1st Qu.:67.44
## Median : 9.345 Median :69.56
## Mean :10.269 Mean :70.52
## 3rd Qu.:12.135 3rd Qu.:72.37
## Max. :29.450 Max. :90.66
# Memeriksa jumlah observasi
nrow(data_model)
## [1] 38
# ============================================================
# C. MENYELARASKAN NAMA PROVINSI DAN KOORDINAT
# ============================================================
# Menyeragamkan penulisan nama provinsi
data_model$provinsi <- toupper(
trimws(as.character(data_model$provinsi))
)
koordinat_data$Provinsi <- toupper(
trimws(as.character(koordinat_data$Provinsi))
)
# Memeriksa duplikasi nama provinsi
anyDuplicated(data_model$provinsi)
## [1] 0
anyDuplicated(koordinat_data$Provinsi)
## [1] 0
# Mencocokkan urutan koordinat dengan dataset utama
urutan <- match(
data_model$provinsi,
koordinat_data$Provinsi
)
# Mengurutkan koordinat sesuai dataset utama
koordinat_data <- koordinat_data[urutan, ]
# Menampilkan hasil pencocokan
hasil_pemeriksaan <- data.frame(
Provinsi_Data = data_model$provinsi,
Provinsi_Koordinat = koordinat_data$Provinsi
)
print(hasil_pemeriksaan)
## Provinsi_Data Provinsi_Koordinat
## 1 ACEH ACEH
## 2 SUMATERA UTARA SUMATERA UTARA
## 3 SUMATERA BARAT SUMATERA BARAT
## 4 RIAU RIAU
## 5 JAMBI JAMBI
## 6 SUMATERA SELATAN SUMATERA SELATAN
## 7 BENGKULU BENGKULU
## 8 LAMPUNG LAMPUNG
## 9 KEPULAUAN BANGKA BELITUNG KEPULAUAN BANGKA BELITUNG
## 10 KEPULAUAN RIAU KEPULAUAN RIAU
## 11 DKI JAKARTA DKI JAKARTA
## 12 JAWA BARAT JAWA BARAT
## 13 JAWA TENGAH JAWA TENGAH
## 14 DI YOGYAKARTA DI YOGYAKARTA
## 15 JAWA TIMUR JAWA TIMUR
## 16 BANTEN BANTEN
## 17 BALI BALI
## 18 NUSA TENGGARA BARAT NUSA TENGGARA BARAT
## 19 NUSA TENGGARA TIMUR NUSA TENGGARA TIMUR
## 20 KALIMANTAN BARAT KALIMANTAN BARAT
## 21 KALIMANTAN TENGAH KALIMANTAN TENGAH
## 22 KALIMANTAN SELATAN KALIMANTAN SELATAN
## 23 KALIMANTAN TIMUR KALIMANTAN TIMUR
## 24 KALIMANTAN UTARA KALIMANTAN UTARA
## 25 SULAWESI UTARA SULAWESI UTARA
## 26 SULAWESI TENGAH SULAWESI TENGAH
## 27 SULAWESI SELATAN SULAWESI SELATAN
## 28 SULAWESI TENGGARA SULAWESI TENGGARA
## 29 GORONTALO GORONTALO
## 30 SULAWESI BARAT SULAWESI BARAT
## 31 MALUKU MALUKU
## 32 MALUKU UTARA MALUKU UTARA
## 33 PAPUA BARAT PAPUA BARAT
## 34 PAPUA BARAT DAYA PAPUA BARAT DAYA
## 35 PAPUA PAPUA
## 36 PAPUA SELATAN PAPUA SELATAN
## 37 PAPUA TENGAH PAPUA TENGAH
## 38 PAPUA PEGUNUNGAN PAPUA PEGUNUNGAN
# ============================================================
# D. EKSPLORASI DATA
# ============================================================
# Statistik deskriptif
summary(
data_model[, variabel]
)
## tpt ipm rls kemiskinan
## Min. :1.490 Min. :54.91 Min. : 4.760 Min. : 3.420
## 1st Qu.:3.500 1st Qu.:72.67 1st Qu.: 8.932 1st Qu.: 5.530
## Median :4.210 Median :74.81 Median : 9.575 Median : 9.345
## Mean :4.468 Mean :74.25 Mean : 9.457 Mean :10.269
## 3rd Qu.:5.545 3rd Qu.:76.29 3rd Qu.:10.092 3rd Qu.:12.135
## Max. :6.960 Max. :85.05 Max. :11.580 Max. :29.450
## tpak
## Min. :63.98
## 1st Qu.:67.44
## Median :69.56
## Mean :70.52
## 3rd Qu.:72.37
## Max. :90.66
# Boxplot
par(mfrow = c(1, 5))
boxplot(data_model$kemiskinan,main = "Boxplot Kemiskinan")
boxplot(data_model$tpt,main = "Boxplot TPT")
boxplot(data_model$ipm,main = "Boxplot IPM")
boxplot(data_model$rls,main = "Boxplot RLS")
boxplot(data_model$tpak,main = "Boxplot TPAK")
# Scatterplot
library(DescTools)
## Warning: package 'DescTools' was built under R version 4.6.2
##
## Attaching package: 'DescTools'
## The following object is masked from 'package:car':
##
## Recode
pairs(
data_model[, c("kemiskinan", "tpt", "ipm", "rls", "tpak")],
pch = 19,
lower.panel = NULL
)
par(mfrow = c(1, 1))
# Matriks korelasi
korelasi <- cor(
data_model[, variabel],
use = "complete.obs"
)
print(korelasi)
## tpt ipm rls kemiskinan tpak
## tpt 1.0000000 0.3710350 0.5648440 -0.1915347 -0.7307117
## ipm 0.3710350 1.0000000 0.8374693 -0.8102000 -0.5598682
## rls 0.5648440 0.8374693 1.0000000 -0.5632780 -0.7100815
## kemiskinan -0.1915347 -0.8102000 -0.5632780 1.0000000 0.3916534
## tpak -0.7307117 -0.5598682 -0.7100815 0.3916534 1.0000000
# Visualisasi korelasi
corrplot(
korelasi,
method = "color",
type = "upper",
addCoef.col = "black",
tl.col = "black",
tl.srt = 45
)
# ============================================================
# PEMETAAN SPASIAL VARIABEL KEMISKINAN
# ============================================================
# Memanggil package
library(sf)
library(sp)
library(spdep)
# Membaca shapefile
peta <- st_read(
"C:/Users/LENOVO/OneDrive/Documents/SEMESTER 5/ANALISIS DATA SPASIAL/Batas Provinsi Indonesia.shp")
## Reading layer `Batas Provinsi Indonesia' from data source
## `C:\Users\LENOVO\OneDrive\Documents\SEMESTER 5\ANALISIS DATA SPASIAL\Batas Provinsi Indonesia.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 38 features and 0 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 94.97191 ymin: -11.00762 xmax: 141.02 ymax: 6.076832
## CRS: NA
# Memasukkan nilai kemiskinan
peta$kemiskinan <- data_model$kemiskinan
# Mengubah objek sf menjadi Spatial
peta_sp <- as(peta, "Spatial")
# Membuat gradasi warna
k <- 101
colfunc <- colorRampPalette(c("green", "yellow", "red"))#(rendah ke tinggi)
warna <- colfunc(k)
# Membuat peta tematik
spplot(
peta_sp,
"kemiskinan",
col.regions = warna,
main = "Peta Persebaran Kemiskinan Provinsi Indonesia"
)
#==================================
# Persiapan koordinat dan jarak
#==================================
library(spdep)
library(geosphere)
## Warning: package 'geosphere' was built under R version 4.6.2
koordinat <- as.matrix(
koordinat_data[, c("Longitude", "Latitude")]
)
storage.mode(koordinat) <- "numeric"
# Jarak dalam kilometer
m.djarak <- geosphere::distm(
koordinat,
fun = geosphere::distHaversine
) / 1000
diag(m.djarak) <- 0
#==================================
# Model OLS
#==================================
ols <- lm(kemiskinan ~ ipm + tpt + rls + tpak, data = data_model)
summary(ols)
##
## Call:
## lm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data = data_model)
##
## Residuals:
## Min 1Q Median 3Q Max
## -7.6122 -2.0724 -0.6896 2.1733 8.2245
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 78.6196 22.8031 3.448 0.00156 **
## ipm -1.3536 0.2145 -6.310 3.88e-07 ***
## tpt 0.3206 0.6462 0.496 0.62317
## rls 2.1797 1.1048 1.973 0.05692 .
## tpak 0.1433 0.2147 0.667 0.50916
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.605 on 33 degrees of freedom
## Multiple R-squared: 0.7051, Adjusted R-squared: 0.6693
## F-statistic: 19.72 on 4 and 33 DF, p-value: 2.25e-08
AIC(ols)
## [1] 211.9339
#==================================
# Matriks Pembobot Spasial KNN (k=5)
#==================================
nb.knn <- knn2nb(knearneigh(koordinat, k = 5, longlat = TRUE))
W.knn <- nb2listw(nb.knn, style = "W")
mt = lm.morantest(ols,W.knn,alternative = "greater")
mt
##
## Global Moran I for regression residuals
##
## data:
## model: lm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data =
## data_model)
## weights: W.knn
##
## Moran I statistic standard deviate = 2.7844, p-value = 0.002681
## alternative hypothesis: greater
## sample estimates:
## Observed Moran I Expectation Variance
## 0.165123438 -0.056921371 0.006359461
ww = W.knn
ww
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 38
## Number of nonzero links: 190
## Percentage nonzero weights: 13.15789
## Average number of links: 5
## Non-symmetric neighbours list
##
## Weights style: W
## Weights constants summary:
## n nn S0 S1 S2
## W 38 1444 38 13.44 158.08
#==================================
# Pemeriksaan Multikolinearitas
#==================================
car::vif(ols)
## ipm tpt rls tpak
## 3.536900 2.268613 4.920634 2.980864
#==================================
# Uji asumsi normalitas residual
#==================================
library(lmtest)
err.ols <- residuals(ols)
shapiro.test(err.ols)
##
## Shapiro-Wilk normality test
##
## data: err.ols
## W = 0.98159, p-value = 0.7732
#==================================
# Uji autokorelasi spasial
#==================================
# 1. Moran pada galat OLS
spdep::lm.morantest(ols,listw = ww,alternative = "two.sided",zero.policy = TRUE)
##
## Global Moran I for regression residuals
##
## data:
## model: lm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data =
## data_model)
## weights: ww
##
## Moran I statistic standard deviate = 2.7844, p-value = 0.005363
## alternative hypothesis: two.sided
## sample estimates:
## Observed Moran I Expectation Variance
## 0.165123438 -0.056921371 0.006359461
# 2. Moran Global pada residual OLS
spdep::moran.test(residuals(ols),ww,randomisation = FALSE,alternative = "two.sided",zero.policy = TRUE)
##
## Moran I test under normality
##
## data: residuals(ols)
## weights: ww
##
## Moran I statistic standard deviate = 2.1785, p-value = 0.02937
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## 0.165123438 -0.027027027 0.007779588
# 3. Moran Global pada variabel kemiskinan
spdep::moran.test(data_model$kemiskinan,ww,randomisation = FALSE,
alternative = "two.sided",zero.policy = TRUE)
##
## Moran I test under normality
##
## data: data_model$kemiskinan
## weights: ww
##
## Moran I statistic standard deviate = 7.6469, p-value = 2.059e-14
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## 0.647441742 -0.027027027 0.007779588
#==================================
# Uji Kehomogenan Ragam
#==================================
lmtest::bptest(ols)
##
## studentized Breusch-Pagan test
##
## data: ols
## BP = 0.31354, df = 4, p-value = 0.9889
#==================================
# Model Autokorelasi Spasial pada x
#==================================
# Moran's I Y: Kemiskinan
moran_y <- moran.test(data_model$kemiskinan,ww,alternative = "greater")
moran_y
##
## Moran I test under randomisation
##
## data: data_model$kemiskinan
## weights: ww
##
## Moran I statistic standard deviate = 7.8491, p-value = 2.095e-15
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.647441742 -0.027027027 0.007383865
# Moran's I X1: IPM
moran_x1 <- moran.test(data_model$ipm,ww,alternative = "greater")
moran_x1
##
## Moran I test under randomisation
##
## data: data_model$ipm
## weights: ww
##
## Moran I statistic standard deviate = 4.8699, p-value = 5.583e-07
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.371497284 -0.027027027 0.006696863
# Moran's I X2: TPT
moran_x2 <- moran.test(data_model$tpt,ww,alternative = "greater")
moran_x2
##
## Moran I test under randomisation
##
## data: data_model$tpt
## weights: ww
##
## Moran I statistic standard deviate = 1.7028, p-value = 0.0443
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.123913056 -0.027027027 0.007857437
# Moran's I X3: RLS
moran_x3 <- moran.test(data_model$rls,ww,alternative = "greater")
moran_x3
##
## Moran I test under randomisation
##
## data: data_model$rls
## weights: ww
##
## Moran I statistic standard deviate = 0.36069, p-value = 0.3592
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.001914966 -0.027027027 0.006438426
# Moran's I X4: TPAK
moran_x4 <- moran.test(data_model$tpak,ww,alternative = "greater")
moran_x4
##
## Moran I test under randomisation
##
## data: data_model$tpak
## weights: ww
##
## Moran I statistic standard deviate = 0.50277, p-value = 0.3076
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.012737261 -0.027027027 0.006255331
Variabel <- c("Kemiskinan", "IPM", "TPT", "RLS", "TPAK")
IndeksMoran <- c(
moran_y$estimate[1],
moran_x1$estimate[1],
moran_x2$estimate[1],
moran_x3$estimate[1],
moran_x4$estimate[1]
)
p_value <- c(
moran_y$p.value,
moran_x1$p.value,
moran_x2$p.value,
moran_x3$p.value,
moran_x4$p.value
)
Tabel_Moran <- data.frame(Variabel,IndeksMoran,p_value)
Tabel_Moran
## Variabel IndeksMoran p_value
## 1 Kemiskinan 0.647441742 2.095139e-15
## 2 IPM 0.371497284 5.583036e-07
## 3 TPT 0.123913056 4.430257e-02
## 4 RLS 0.001914966 3.591642e-01
## 5 TPAK 0.012737261 3.075635e-01
#======================= Uji LM dan Robust LM =======================
LM <- spdep::lm.RStests(ols,listw = ww,test = "all")
summary(LM)
## Rao's score (a.k.a Lagrange multiplier) diagnostics for spatial
## dependence
## data:
## model: lm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data =
## data_model)
## test weights: ww
##
## statistic parameter p.value
## RSerr 2.92945 1 0.0869774 .
## RSlag 11.76553 1 0.0006034 ***
## adjRSerr 0.40944 1 0.5222544
## adjRSlag 9.24552 1 0.0023607 **
## SARMA 12.17497 2 0.0022711 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Model Pertimbangan
# a. SAR
SAR <- lagsarlm(kemiskinan ~ ipm + tpt + rls + tpak, data= data_model, listw = ww)
summary(SAR, Nagelkerke = T)
##
## Call:
## lagsarlm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data = data_model,
## listw = ww)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.1587811 -1.8136730 -0.0052148 1.5235021 6.0608424
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 43.1010073 20.2564339 2.1278 0.033356
## ipm -0.6737938 0.2257119 -2.9852 0.002834
## tpt -0.0011786 0.4943381 -0.0024 0.998098
## rls 0.4324924 0.9355721 0.4623 0.643883
## tpak 0.1091438 0.1653159 0.6602 0.509117
##
## Rho: 0.5375, LR test value: 12.731, p-value: 0.00035967
## Asymptotic standard error: 0.12259
## z-value: 4.3844, p-value: 1.1631e-05
## Wald statistic: 19.223, p-value: 1.1631e-05
##
## Log likelihood: -93.60154 for lag model
## ML residual variance (sigma squared): 7.6042, (sigma: 2.7576)
## Nagelkerke pseudo-R-squared: 0.78902
## Number of observations: 38
## Number of parameters estimated: 7
## AIC: 201.2, (AIC for lm: 211.93)
## LM test for residual autocorrelation
## test value: 0.0049013, p-value: 0.94419
# b. SARMA
SARMA <- sacsarlm(kemiskinan ~ ipm + tpt + rls + tpak, data= data_model, ww, zero.policy = TRUE)
summary(SARMA)
##
## Call:
## sacsarlm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data = data_model,
## listw = ww, zero.policy = TRUE)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.136598 -1.849599 -0.014937 1.519797 6.049737
##
## Type: sac
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 42.027572 22.777175 1.8452 0.06501
## ipm -0.664314 0.275828 -2.4084 0.01602
## tpt 0.016641 0.492072 0.0338 0.97302
## rls 0.402328 1.020884 0.3941 0.69351
## tpak 0.116314 0.166141 0.7001 0.48387
##
## Rho: 0.54407
## Asymptotic standard error: 0.17456
## z-value: 3.1167, p-value: 0.0018286
## Lambda: -0.03221
## Asymptotic standard error: 0.39895
## z-value: -0.080738, p-value: 0.93565
##
## LR test value: 12.737, p-value: 0.0017151
##
## Log likelihood: -93.5987 for sac model
## ML residual variance (sigma squared): 7.5882, (sigma: 2.7547)
## Number of observations: 38
## Number of parameters estimated: 8
## AIC: 203.2, (AIC for lm: 211.93)
# b. SDM
SDM <- lagsarlm(kemiskinan ~ ipm + tpt + rls + tpak, data = data_model, listw=ww, type="mixed");
summary(SDM)
##
## Call:
## lagsarlm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data = data_model,
## listw = ww, type = "mixed")
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.283272 -1.328478 0.030329 1.360138 5.252345
##
## Type: mixed
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.70171 42.42243 -0.0165 0.9868027
## ipm -1.03369 0.30230 -3.4194 0.0006275
## tpt 0.42997 0.51193 0.8399 0.4009570
## rls 1.40401 1.01889 1.3780 0.1682078
## tpak 0.23647 0.16341 1.4471 0.1478720
## lag.ipm -0.13143 0.48687 -0.2699 0.7872023
## lag.tpt 2.77720 1.04062 2.6688 0.0076123
## lag.rls -2.29278 2.46689 -0.9294 0.3526726
## lag.tpak 1.06581 0.44373 2.4019 0.0163085
##
## Rho: 0.01116, LR test value: 0.0012796, p-value: 0.97146
## Asymptotic standard error: 0.25597
## z-value: 0.043599, p-value: 0.96522
## Wald statistic: 0.0019009, p-value: 0.96522
##
## Log likelihood: -89.20693 for mixed model
## ML residual variance (sigma squared): 6.4058, (sigma: 2.531)
## Number of observations: 38
## Number of parameters estimated: 11
## AIC: 200.41, (AIC for lm: 198.42)
## LM test for residual autocorrelation
## test value: 0.37209, p-value: 0.54187
#====================== Model Terbaik================================
cbind.data.frame(AIC(ols),AIC(SAR),AIC(SARMA),AIC(SDM))
## AIC(ols) AIC(SAR) AIC(SARMA) AIC(SDM)
## 1 211.9339 201.2031 203.1974 200.4139
# Mengambil log-likelihood
ll_SDM <- logLik(SDM)
ll_SAR <- logLik(SAR)
# Menghitung statistik LR
LR_stat <- 2 * (as.numeric(ll_SDM) - as.numeric(ll_SAR))
# Derajat bebas
df <- attr(ll_SDM, "df") - attr(ll_SAR, "df")
# Menghitung p-value
p_value <- pchisq(LR_stat, df = df, lower.tail = FALSE)
# Menampilkan hasil
cat("LR Statistic :", LR_stat, "\n")
## LR Statistic : 8.789222
cat("Derajat Bebas:", df, "\n")
## Derajat Bebas: 4
cat("P-value :", p_value, "\n")
## P-value : 0.06658937
#============= Asumsi Model Terbaik ===============#
library(nortest)
residual.SDM <- residuals(SDM)
# a. normalitas
shapiro.test(residual.SDM)
##
## Shapiro-Wilk normality test
##
## data: residual.SDM
## W = 0.98271, p-value = 0.8108
# b. kehomogenan ragam
bptest.Sarlm(SDM)
##
## studentized Breusch-Pagan test
##
## data:
## BP = 12.07, df = 8, p-value = 0.1481
# c. autokorelasi residual
moran.test(residual.SDM, ww, alternative="two.sided", zero.policy = TRUE)
##
## Moran I test under randomisation
##
## data: residual.SDM
## weights: ww
##
## Moran I statistic standard deviate = 0.086615, p-value = 0.931
## alternative hypothesis: two.sided
## sample estimates:
## Moran I statistic Expectation Variance
## -0.019413521 -0.027027027 0.007726552
#============ Interpretasi Model Terbaik ===================
S = summary(SDM)
S
##
## Call:
## lagsarlm(formula = kemiskinan ~ ipm + tpt + rls + tpak, data = data_model,
## listw = ww, type = "mixed")
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.283272 -1.328478 0.030329 1.360138 5.252345
##
## Type: mixed
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.70171 42.42243 -0.0165 0.9868027
## ipm -1.03369 0.30230 -3.4194 0.0006275
## tpt 0.42997 0.51193 0.8399 0.4009570
## rls 1.40401 1.01889 1.3780 0.1682078
## tpak 0.23647 0.16341 1.4471 0.1478720
## lag.ipm -0.13143 0.48687 -0.2699 0.7872023
## lag.tpt 2.77720 1.04062 2.6688 0.0076123
## lag.rls -2.29278 2.46689 -0.9294 0.3526726
## lag.tpak 1.06581 0.44373 2.4019 0.0163085
##
## Rho: 0.01116, LR test value: 0.0012796, p-value: 0.97146
## Asymptotic standard error: 0.25597
## z-value: 0.043599, p-value: 0.96522
## Wald statistic: 0.0019009, p-value: 0.96522
##
## Log likelihood: -89.20693 for mixed model
## ML residual variance (sigma squared): 6.4058, (sigma: 2.531)
## Number of observations: 38
## Number of parameters estimated: 11
## AIC: 200.41, (AIC for lm: 198.42)
## LM test for residual autocorrelation
## test value: 0.37209, p-value: 0.54187
# Spill over
Im = impacts(SDM, listw = ww)
Im
## Impact measures (mixed, exact):
## Direct Indirect Total
## ipm dy/dx -1.0339372 -0.1443317 -1.1782689
## tpt dy/dx 0.4347750 2.8085975 3.2433725
## rls dy/dx 1.4000792 -2.2988759 -0.8987967
## tpak dy/dx 0.2383151 1.0786618 1.3169769
# Efek Umpan Balik
koef = S$coefficients[-1]
diref = Im$direct
umbal = diref-koef
cbind.data.frame(Koefisien=koef,EfekLangsung=diref,UmpanBalik=umbal)
## Koefisien EfekLangsung UmpanBalik
## ipm -1.0336904 -1.0339372 -0.0002467835
## tpt 0.4299728 0.4347750 0.0048022410
## rls 1.4040099 1.4000792 -0.0039307007
## tpak 0.2364708 0.2383151 0.0018443347
## lag.ipm -0.1314290 -1.0339372 -0.9025082194
## lag.tpt 2.7772036 0.4347750 -2.3424285886
## lag.rls -2.2927760 1.4000792 3.6928551898
## lag.tpak 1.0658086 0.2383151 -0.8274934425
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.