Analisis Studi Kasus: Data Pendidikan menerapkan teknik sains data

I. Data Preparation

1. Import Data

#membaca file csv
data_pendidikan <- read.csv("~/Nayla/R/DATA PENDIDIKAN.csv")

2. Struktur Data

#melihat struktur tipe data
str(data_pendidikan)
## 'data.frame':    39 obs. of  11 variables:
##  $ Provinsi                     : chr  "Prov. D.K.I. Jakarta" "Prov. Jawa Barat" "Prov. Jawa Tengah" "Prov. D.I. Yogyakarta" ...
##  $ Sekolah                      : int  2224 19553 18618 1846 18980 3532 9751 4206 3815 2464 ...
##  $ Siswa                        : int  756455 4487262 2595050 270610 2530849 489863 1524481 592365 776574 368620 ...
##  $ Mengulang                    : int  1202 4778 6909 357 4694 1406 4896 4643 4446 2006 ...
##  $ Putus.Sekolah                : int  869 5675 2399 75 3327 905 4390 858 1388 835 ...
##  $ Kepala.Sekolah.dan.Guru...S1.: int  38305 209252 167535 19771 180465 47490 108599 47064 50310 26403 ...
##  $ Rombongan.Belajar            : int  27830 169704 127266 13719 134724 25829 74970 31481 35120 18911 ...
##  $ Ruang.kelas.baik.            : int  23320 59592 51050 8217 58679 10261 33726 12164 15935 6857 ...
##  $ Ruang.kelas.rusak.ringan.    : int  3886 46006 42356 3878 42896 7483 21203 9121 8745 5787 ...
##  $ Ruang.kelas.rusak.sedang.    : int  717 34432 26321 1827 24218 6076 14880 7904 6458 4701 ...
##  $ Ruang.kelas.rusak.berat.     : int  345 14397 13457 548 14389 3122 9371 3600 3719 2377 ...

3. Summary Data

#menampilkan ringkasan statistik
summary(data_pendidikan)
##       Provinsi     Sekolah            Siswa           Mengulang   
##  Length   :39   Min.   :  124.0   Min.   :  17789   Min.   :  56  
##  N.unique :39   1st Qu.:  956.5   1st Qu.: 143176   1st Qu.:1258  
##  N.blank  : 0   Median : 2347.0   Median : 312352   Median :2049  
##  Min.nchar:10   Mean   : 3817.5   Mean   : 617044   Mean   :2841  
##  Max.nchar:31   3rd Qu.: 4326.5   3rd Qu.: 709881   3rd Qu.:4212  
##                 Max.   :19553.0   Max.   :4487262   Max.   :9801  
##  Putus.Sekolah  Kepala.Sekolah.dan.Guru...S1. Rombongan.Belajar
##  Min.   :  75   Min.   :   450                Min.   :   913   
##  1st Qu.: 466   1st Qu.: 10400                1st Qu.:  7654   
##  Median : 835   Median : 25737                Median : 17694   
##  Mean   :1155   Mean   : 40252                Mean   : 29318   
##  3rd Qu.:1280   3rd Qu.: 48900                3rd Qu.: 33301   
##  Max.   :5675   Max.   :209252                Max.   :169704   
##  Ruang.kelas.baik. Ruang.kelas.rusak.ringan. Ruang.kelas.rusak.sedang.
##  Min.   :  594     Min.   :  169             Min.   :    9            
##  1st Qu.: 2801     1st Qu.: 1895             1st Qu.: 1444            
##  Median : 7730     Median : 4432             Median : 3536            
##  Mean   :12033     Mean   : 8255             Mean   : 6110            
##  3rd Qu.:13262     3rd Qu.: 8933             3rd Qu.: 6850            
##  Max.   :59592     Max.   :46006             Max.   :34432            
##  Ruang.kelas.rusak.berat.
##  Min.   :    5.0         
##  1st Qu.:  683.5         
##  Median : 1924.0         
##  Mean   : 3102.8         
##  3rd Qu.: 3561.0         
##  Max.   :14397.0

4. Missing Value

