Eksplorasi Data
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.3
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
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
plot_ly(
data1,
x = ~factor(Wilayah),
y = ~TPT,
text = ~paste('Kabupaten/Kota: ', Wilayah, '<br>Value: ', TPT), # Menampilkan informasi saat hover
hoverinfo = 'text', # Tampilkan info saat hover
type = "bar",
color = ~factor(Wilayah) # Warna berdasarkan Wilayah
) %>%
layout(
title = list(text = "Tingkat Pengangguran Terbuka"), # Judul grafik
xaxis = list(title = "Kota/Kabupaten"), # Label sumbu X
yaxis = list(title = "TPT"), # Label sumbu Y
legend = list(title = list(text = "Kab/Kota")) # Judul untuk legenda
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
plot_ly(
data1,
x = ~factor(Wilayah),
y = ~TPAK,
text = ~paste('Kabupaten/Kota: ', Wilayah, '<br>Value: ', TPAK), # Menampilkan informasi saat hover
hoverinfo = 'text', # Tampilkan info saat hover
type = "bar",
color = ~factor(Wilayah) # Warna berdasarkan Wilayah
) %>%
layout(
title = list(text = "Tingkat Partisipasi Angkatan Kerja"), # Judul grafik
xaxis = list(title = "Kota/Kabupaten"), # Label sumbu X
yaxis = list(title = "TPAK"), # Label sumbu Y
legend = list(title = list(text = "Kab/Kota")) # Judul untuk legenda
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
plot_ly(
data1,
x = ~factor(Wilayah),
y = ~`Upah Minimum`,
text = ~paste('Kabupaten/Kota: ', Wilayah, '<br>Value: ', `Upah Minimum`), # Menampilkan informasi saat hover
hoverinfo = 'text', # Tampilkan info saat hover
type = "bar",
color = ~factor(Wilayah) # Warna berdasarkan Wilayah
) %>%
layout(
title = list(text = "Upah Minimum Kabupaten/Kota"), # Judul grafik
xaxis = list(title = "Kota/Kabupaten"), # Label sumbu X
yaxis = list(title = "UMK"), # Label sumbu Y
legend = list(title = list(text = "Kab/Kota")) # Judul untuk legenda
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
plot_ly(
data1,
x = ~factor(Wilayah),
y = ~`PDRB atas daasar harga berlaku (ribu rupiah)`,
text = ~paste('Kabupaten/Kota: ', Wilayah, '<br>Value: ', `PDRB atas daasar harga berlaku (ribu rupiah)`), # Menampilkan informasi saat hover
hoverinfo = 'text', # Tampilkan info saat hover
type = "bar",
color = ~factor(Wilayah) # Warna berdasarkan Wilayah
) %>%
layout(
title = list(text = "PDRB per Kapita (dalam ribu rupiah)"), # Judul grafik
xaxis = list(title = "Kota/Kabupaten"), # Label sumbu X
yaxis = list(title = "PDRB"), # Label sumbu Y
legend = list(title = list(text = "Kab/Kota")) # Judul untuk legenda
)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
Buat data baru
# Pastikan data adalah data frame, bukan tibble
data_klas <- as.data.frame(data1)
# Atur kolom pertama sebagai nama baris
row.names(data_klas) <- data_klas[, 1]
# Hapus kolom pertama (karena sudah menjadi nama baris)
data_klas <- data_klas[, -1]
data_klas = scale(data_klas)
data_klas2 = as.data.frame(data1[,2:5])
data_pengganti = data_klas2
data_pengganti = as.data.frame(data_pengganti)
head(data_klas)
## TPT TPAK Upah Minimum
## Bogor 0.63482318 -0.75704340 1.12884711
## Sukabumi 0.06628382 0.21590437 0.05063854
## Cianjur 0.25909282 1.47274340 -0.37263671
## Bandung -0.32922183 0.03674968 0.18037731
## Garut 0.07122764 0.86361747 -1.08869667
## Tasikmalaya -1.62944663 0.38679038 -0.73557593
## PDRB atas daasar harga berlaku (ribu rupiah)
## Bogor 0.04304526
## Sukabumi -0.64873767
## Cianjur -0.85460219
## Bandung -0.27152582
## Garut -0.72605798
## Tasikmalaya -0.81226059
str(data_pengganti)
## 'data.frame': 27 obs. of 4 variables:
## $ TPT : num 8.47 7.32 7.71 6.52 7.33 3.89 3.52 9.49 7.65 4.12 ...
## $ TPAK : num 64.2 67.8 72.3 67.1 70.1 ...
## $ Upah Minimum : num 4520212 3351883 2893229 3492466 2117318 ...
## $ PDRB atas daasar harga berlaku (ribu rupiah): num 51378 29374 22826 41372 26914 ...
Pengujian asumsi Multkiolinearitas dan KMO
library(psych)
## Warning: package 'psych' was built under R version 4.3.3
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(REdaS)
## Warning: package 'REdaS' was built under R version 4.3.3
## Loading required package: grid
cor(data_pengganti)
## TPT TPAK Upah Minimum
## TPT 1.0000000 -0.5534225 0.5465061
## TPAK -0.5534225 1.0000000 -0.4040098
## Upah Minimum 0.5465061 -0.4040098 1.0000000
## PDRB atas daasar harga berlaku (ribu rupiah) 0.4343346 -0.2290087 0.5850198
## PDRB atas daasar harga berlaku (ribu rupiah)
## TPT 0.4343346
## TPAK -0.2290087
## Upah Minimum 0.5850198
## PDRB atas daasar harga berlaku (ribu rupiah) 1.0000000
KMOS(data_pengganti)
##
## Kaiser-Meyer-Olkin Statistics
##
## Call: KMOS(x = data_pengganti)
##
## Measures of Sampling Adequacy (MSA):
## TPT
## 0.7193893
## TPAK
## 0.6905294
## Upah Minimum
## 0.7116839
## PDRB atas daasar harga berlaku (ribu rupiah)
## 0.6877714
##
## KMO-Criterion: 0.7044463
Penentuan Jumlah Klaster
#grafik wss dan siluet
library(cluster)
library(factoextra)
## Warning: package 'factoextra' was built under R version 4.3.3
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
fviz_nbclust(data_klas, FUN = pam , method = "wss")

fviz_nbclust(data_klas, pam, method = "silhouette")

#evaluasi jumlah klaster terbaik
library(clValid)
## Warning: package 'clValid' was built under R version 4.3.3
evaluasi = clValid(data_klas,nClust = 2:10,
clMethods = "pam",
validation = "internal",
metric = "euclidean")
summary(evaluasi)
##
## Clustering Methods:
## pam
##
## Cluster sizes:
## 2 3 4 5 6 7 8 9 10
##
## Validation Measures:
## 2 3 4 5 6 7 8 9 10
##
## pam Connectivity 7.1016 18.0575 21.9817 23.8984 27.5599 30.1500 34.3413 35.0913 39.4226
## Dunn 0.2199 0.2481 0.2481 0.3208 0.2580 0.3431 0.5458 0.5585 0.4626
## Silhouette 0.3574 0.2916 0.3054 0.3189 0.3592 0.3824 0.3649 0.3517 0.3654
##
## Optimal Scores:
##
## Score Method Clusters
## Connectivity 7.1016 pam 2
## Dunn 0.5585 pam 9
## Silhouette 0.3824 pam 7
library(cluster)
library(fpc)
## Warning: package 'fpc' was built under R version 4.3.3
medoids = pam(data_klas, k = 7)
medoids$clustering
## Bogor Sukabumi Cianjur Bandung
## 1 2 2 2
## Garut Tasikmalaya Ciamis Kuningan
## 2 3 3 4
## Cirebon Majalengka Sumedang Indramayu
## 2 3 2 4
## Subang Purwakarta Karawang Bekasi
## 2 1 5 5
## Bandung Barat Pangandaran Kota Bogor Kota Sukabumi
## 2 6 1 4
## Kota Bandung Kota Cirebon Kota Bekasi Kota Depok
## 5 7 1 1
## Kota Cimahi Kota Tasikmalaya Kota Banjar
## 7 2 3
plot = fviz_cluster(medoids, data = data_klas)
plot

Penentuan Anggota Klaster
member = data.frame(data_klas,medoids$clustering)
final_member =member[order(member$medoids.clustering),]
final_member
## TPT TPAK Upah.Minimum
## Bogor 0.63482318 -0.757043397 1.12884711
## Purwakarta 0.26403664 -0.164454816 1.07759381
## Kota Bogor 1.08965467 -0.594426065 1.23886829
## Kota Bekasi 0.35302541 -0.638525680 1.71766738
## Kota Depok -0.10674990 -1.159452387 1.28968515
## Sukabumi 0.06628382 0.215904367 0.05063854
## Cianjur 0.25909282 1.472743404 -0.37263671
## Bandung -0.32922183 0.036749679 0.18037731
## Garut 0.07122764 0.863617467 -1.08869667
## Cirebon 0.22942989 -0.222335561 -0.79941346
## Sumedang -0.12158136 0.218660593 0.16069088
## Subang 0.22942989 0.844323885 -0.02141183
## Bandung Barat 0.45684564 0.011943646 0.16960695
## Kota Tasikmalaya -0.31439037 -0.420783830 -0.70476438
## Tasikmalaya -1.62944663 0.386790376 -0.73557593
## Ciamis -1.81236799 -0.194773301 -1.17697864
## Majalengka -1.51573876 0.422621314 -1.03029361
## Kota Banjar -0.86809827 0.130461362 -1.19870135
## Kuningan 1.13909288 -1.382706689 -1.18705919
## Indramayu -0.35888475 -0.850755079 -0.69677635
## Kota Sukabumi 0.66448610 -1.211820680 -0.37263671
## Karawang 0.87212657 -0.983053925 1.73421513
## Bekasi 0.83257600 -0.542057772 1.69858924
## Kota Bandung 0.81280072 0.000918742 0.69348653
## Pangandaran -2.80113211 3.633624556 -1.17999495
## Kota Cirebon 0.23437372 0.480502059 -0.77566285
## Kota Cimahi 1.64830639 0.403327732 0.20033633
## PDRB.atas.daasar.harga.berlaku..ribu.rupiah.
## Bogor 0.04304526
## Purwakarta 0.91752164
## Kota Bogor 0.10153898
## Kota Bekasi -0.14863550
## Kota Depok -0.28898453
## Sukabumi -0.64873767
## Cianjur -0.85460219
## Bandung -0.27152582
## Garut -0.72605798
## Cirebon -0.75562708
## Sumedang -0.41612124
## Subang -0.62528617
## Bandung Barat -0.60950690
## Kota Tasikmalaya -0.41041045
## Tasikmalaya -0.81226059
## Ciamis -0.57140887
## Majalengka -0.59399424
## Kota Banjar -0.77732023
## Kuningan -0.72082254
## Indramayu 0.14648808
## Kota Sukabumi -0.23412383
## Karawang 2.04851897
## Bekasi 2.25219287
## Kota Bandung 2.83369071
## Pangandaran -0.53341678
## Kota Cirebon 1.07287780
## Kota Cimahi 0.58296829
## medoids.clustering
## Bogor 1
## Purwakarta 1
## Kota Bogor 1
## Kota Bekasi 1
## Kota Depok 1
## Sukabumi 2
## Cianjur 2
## Bandung 2
## Garut 2
## Cirebon 2
## Sumedang 2
## Subang 2
## Bandung Barat 2
## Kota Tasikmalaya 2
## Tasikmalaya 3
## Ciamis 3
## Majalengka 3
## Kota Banjar 3
## Kuningan 4
## Indramayu 4
## Kota Sukabumi 4
## Karawang 5
## Bekasi 5
## Kota Bandung 5
## Pangandaran 6
## Kota Cirebon 7
## Kota Cimahi 7
Rataan Setiap Klaster
library(dplyr)
terakhir = data_pengganti%>% mutate(Cluster = member$medoids.clustering)%>%
group_by(Cluster)%>%summarise_all("mean") #3 cluster
terakhir
## # A tibble: 7 × 5
## Cluster TPT TPAK `Upah Minimum` PDRB atas daasar harga berlaku (ribu rupi…¹
## <int> <dbl> <dbl> <dbl> <dbl>
## 1 1 8.09 64.6 4695412. 53982.
## 2 2 7.31 68.2 3004973. 31214.
## 3 3 4.24 67.6 2175083. 28101.
## 4 4 8.16 62.8 2481987. 41437.
## 5 5 8.88 65.1 4787406. 125653.
## 6 6 1.52 80.2 2018389 33042.
## 7 7 9.09 68.6 2985305. 76344.
## # ℹ abbreviated name: ¹`PDRB atas daasar harga berlaku (ribu rupiah)`