#================================================
# MEMASUKKAN DATA
#================================================

umur <- c("15-19","20-24","25-29","30-34","35-39",
          "40-44","45-49","50-54","55-59","60+")

bekerja <- c(4936027,13977178,16577144,16913459,17165872,
             16653869,16019919,14211997,11549858,18536941)

pernah_bekerja <- c(181379,972616,699549,455146,301281,
                    241624,259237,206099,152653,250649)

belum_pernah_bekerja <- c(1321177,1368395,484539,152022,112418,
                          73380,61591,45710,50832,71210)

data_kerja <- data.frame(
  Umur = umur,
  Bekerja = bekerja,
  Pernah_Bekerja = pernah_bekerja,
  Belum_Pernah_Bekerja = belum_pernah_bekerja
)

# Menampilkan tabel data
knitr::kable(data_kerja, caption = "Data Status Pekerjaan Berdasarkan Kelompok Umur")
Data Status Pekerjaan Berdasarkan Kelompok Umur
Umur Bekerja Pernah_Bekerja Belum_Pernah_Bekerja
15-19 4936027 181379 1321177
20-24 13977178 972616 1368395
25-29 16577144 699549 484539
30-34 16913459 455146 152022
35-39 17165872 301281 112418
40-44 16653869 241624 73380
45-49 16019919 259237 61591
50-54 14211997 206099 45710
55-59 11549858 152653 50832
60+ 18536941 250649 71210
#================================================
# MENGHITUNG ANGKATAN KERJA
#================================================

angkatan_kerja <- bekerja + pernah_bekerja


#================================================
# MEMANGGIL LIBRARY
#================================================

library(ggplot2)
library(tidyr)
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
#================================================
# PIE CHART STATUS PEKERJAAN
#================================================

data_long <- data_kerja %>%
  pivot_longer(cols = Bekerja:Belum_Pernah_Bekerja,
               names_to = "Status",
               values_to = "Jumlah")

ggplot(data_long, aes(x="", y=Jumlah, fill=Status))+
  geom_bar(stat="identity", width=1)+
  coord_polar("y")+
  facet_wrap(~Umur)+
  theme_void()+
  labs(title="Pie Chart Status Pekerjaan per Kelompok Umur")

#================================================
# BAR CHART ANGKATAN KERJA
#================================================

barplot(angkatan_kerja,
        names.arg = umur,
        col = "skyblue",
        main = "Angkatan Kerja Berdasarkan Kelompok Umur",
        xlab = "Kelompok Umur",
        ylab = "Jumlah Penduduk")

#================================================
# BAR CHART STATUS PEKERJAAN
#================================================

data_matrix <- rbind(bekerja, pernah_bekerja, belum_pernah_bekerja)

barplot(data_matrix,
        beside = TRUE,
        col = c("blue","green","red"),
        names.arg = umur,
        legend.text = c("Bekerja","Pernah Bekerja","Belum Pernah Bekerja"),
        main = "Perbandingan Status Pekerjaan",
        xlab = "Kelompok Umur",
        ylab = "Jumlah Penduduk")

#================================================
# HISTOGRAM
#================================================

hist(angkatan_kerja,
     col="orange",
     main="Histogram Angkatan Kerja",
     xlab="Jumlah Angkatan Kerja")

#================================================
# DENSITY PLOT
#================================================

plot(density(angkatan_kerja),
     col="blue",
     lwd=2,
     main="Density Plot Angkatan Kerja",
     xlab="Jumlah Angkatan Kerja")

#================================================
# BOXPLOT
#================================================

boxplot(bekerja, pernah_bekerja, belum_pernah_bekerja,
        col=c("blue","green","red"),
        names=c("Bekerja","Pernah Bekerja","Belum Pernah Bekerja"),
        main="Boxplot Status Pekerjaan",
        ylab="Jumlah Penduduk")

#================================================
# STATISTIK DESKRIPTIF
#================================================

# fungsi mencari modus
modus <- function(x){
  uniqv <- unique(x)
  uniqv[which.max(tabulate(match(x, uniqv)))]
}

Mean <- mean(angkatan_kerja)
Median <- median(angkatan_kerja)
Modus <- modus(angkatan_kerja)

Q1 <- quantile(angkatan_kerja,0.25)
Q3 <- quantile(angkatan_kerja,0.75)

Range <- max(angkatan_kerja) - min(angkatan_kerja)
Varians <- var(angkatan_kerja)
Std_Deviation <- sd(angkatan_kerja)

tabel_statistik <- data.frame(
Mean,
Median,
Modus,
Q1,
Q3,
Range,
Varians,
Standard_Deviation = Std_Deviation
)

# Menampilkan tabel statistik
knitr::kable(tabel_statistik,
             caption = "Tabel Statistik Deskriptif Angkatan Kerja")
Tabel Statistik Deskriptif Angkatan Kerja
Mean Median Modus Q1 Q3 Range Varians Standard_Deviation
25% 15026250 16587325 5117406 14551021 17345627 13670184 1.614764e+13 4018413
#================================================
# STATISTIK INFERENSIA (UJI KORELASI)
#================================================

umur_index <- 1:length(umur)

hasil_korelasi <- cor.test(umur_index, angkatan_kerja)

hasil_korelasi
## 
##  Pearson's product-moment correlation
## 
## data:  umur_index and angkatan_kerja
## t = 1.1449, df = 8, p-value = 0.2854
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.3331167  0.8128131
## sample estimates:
##       cor 
## 0.3752047