#mengecek total missing value di setiap kolom
colSums(is.na(data_pendidikan))
##                      Provinsi                       Sekolah 
##                             0                             0 
##                         Siswa                     Mengulang 
##                             0                             0 
##                 Putus.Sekolah Kepala.Sekolah.dan.Guru...S1. 
##                             0                             0 
##             Rombongan.Belajar             Ruang.kelas.baik. 
##                             0                             0 
##     Ruang.kelas.rusak.ringan.     Ruang.kelas.rusak.sedang. 
##                             0                             0 
##      Ruang.kelas.rusak.berat. 
##                             0

5. Select Data

#memilih kolom spesifik
library(dplyr)
data_pilihan <- select(data_pendidikan,Provinsi,Sekolah,Putus.Sekolah,Rombongan.Belajar,Ruang.kelas.rusak.berat.)

#menampilkan 5 baris pertama hasil seleksi
head(data_pilihan)
##                Provinsi Sekolah Putus.Sekolah Rombongan.Belajar
## 1  Prov. D.K.I. Jakarta    2224           869             27830
## 2      Prov. Jawa Barat   19553          5675            169704
## 3     Prov. Jawa Tengah   18618          2399            127266
## 4 Prov. D.I. Yogyakarta    1846            75             13719
## 5      Prov. Jawa Timur   18980          3327            134724
## 6            Prov. Aceh    3532           905             25829
##   Ruang.kelas.rusak.berat.
## 1                      345
## 2                    14397
## 3                    13457
## 4                      548
## 5                    14389
## 6                     3122

6. Mutate

#menambahkan kolom proporsi baru
data_mutate <- data_pendidikan %>%
  mutate(Rata_rata_Ruang_Kelas = rowMeans(cbind(Ruang.kelas.rusak.ringan.,
                                    Ruang.kelas.rusak.sedang.,
                                    Ruang.kelas.rusak.berat.), na.rm = TRUE))
