The aim of this project is to perform kmeans clustering on dataset that contains information on average score of 8th grade exam in Poland together with some variables like school financing, number of teachers in each county (powiat), etc. The result is a cartogam with counties that are similar to each other. The data set was prepared by me using data from OKE (Okręgowe Komisje Egzaminacyjne) and GUS.
Warning: package 'factoextra' was built under R version 4.3.2
Loading required package: ggplot2
Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(flexclust)
Warning: package 'flexclust' was built under R version 4.3.2
Loading required package: grid
Loading required package: lattice
Loading required package: modeltools
Loading required package: stats4
library(fpc)
Warning: package 'fpc' was built under R version 4.3.2
library(clustertend)
Package `clustertend` is deprecated. Use package `hopkins` instead.
library(cluster)
Warning: package 'cluster' was built under R version 4.3.2
library(ClusterR)
Warning: package 'ClusterR' was built under R version 4.3.2
Now, we need to load the data set and check the structure. X1 variable is the amount of books per school in a county, X2 is the expenditure per school in a county, X3 is the number of full-time teacher positions in a school and X4 is the amount of students in a class. O1 is the average exam score of 8th graders in Poland. The variables x1, x2, x3 and x4 are for the year 2021 and the exam score is from 2022 as, in literature it is assumed, that inputs from year t have an influence on output of year t+1.
Some data manipulation has been already done in excel. But we still need to make e correction to data. Initial territorial values did not have 0 in front if the length was less equal to 6.
library(RColorBrewer)library(ggplot2)ggplot(shp_merged$geometry)+geom_sf(aes(fill=as.factor(shp_merged$cluster))) +scale_fill_brewer(name="clusters", type ="seq", palette ="Dark2")
As we can see the city counties and counties located nearby have been classified as 1 cluster. The second one are more rural areas. We can see there is a significant difference when it comes to education system in Poland.
$`1`
x1_ksiegozbior_na_szkole x2_wydatki_na_szkole x3_etaty_na_szkole
Min. : 3238 Min. :1488178 Min. :10.17
1st Qu.: 6244 1st Qu.:2069560 1st Qu.:13.57
Median : 7469 Median :2284001 Median :14.72
Mean : 7795 Mean :2321420 Mean :15.05
3rd Qu.: 8859 3rd Qu.:2546151 3rd Qu.:16.47
Max. :14770 Max. :3537927 Max. :21.98
x4_uczniowie_na_odział o1_wyniki_e8
Min. :11.00 Min. :43.78
1st Qu.:14.00 1st Qu.:52.09
Median :15.00 Median :54.97
Mean :15.36 Mean :55.40
3rd Qu.:16.00 3rd Qu.:58.30
Max. :18.00 Max. :74.78
$`2`
x1_ksiegozbior_na_szkole x2_wydatki_na_szkole x3_etaty_na_szkole
Min. : 5320 Min. :2418552 Min. :17.95
1st Qu.: 8026 1st Qu.:3067690 1st Qu.:20.97
Median :11252 Median :3403088 Median :23.65
Mean :12086 Mean :3486557 Mean :24.34
3rd Qu.:15237 3rd Qu.:3898023 3rd Qu.:26.64
Max. :34157 Max. :5622205 Max. :36.55
x4_uczniowie_na_odział o1_wyniki_e8
Min. :15.00 Min. :49.87
1st Qu.:18.00 1st Qu.:58.07
Median :18.00 Median :62.21
Mean :18.26 Mean :62.37
3rd Qu.:19.00 3rd Qu.:66.59
Max. :20.00 Max. :77.97
As we can see from descriptive statistics counties classified as 2, which are the city counties or located nearby cities have, on average, all variables higher. It means that those counties have higher expenditures per school, more books in schools, have more teachers, classes are more populated and they have higher average exam scores.