Hubungan Kelompok Umur (kategori) dengan Jenis Layanan Publik yang paling sering dipakai (kategori).
rm(list = ls())
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(FactoMineR)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
Data: Dibangkitkan di R, ukuran sampel n = 450, dengan probabilitas layanan yang dibuat berbeda per kelompok umur (supaya ada pola, bukan “independen total”).
set.seed(123)
n <- 450
Umur <- sample(
x = c("17–20", "21–25", "26–35", "36–50", "51+"),
size = n,
replace = TRUE,
prob = c(0.20, 0.28, 0.25, 0.17, 0.10)
)
prob_layanan <- function(u){
if(u == "17–20") return(c(0.12, 0.18, 0.30, 0.20, 0.20))
if(u == "21–25") return(c(0.10, 0.22, 0.26, 0.22, 0.20))
if(u == "26–35") return(c(0.14, 0.26, 0.18, 0.22, 0.20))
if(u == "36–50") return(c(0.18, 0.28, 0.12, 0.22, 0.20))
return(c(0.22, 0.26, 0.08, 0.22, 0.22)) # 51+
}
levels_layanan <- c("Kesehatan", "Administrasi", "Transportasi", "Kelurahan", "Perizinan")
JenisLayanan <- sapply(Umur, function(u){
sample(levels_layanan, size = 1, prob = prob_layanan(u))
})
data_ca <- data.frame(
Umur = factor(Umur, levels = c("17–20", "21–25", "26–35", "36–50", "51+")),
JenisLayanan = factor(JenisLayanan, levels = levels_layanan)
)
print(head(data_ca))
## Umur JenisLayanan
## 1 26–35 Perizinan
## 2 36–50 Kelurahan
## 3 26–35 Administrasi
## 4 36–50 Administrasi
## 5 51+ Administrasi
## 6 21–25 Perizinan
print(table(data_ca$Umur))
##
## 17–20 21–25 26–35 36–50 51+
## 88 123 125 70 44
print(table(data_ca$JenisLayanan))
##
## Kesehatan Administrasi Transportasi Kelurahan Perizinan
## 54 102 99 84 111
tab <- table(data_ca$Umur, data_ca$JenisLayanan)
cat("\n Tabel Kontingensi (Umur x Jenis Layanan) \n")
##
## Tabel Kontingensi (Umur x Jenis Layanan)
print(tab)
##
## Kesehatan Administrasi Transportasi Kelurahan Perizinan
## 17–20 5 15 31 16 21
## 21–25 11 25 32 26 29
## 26–35 16 29 27 24 29
## 36–50 15 20 4 14 17
## 51+ 7 13 5 4 15
cat("\n Proporsi per baris (dalam %) \n")
##
## Proporsi per baris (dalam %)
print(round(prop.table(tab, 1) * 100, 2))
##
## Kesehatan Administrasi Transportasi Kelurahan Perizinan
## 17–20 5.68 17.05 35.23 18.18 23.86
## 21–25 8.94 20.33 26.02 21.14 23.58
## 26–35 12.80 23.20 21.60 19.20 23.20
## 36–50 21.43 28.57 5.71 20.00 24.29
## 51+ 15.91 29.55 11.36 9.09 34.09
chisq <- chisq.test(tab)
cat("\n Uji Chi-Square \n")
##
## Uji Chi-Square
print(chisq)
##
## Pearson's Chi-squared test
##
## data: tab
## X-squared = 36.284, df = 16, p-value = 0.002642
res_ca <- CA(tab, graph = FALSE)
cat("\n=== Ringkasan CA ===\n")
##
## === Ringkasan CA ===
print(res_ca)
## **Results of the Correspondence Analysis (CA)**
## The row variable has 5 categories; the column variable has 5 categories
## The chi square of independence between the two variables is equal to 36.28441 (p-value = 0.002641512 ).
## *The results are available in the following objects:
##
## name description
## 1 "$eig" "eigenvalues"
## 2 "$col" "results for the columns"
## 3 "$col$coord" "coord. for the columns"
## 4 "$col$cos2" "cos2 for the columns"
## 5 "$col$contrib" "contributions of the columns"
## 6 "$row" "results for the rows"
## 7 "$row$coord" "coord. for the rows"
## 8 "$row$cos2" "cos2 for the rows"
## 9 "$row$contrib" "contributions of the rows"
## 10 "$call" "summary called parameters"
## 11 "$call$marge.col" "weights of the columns"
## 12 "$call$marge.row" "weights of the rows"
# Nilai penting:
cat("\n=== Eigenvalues (inertia) ===\n")
##
## === Eigenvalues (inertia) ===
print(res_ca$eig)
## eigenvalue percentage of variance cumulative percentage of variance
## dim 1 7.098902e-02 88.0407360 88.04074
## dim 2 9.029111e-03 11.1979236 99.23866
## dim 3 5.302571e-04 0.6576261 99.89629
## dim 4 8.362701e-05 0.1037144 100.00000
cat("\n=== Koordinat baris (Umur) - dimensi 1&2 ===\n")
##
## === Koordinat baris (Umur) - dimensi 1&2 ===
print(round(res_ca$row$coord[, 1:2], 4))
## Dim 1 Dim 2
## 17–20 -0.3532 -0.0419
## 21–25 -0.1364 0.0389
## 26–35 0.0187 0.0305
## 36–50 0.4495 0.0936
## 51+ 0.3194 -0.2608
cat("\n=== Koordinat kolom (Jenis Layanan) - dimensi 1&2 ===\n")
##
## === Koordinat kolom (Jenis Layanan) - dimensi 1&2 ===
print(round(res_ca$col$coord[, 1:2], 4))
## Dim 1 Dim 2
## Kesehatan 0.4178 0.0558
## Administrasi 0.1831 -0.0296
## Transportasi -0.4327 -0.0167
## Kelurahan -0.0526 0.1682
## Perizinan 0.0542 -0.1123
cat("\n=== Kontribusi baris (Umur) ke dimensi 1&2 (semakin besar semakin 'ngangkat') ===\n")
##
## === Kontribusi baris (Umur) ke dimensi 1&2 (semakin besar semakin 'ngangkat') ===
print(round(res_ca$row$contrib[, 1:2], 2))
## Dim 1 Dim 2
## 17–20 34.37 3.80
## 21–25 7.16 4.59
## 26–35 0.14 2.87
## 36–50 44.28 15.10
## 51+ 14.05 73.65
cat("\n=== Kontribusi kolom (Layanan) ke dimensi 1&2 ===\n")
##
## === Kontribusi kolom (Layanan) ke dimensi 1&2 ===
print(round(res_ca$col$contrib[, 1:2], 2))
## Dim 1 Dim 2
## Kesehatan 29.51 4.13
## Administrasi 10.71 2.20
## Transportasi 58.03 0.68
## Kelurahan 0.73 58.51
## Perizinan 1.02 34.48
cat("\n=== Cos2 baris (kualitas representasi) dimensi 1&2 ===\n")
##
## === Cos2 baris (kualitas representasi) dimensi 1&2 ===
print(round(res_ca$row$cos2[, 1:2], 3))
## Dim 1 Dim 2
## 17–20 0.981 0.014
## 21–25 0.873 0.071
## 26–35 0.199 0.530
## 36–50 0.958 0.042
## 51+ 0.600 0.400
cat("\n=== Cos2 kolom (kualitas representasi) dimensi 1&2 ===\n")
##
## === Cos2 kolom (kualitas representasi) dimensi 1&2 ===
print(round(res_ca$col$cos2[, 1:2], 3))
## Dim 1 Dim 2
## Kesehatan 0.972 0.017
## Administrasi 0.968 0.025
## Transportasi 0.996 0.001
## Kelurahan 0.087 0.893
## Perizinan 0.183 0.787
# Scree plot inertia (berapa dimensi yang cukup)
fviz_screeplot(res_ca, addlabels = TRUE) +
ggtitle("Scree Plot Inertia - Analisis Korespondensi")
# Biplot utama (simetris)
fviz_ca_biplot(res_ca, repel = TRUE) +
ggtitle("Biplot CA: Umur vs Jenis Layanan")
# Plot kontribusi biar tahu siapa yang paling penting
fviz_contrib(res_ca, choice = "row", axes = 1) +
ggtitle("Kontribusi Baris (Umur) - Dimensi 1")
fviz_contrib(res_ca, choice = "col", axes = 1) +
ggtitle("Kontribusi Kolom (Layanan) - Dimensi 1")
pval <- chisq$p.value
cat("Uji Chi-square p-value =", signif(pval, 4), "\n")
## Uji Chi-square p-value = 0.002642
if(pval < 0.05){
cat("Kesimpulan uji: Terdapat asosiasi signifikan antara Umur dan Jenis Layanan.\n")
} else {
cat("Kesimpulan uji: Tidak ada bukti asosiasi signifikan antara Umur dan Jenis Layanan.\n")
}
## Kesimpulan uji: Terdapat asosiasi signifikan antara Umur dan Jenis Layanan.
eig <- res_ca$eig
inertia2 <- sum(eig[1:2, 2])
cat("Total inertia yang dijelaskan Dim 1-2 =", round(inertia2, 2), "%\n")
## Total inertia yang dijelaskan Dim 1-2 = 99.24 %
cat("\nCara baca biplot:\n")
##
## Cara baca biplot:
cat("- Titik yang berdekatan = profil mirip.\n")
## - Titik yang berdekatan = profil mirip.
cat("- Umur dekat dengan jenis layanan tertentu = kecenderungan asosiasi.\n")
## - Umur dekat dengan jenis layanan tertentu = kecenderungan asosiasi.
cat("- Fokus interpretasi pada kategori dengan kontribusi besar dan cos2 tinggi.\n")
## - Fokus interpretasi pada kategori dengan kontribusi besar dan cos2 tinggi.
# Ambil top contributor sederhana
top_row_dim1 <- names(sort(res_ca$row$contrib[,1], decreasing = TRUE))[1:2]
top_col_dim1 <- names(sort(res_ca$col$contrib[,1], decreasing = TRUE))[1:2]
top_row_dim2 <- names(sort(res_ca$row$contrib[,2], decreasing = TRUE))[1:2]
top_col_dim2 <- names(sort(res_ca$col$contrib[,2], decreasing = TRUE))[1:2]
cat("\nTop kontribusi Dimensi 1:\n")
##
## Top kontribusi Dimensi 1:
cat(" - Umur:", paste(top_row_dim1, collapse = ", "), "\n")
## - Umur: 36–50, 17–20
cat(" - Layanan:", paste(top_col_dim1, collapse = ", "), "\n")
## - Layanan: Transportasi, Kesehatan
cat("\nTop kontribusi Dimensi 2:\n")
##
## Top kontribusi Dimensi 2:
cat(" - Umur:", paste(top_row_dim2, collapse = ", "), "\n")
## - Umur: 51+, 36–50
cat(" - Layanan:", paste(top_col_dim2, collapse = ", "), "\n")
## - Layanan: Kelurahan, Perizinan
Berdasarkan tabel kontingensi dan hasil uji Chi-square, diperoleh p-value < 0,05 yang menunjukkan bahwa terdapat asosiasi signifikan antara kelompok umur dan jenis layanan publik yang paling sering digunakan. Artinya, pola pemanfaatan layanan tidak bersifat independen, melainkan berbeda antar kelompok umur. Dengan kata lain, preferensi layanan publik dipengaruhi oleh karakteristik usia, sehingga setiap kelompok umur cenderung memiliki fokus layanan yang berbeda sesuai kebutuhan dan aktivitasnya.
Hasil Analisis Korespondensi (CA) memperkuat temuan tersebut dengan memetakan hubungan antar kategori secara visual melalui biplot, di mana Dimensi 1 dan Dimensi 2 mampu menjelaskan proporsi inertia utama dari variasi data. Kategori umur dan jenis layanan yang memiliki kontribusi tinggi dan nilai cos² besar teridentifikasi sebagai elemen yang paling berperan dalam membentuk struktur asosiasi. Kedekatan posisi titik pada biplot mengindikasikan kemiripan profil dan kecenderungan hubungan, sehingga CA tidak hanya mengonfirmasi adanya asosiasi, tetapi juga memberikan interpretasi yang lebih intuitif dan informatif mengenai pola keterkaitan antara kelompok umur dan jenis layanan publik.