data_mutate
##                           Provinsi Sekolah   Siswa Mengulang Putus.Sekolah
## 1             Prov. D.K.I. Jakarta    2224  756455      1202           869
## 2                 Prov. Jawa Barat   19553 4487262      4778          5675
## 3                Prov. Jawa Tengah   18618 2595050      6909          2399
## 4            Prov. D.I. Yogyakarta    1846  270610       357            75
## 5                 Prov. Jawa Timur   18980 2530849      4694          3327
## 6                       Prov. Aceh    3532  489863      1406           905
## 7             Prov. Sumatera Utara    9751 1524481      4896          4390
## 8             Prov. Sumatera Barat    4206  592365      4643           858
## 9                       Prov. Riau    3815  776574      4446          1388
## 10                     Prov. Jambi    2464  368620      2006           835
## 11          Prov. Sumatera Selatan    4719  882011      6469          1976
## 12                   Prov. Lampung    4726  798892      2412           833
## 13          Prov. Kalimantan Barat    4447  563178      9801          1324
## 14         Prov. Kalimantan Tengah    2650  276421      2806           675
## 15        Prov. Kalimantan Selatan    2920  353174      3201           532
## 16          Prov. Kalimantan Timur    1929  419472      2063           669
## 17            Prov. Sulawesi Utara    2209  218823       728           435
## 18           Prov. Sulawesi Tengah    2944  312352      3004          1033
## 19          Prov. Sulawesi Selatan    6434  883153      3300          1613
## 20         Prov. Sulawesi Tenggara    2347  294170      1643           784
## 21                    Prov. Maluku    1815  206984      1933          1076
## 22                      Prov. Bali    2409  383616       183           179
## 23       Prov. Nusa Tenggara Barat    3330  512620      1501          1235
## 24       Prov. Nusa Tenggara Timur    5225  663307      8887          2771
## 25                     Prov. Papua     831  116836      1605           651
## 26                  Prov. Bengkulu    1407  194870      1313           390
## 27              Prov. Maluku Utara    1317  141138      1126           630
## 28                    Prov. Banten    4610 1203432      2551          1779
## 29 Prov. Kepulauan Bangka Belitung     833  161703      1202           332
## 30                 Prov. Gorontalo     931  108058      1446           458
## 31            Prov. Kepulauan Riau     982  227249       651           385
## 32               Prov. Papua Barat     569   71737      2049           474
## 33            Prov. Sulawesi Barat    1329  143300      1092           511
## 34          Prov. Kalimantan Utara     485   79877       364           188
## 35                     Luar Negeri     124   17789        56            89
## 36              Prov. Papua Tengah     553  143052      3741          1106
## 37             Prov. Papua Selatan     606   94976      5003           936
## 38          Prov. Papua Pegunungan     665  140165      3978           928
## 39          Prov. Papua Barat Daya     547   60227      1347           334
##    Kepala.Sekolah.dan.Guru...S1. Rombongan.Belajar Ruang.kelas.baik.
## 1                          38305             27830             23320
## 2                         209252            169704             59592
## 3                         167535            127266             51050
## 4                          19771             13719              8217
## 5                         180465            134724             58679
## 6                          47490             25829             10261
## 7                         108599             74970             33726
## 8                          47064             31481             12164
## 9                          50310             35120             15935
## 10                         26403             18911              6857
## 11                         59059             40713             15358
## 12                         55421             38340             13582
## 13                         38364             31317             10878
## 14                         25030             17694              6741
## 15                         29351             20814              9040
## 16                         25737             18585              9677
## 17                         18866             14384              6255
## 18                         26456             19335              7730
## 19                         69029             46819             16108
## 20                         26570             16878              5867
## 21                         16351             11920              4543
## 22                         25097             17327              8646
## 23                         42660             24116              7795
## 24                         52919             36988             12941
## 25                          6812              6031              2010
## 26                         16355             10570              4232
## 27                         11222              8480              2544
## 28                         56799             44351             20757
## 29                          9577              6827              3358
## 30                          8455              6090              3032
## 31                         13859              9871              5900
## 32                          4895              4056              1656
## 33                         13077              9037              2570
## 34                          6049              4141              1976
## 35                           450               913               594
## 36                          4311              5095              1683
## 37                          3857              4346              1210
## 38                          3086              5003              1319
## 39                          4914              3815              1484
##    Ruang.kelas.rusak.ringan. Ruang.kelas.rusak.sedang. Ruang.kelas.rusak.berat.
## 1                       3886                       717                      345
## 2                      46006                     34432                    14397
## 3                      42356                     26321                    13457
## 4                       3878                      1827                      548
## 5                      42896                     24218                    14389
## 6                       7483                      6076                     3122
## 7                      21203                     14880                     9371
## 8                       9121                      7904                     3600
## 9                       8745                      6458                     3719
## 10                      5787                      4701                     2377
## 11                     10839                      8665                     3522
## 12                     11111                      9451                     3884
## 13                      8540                      7243                     4087
## 14                      5247                      4401                     2089
## 15                      6053                      5091                     1638
## 16                      4432                      2326                     1497
## 17                      3707                      3126                     1924
## 18                      5247                      4750                     2887
## 19                     11949                     13128                     5990
## 20                      4370                      4196                     2704
## 21                      2456                      3536                     2230
## 22                      4835                      3042                     1142
## 23                      7818                      6377                     1520
## 24                     11971                     10040                     6707
## 25                      1358                      1824                      872
## 26                      3371                      3359                      717
## 27                      2167                      2919                     1269
## 28                     10581                      6117                     3434
## 29                      1740                      1285                     1047
## 30                      1491                      1603                      614
## 31                      2050                       862                      650
## 32                      1183                       737                      339
## 33                      2065                      2533                     2055
## 34                       887                       549                      582
## 35                       169                         9                        5
## 36                      1461                      1029                      301
## 37                      1252                       948                      596
## 38                      1224                       898                      875
## 39                      1006                       712                      509
##    Rata_rata_Ruang_Kelas
## 1              1649.3333
## 2             31611.6667
## 3             27378.0000
## 4              2084.3333
## 5             27167.6667
## 6              5560.3333
## 7             15151.3333
## 8              6875.0000
## 9              6307.3333
## 10             4288.3333
## 11             7675.3333
## 12             8148.6667
## 13             6623.3333
## 14             3912.3333
## 15             4260.6667
## 16             2751.6667
## 17             2919.0000
## 18             4294.6667
## 19            10355.6667
## 20             3756.6667
## 21             2740.6667
## 22             3006.3333
## 23             5238.3333
## 24             9572.6667
## 25             1351.3333
## 26             2482.3333
## 27             2118.3333
## 28             6710.6667
## 29             1357.3333
## 30             1236.0000
## 31             1187.3333
## 32              753.0000
## 33             2217.6667
## 34              672.6667
## 35               61.0000
## 36              930.3333
## 37              932.0000
## 38              999.0000
## 39              742.3333

7. Filter and Sort Data

#memfilter data pendidikan prov aceh
data_provaceh <- filter(data_pendidikan, Provinsi =="Prov. Aceh")
head(data_provaceh)
##     Provinsi Sekolah  Siswa Mengulang Putus.Sekolah
## 1 Prov. Aceh    3532 489863      1406           905
##   Kepala.Sekolah.dan.Guru...S1. Rombongan.Belajar Ruang.kelas.baik.
## 1                         47490             25829             10261
##   Ruang.kelas.rusak.ringan. Ruang.kelas.rusak.sedang. Ruang.kelas.rusak.berat.
## 1                      7483                      6076                     3122

8. join data

library(dplyr)

#membuat kolom (True jika > 10000, False jika tidak)
data_join <- data_pendidikan %>%
  mutate(Sekolah_terbanyak_lebih_dari_10.000 = if_else(Sekolah > 10000, "True", "False"))

#melihat hasilnya
head(data_join)
##                Provinsi Sekolah   Siswa Mengulang Putus.Sekolah
## 1  Prov. D.K.I. Jakarta    2224  756455      1202           869
## 2      Prov. Jawa Barat   19553 4487262      4778          5675
## 3     Prov. Jawa Tengah   18618 2595050      6909          2399
## 4 Prov. D.I. Yogyakarta    1846  270610       357            75
## 5      Prov. Jawa Timur   18980 2530849      4694          3327
## 6            Prov. Aceh    3532  489863      1406           905
##   Kepala.Sekolah.dan.Guru...S1. Rombongan.Belajar Ruang.kelas.baik.
## 1                         38305             27830             23320
## 2                        209252            169704             59592
## 3                        167535            127266             51050
## 4                         19771             13719              8217
## 5                        180465            134724             58679
## 6                         47490             25829             10261
##   Ruang.kelas.rusak.ringan. Ruang.kelas.rusak.sedang. Ruang.kelas.rusak.berat.
## 1                      3886                       717                      345
## 2                     46006                     34432                    14397
## 3                     42356                     26321                    13457
## 4                      3878                      1827                      548
## 5                     42896                     24218                    14389
## 6                      7483                      6076                     3122
##   Sekolah_terbanyak_lebih_dari_10.000
## 1                               False
## 2                                True
## 3                                True
## 4                               False
## 5                                True
## 6                               False

9. Group and Summarize

library(dplyr)

#mengelompokan berdasarkan provinsi dan menghitung ringkasan
data_summary <- data_pendidikan %>%
  group_by(Provinsi) %>%
  summarise(Total_Siswa = sum(Siswa, na.rm = TRUE),
            Rata_rata_Siswa = mean(Siswa, na.rm = TRUE))
head(data_summary)
## # A tibble: 6 × 3
##   Provinsi              Total_Siswa Rata_rata_Siswa
##   <chr>                       <int>           <dbl>
## 1 Luar Negeri                 17789           17789
## 2 Prov. Aceh                 489863          489863
## 3 Prov. Bali                 383616          383616
## 4 Prov. Banten              1203432         1203432
## 5 Prov. Bengkulu             194870          194870
## 6 Prov. D.I. Yogyakarta      270610          270610

10. Split Data

#menggunakan fungsi bawaan split() berdasarkan kolom provinsi
data_list <- split(data_pendidikan, data_pendidikan$Provinsi)
head(data_list[[1]])
##       Provinsi Sekolah Siswa Mengulang Putus.Sekolah
## 35 Luar Negeri     124 17789        56            89
##    Kepala.Sekolah.dan.Guru...S1. Rombongan.Belajar Ruang.kelas.baik.
## 35                           450               913               594
##    Ruang.kelas.rusak.ringan. Ruang.kelas.rusak.sedang. Ruang.kelas.rusak.berat.
## 35                       169                         9                        5

II. Data Wrangling

library(tidyverse)
data_pendidikan <- read.csv("~/Nayla/R/DATA PENDIDIKAN.csv")
data_prov <- data_pendidikan %>%
  filter(Provinsi != "Luar Negeri")

1. Berapa proporsi ruang kelas kondisi baik vs rusak (ringan, sedang, berat) secara agregat nasional?

proporsi_nasional <- data_prov %>%
  summarise(
    Baik = sum(`Ruang.kelas.baik.`, na.rm = TRUE), 
    Rusak_Ringan = sum(`Ruang.kelas.rusak.ringan.`, na.rm = TRUE), 
    Rusak_Sedang = sum(`Ruang.kelas.rusak.sedang.`, na.rm = TRUE), 
    Rusak_Berat = sum(`Ruang.kelas.rusak.berat.`, na.rm = TRUE)
    ) %>%
pivot_longer(cols = everything(), names_to = "Kondisi", values_to = "Jumlah") %>%
mutate(Persentase = (Jumlah/sum(Jumlah)) * 100)
print("1. Proporsi Ruang Kelas Secara Nasional:")
## [1] "1. Proporsi Ruang Kelas Secara Nasional:"
print(proporsi_nasional)
## # A tibble: 4 × 3
##   Kondisi      Jumlah Persentase
##   <chr>         <int>      <dbl>
## 1 Baik         468693       40.8
## 2 Rusak_Ringan 321772       28.0
## 3 Rusak_Sedang 238281       20.7
## 4 Rusak_Berat  121006       10.5

2. Provinsi mana yang memiliki persentase kerusakan ruang kelas terparah?

kerusakan_provinsi <- data_prov %>%
  mutate(
    Total_Kelas = `Ruang.kelas.baik.` + `Ruang.kelas.rusak.ringan.` + 
                  `Ruang.kelas.rusak.sedang.` + `Ruang.kelas.rusak.berat.`,
    Pct_Rusak_Berat = (`Ruang.kelas.rusak.berat.` / Total_Kelas) * 100,
    Pct_Total_Rusak = ((`Ruang.kelas.rusak.ringan.` + `Ruang.kelas.rusak.sedang.` + `Ruang.kelas.rusak.berat.`) / Total_Kelas) * 100
  ) %>%
  select(Provinsi, Total_Kelas, Pct_Rusak_Berat, Pct_Total_Rusak) %>%
  arrange(desc(Pct_Rusak_Berat))

print("2. Top 5 Provinsi dengan Kerusakan Ruang Kelas Terparah (Rusak Berat):")
## [1] "2. Top 5 Provinsi dengan Kerusakan Ruang Kelas Terparah (Rusak Berat):"
print(head(kerusakan_provinsi, 5))
##                    Provinsi Total_Kelas Pct_Rusak_Berat Pct_Total_Rusak
## 1      Prov. Sulawesi Barat        9223        22.28125        72.13488
## 2    Prov. Papua Pegunungan        4316        20.27340        69.43930
## 3              Prov. Maluku       12765        17.46964        64.41050
## 4 Prov. Nusa Tenggara Timur       41659        16.09976        68.93588
## 5   Prov. Sulawesi Tenggara       17137        15.77872        65.76414

3. Manakah Provinsi dengan kepadatan siswa per rombongan belajar (rombel) terparah?

kepadatan_rombel <- data_prov %>%
  mutate(Siswa_per_Rombel = `Siswa` / `Rombongan.Belajar`) %>%
  select(Provinsi, Siswa, `Rombongan.Belajar`, Siswa_per_Rombel) %>%
  arrange(desc(Siswa_per_Rombel))

print("3. Top 5 Provinsi Kepadatan Siswa per Rombel Terparah:")
## [1] "3. Top 5 Provinsi Kepadatan Siswa per Rombel Terparah:"
print(head(kepadatan_rombel, 5))
##                 Provinsi   Siswa Rombongan.Belajar Siswa_per_Rombel
## 1     Prov. Papua Tengah  143052              5095         28.07694
## 2 Prov. Papua Pegunungan  140165              5003         28.01619
## 3   Prov. D.K.I. Jakarta  756455             27830         27.18128
## 4           Prov. Banten 1203432             44351         27.13427
## 5       Prov. Jawa Barat 4487262            169704         26.44170

4. Apa Provinsi dengan Tingkat Putus Sekolah (Dropout Rate) tertinggi?

dropout_rate <- data_prov %>%
  mutate(Pct_Putus_Sekolah = (`Putus.Sekolah` / `Siswa`) * 100) %>%
  select(Provinsi, Siswa, `Putus.Sekolah`, Pct_Putus_Sekolah) %>%
  arrange(desc(Pct_Putus_Sekolah))

print("4. Top 5 Provinsi dengan Tingkat Putus Sekolah Tertinggi:")
## [1] "4. Top 5 Provinsi dengan Tingkat Putus Sekolah Tertinggi:"
print(head(dropout_rate, 5))
##                 Provinsi  Siswa Putus.Sekolah Pct_Putus_Sekolah
## 1    Prov. Papua Selatan  94976           936         0.9855121
## 2     Prov. Papua Tengah 143052          1106         0.7731454
## 3 Prov. Papua Pegunungan 140165           928         0.6620768
## 4      Prov. Papua Barat  71737           474         0.6607469
## 5            Prov. Papua 116836           651         0.5571913

5. Bagaimana analisis korelasi antara tingkat mengulang dan tingkat putus sekolah?

korelasi_data <- data_prov %>%
  mutate(
    Pct_Mengulang = (`Mengulang` / `Siswa`) * 100,
    Pct_Putus_Sekolah = (`Putus.Sekolah` / `Siswa`) * 100
  )

# Menghitung koefisien korelasi Pearson
nilai_korelasi <- cor(korelasi_data$Pct_Mengulang, korelasi_data$Pct_Putus_Sekolah)

print(paste("5. Nilai Korelasi antara % Mengulang dan % Putus Sekolah:", round(nilai_korelasi, 4)))
## [1] "5. Nilai Korelasi antara % Mengulang dan % Putus Sekolah: 0.902"

III. Visualisasi Data

Proporsi Kondisi Ruang Kelas Secara Nasional

# Visualisasi Bar Chart (Grafik Batang)
ggplot(proporsi_nasional, aes(x = reorder(Kondisi, -Jumlah), y = Persentase, fill = Kondisi)) +
  geom_bar(stat = "identity", show.legend = FALSE, width = 0.6) +
  geom_text(aes(label = paste0(round(Persentase, 1), "%")), vjust = -0.5, fontface = "bold") +
  scale_fill_manual(values = c(
    "Baik" = "#2ecc71", 
    "Rusak_Ringan" = "#f1c40f", 
    "Rusak_Sedang" = "#e67e22", 
    "Rusak_Berat" = "#e74c3c")) +
  scale_y_continuous(limits = c(0, 50)) +
  labs(
    title = "Proporsi Kondisi Ruang Kelas Secara Nasional",
    x = "Kondisi Ruang Kelas",
    y = "Persentase (%)"
  ) +
  theme_minimal()

Distribusi Persentase Kelayakan Ruang Kelas

#Visualisai Donut Chart / Pie Chart
ggplot(proporsi_nasional, aes(x = 2, y = Persentase, fill = Kondisi)) +
  geom_bar(stat = "identity", width = 1, color = "white") +
  coord_polar(theta = "y") +
  xlim(0.5, 2.5) + # Membuat efek donut hole di tengah
  geom_text(aes(label = paste0(Kondisi, "\n", round(Persentase, 1), "%")), 
            position = position_stack(vjust = 0.5), color = "white", fontface = "bold") +
  scale_fill_manual(values = c("Baik" = "#2ecc71", "Rusak_Ringan" = "#f1c40f", 
                               "Rusak_Sedang" = "#e67e22", "Rusak_Berat" = "#e0392b")) +
  labs(title = "Distribusi Persentase Kelayakan Ruang Kelas") +
  theme_void()

Korelasi antara Siswa mengulang dan putus sekolah

# Visualisasi hubungan (Scatter Plot)
ggplot(korelasi_data, aes(x = Pct_Mengulang, y = Pct_Putus_Sekolah, label = Provinsi)) +
  geom_point(color = "red", size = 3) +
  geom_smooth(method = "lm", se = FALSE, color = "blue", linetype = "dashed") +
  labs(
    title = "Hubungan Antara % Siswa Mengulang dan % Putus Sekolah",
    x = "Tingkat Mengulang (%)",
    y = "Tingkat Putus Sekolah (%)"
  ) +
  theme_minimal()
## Warning: The following aesthetics were dropped during statistical transformation: label.
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?