install.packages(c(
"tidyverse", "rmarkdown", "WDI", "jsonlite", "httr2",
"rvest", "xml2", "readxl", "writexl", "skimr", "janitor",
"knitr", "kableExtra", "here", "scales", "plotly", "maps", "DT",
"htmltools"
))library(tidyverse)
library(rmarkdown)
library(WDI)
library(jsonlite)
library(httr2)
library(rvest)
library(xml2)
library(readxl)
library(writexl)
library(skimr)
library(janitor)
library(knitr)
library(kableExtra)
library(here)
library(scales)
library(plotly)
library(maps)
library(DT)
library(htmltools)theme_praktikum <- function(base_size = 13) {
theme_minimal(base_size = base_size) +
theme(
plot.title = element_text(face = "bold", color = "#1B5E20", size = rel(1.15)),
plot.subtitle = element_text(color = "#C0392B"),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(color = "#FDEDEC"),
legend.position = "right"
)
}happiness_demo <- read_csv(
here("world_happiness_report_2019.csv"),
show_col_types = FALSE
)
head(happiness_demo)## [1] 156 9
## Rows: 156
## Columns: 9
## $ `Overall rank` <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, …
## $ `Country or region` <chr> "Finland", "Denmark", "Norway", "Icelan…
## $ Score <dbl> 7.769, 7.600, 7.554, 7.494, 7.488, 7.48…
## $ `GDP per capita` <dbl> 1.340, 1.383, 1.488, 1.380, 1.396, 1.45…
## $ `Social support` <dbl> 1.587, 1.573, 1.582, 1.624, 1.522, 1.52…
## $ `Healthy life expectancy` <dbl> 0.986, 0.996, 1.028, 1.026, 0.999, 1.05…
## $ `Freedom to make life choices` <dbl> 0.596, 0.592, 0.603, 0.591, 0.557, 0.57…
## $ Generosity <dbl> 0.153, 0.252, 0.271, 0.354, 0.322, 0.26…
## $ `Perceptions of corruption` <dbl> 0.393, 0.410, 0.341, 0.118, 0.298, 0.34…
## [1] "overall_rank" "country_or_region"
## [3] "score" "gdp_per_capita"
## [5] "social_support" "healthy_life_expectancy"
## [7] "freedom_to_make_life_choices" "generosity"
## [9] "perceptions_of_corruption"
## overall_rank country_or_region
## 0 0
## score gdp_per_capita
## 0 0
## social_support healthy_life_expectancy
## 0 0
## freedom_to_make_life_choices generosity
## 0 0
## perceptions_of_corruption
## 0
| Name | happiness_demo |
| Number of rows | 156 |
| Number of columns | 9 |
| _______________________ | |
| Column type frequency: | |
| character | 1 |
| numeric | 8 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| country_or_region | 0 | 1 | 4 | 24 | 0 | 156 | 0 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| overall_rank | 0 | 1 | 78.50 | 45.18 | 1.00 | 39.75 | 78.50 | 117.25 | 156.00 | ▇▇▇▇▇ |
| score | 0 | 1 | 5.41 | 1.11 | 2.85 | 4.54 | 5.38 | 6.18 | 7.77 | ▂▇▇▇▃ |
| gdp_per_capita | 0 | 1 | 0.91 | 0.40 | 0.00 | 0.60 | 0.96 | 1.23 | 1.68 | ▃▅▇▇▃ |
| social_support | 0 | 1 | 1.21 | 0.30 | 0.00 | 1.06 | 1.27 | 1.45 | 1.62 | ▁▁▂▆▇ |
| healthy_life_expectancy | 0 | 1 | 0.73 | 0.24 | 0.00 | 0.55 | 0.79 | 0.88 | 1.14 | ▁▃▃▇▅ |
| freedom_to_make_life_choices | 0 | 1 | 0.39 | 0.14 | 0.00 | 0.31 | 0.42 | 0.51 | 0.63 | ▁▃▆▇▆ |
| generosity | 0 | 1 | 0.18 | 0.10 | 0.00 | 0.11 | 0.18 | 0.25 | 0.57 | ▆▇▆▁▁ |
| perceptions_of_corruption | 0 | 1 | 0.11 | 0.09 | 0.00 | 0.05 | 0.09 | 0.14 | 0.45 | ▇▅▁▁▁ |
happiness2_demo <- happiness_demo %>%
select(
country_or_region,
score,
gdp_per_capita,
social_support,
healthy_life_expectancy,
freedom_to_make_life_choices
)
head(happiness2_demo)happiness2_demo %>%
slice_max(score, n = 10) %>%
ggplot(aes(
x = reorder(country_or_region, score),
y = score,
fill = score
)) +
geom_col() +
coord_flip() +
scale_fill_gradient(low = "#E74C3C", high = "#27AE60", guide = "none") +
labs(
title = "10 Negara dengan Happiness Score Tertinggi (2019)",
x = NULL,
y = "Happiness Score"
) +
theme_praktikum()Package yang digunakan dalam tugas ini sudah diinstal dan dipanggil pada bagian Persiapan Library. Daftar package yang aktif dan digunakan:
## [1] "base" "datasets" "dplyr" "DT" "forcats"
## [6] "ggplot2" "graphics" "grDevices" "here" "htmltools"
## [11] "httr2" "janitor" "jsonlite" "kableExtra" "knitr"
## [16] "lubridate" "maps" "methods" "plotly" "purrr"
## [21] "readr" "readxl" "rmarkdown" "rvest" "scales"
## [26] "skimr" "stats" "stringr" "tibble" "tidyr"
## [31] "tidyverse" "utils" "WDI" "writexl" "xml2"
## [1] "Python 3.13.14"
## [1] "Authentication required to call the Kaggle API."
## [2] ""
## [3] "First, you will need a Kaggle account. You can sign up at"
## [4] " https://www.kaggle.com/account/login"
## [5] ""
## [6] "Recommended: log in with OAuth via a web-based authorization flow."
## [7] "No token to manage; credentials are cached locally for you."
## [8] " kaggle auth login"
## [9] ""
## [10] "If you'd rather not use OAuth, generate an API token at"
## [11] " https://www.kaggle.com/settings/api (click \"Generate New Token\" under \"API\")"
## [12] "and supply it to the CLI in one of these ways:"
## [13] ""
## [14] " Option A: Environment variable"
## [15] " export KAGGLE_API_TOKEN=xxxxxxxxxxxxxx # token copied from the settings UI"
## [16] ""
## [17] " Option B: API token file"
## [18] " Save the token to ~/.kaggle/access_token"
## [19] "Kaggle CLI 2.2.4"
hasil_pencarian <- system2(
"python",
c("-m", "kaggle", "datasets", "list", "-s", "world-happiness"),
stdout = TRUE,
stderr = TRUE
)
cat(hasil_pencarian, sep = "\n")## Authentication required to call the Kaggle API.
##
## First, you will need a Kaggle account. You can sign up at
## https://www.kaggle.com/account/login
##
## Recommended: log in with OAuth via a web-based authorization flow.
## No token to manage; credentials are cached locally for you.
## kaggle auth login
##
## If you'd rather not use OAuth, generate an API token at
## https://www.kaggle.com/settings/api (click "Generate New Token" under "API")
## and supply it to the CLI in one of these ways:
##
## Option A: Environment variable
## export KAGGLE_API_TOKEN=xxxxxxxxxxxxxx # token copied from the settings UI
##
## Option B: API token file
## Save the token to ~/.kaggle/access_token
## Authentication required to call the Kaggle API.
##
## First, you will need a Kaggle account. You can sign up at
## https://www.kaggle.com/account/login
##
## Recommended: log in with OAuth via a web-based authorization flow.
## No token to manage; credentials are cached locally for you.
## kaggle auth login
##
## If you'd rather not use OAuth, generate an API token at
## https://www.kaggle.com/settings/api (click "Generate New Token" under "API")
## and supply it to the CLI in one of these ways:
##
## Option A: Environment variable
## export KAGGLE_API_TOKEN=xxxxxxxxxxxxxx # token copied from the settings UI
##
## Option B: API token file
## Save the token to ~/.kaggle/access_token
system2(
"python",
c(
"-m", "kaggle", "datasets", "download",
"-d", "unsdsn/world-happiness",
"-p", "data",
"--force"
),
stdout = TRUE,
stderr = TRUE
)## [1] "Authentication required to call the Kaggle API."
## [2] ""
## [3] "First, you will need a Kaggle account. You can sign up at"
## [4] " https://www.kaggle.com/account/login"
## [5] ""
## [6] "Recommended: log in with OAuth via a web-based authorization flow."
## [7] "No token to manage; credentials are cached locally for you."
## [8] " kaggle auth login"
## [9] ""
## [10] "If you'd rather not use OAuth, generate an API token at"
## [11] " https://www.kaggle.com/settings/api (click \"Generate New Token\" under \"API\")"
## [12] "and supply it to the CLI in one of these ways:"
## [13] ""
## [14] " Option A: Environment variable"
## [15] " export KAGGLE_API_TOKEN=xxxxxxxxxxxxxx # token copied from the settings UI"
## [16] ""
## [17] " Option B: API token file"
## [18] " Save the token to ~/.kaggle/access_token"
## [19] "Dataset URL: https://www.kaggle.com/datasets/unsdsn/world-happiness"
## [20] "License(s): CC0-1.0"
## [21] "Downloading world-happiness.zip to data"
## [22] "\r 0%| | 0.00/36.8k [00:00<?, ?B/s]\r100%|██████████| 36.8k/36.8k [00:00<00:00, 25.4MB/s]"
## [23] ""
## [1] "2015.csv" "2016.csv" "2017.csv"
## [4] "2018.csv" "2019.csv" "world-happiness.zip"
happiness_kaggle <- read_csv(
"data/2019.csv",
show_col_types = FALSE
) |>
clean_names()
head(happiness_kaggle)## [1] 156 9
## Rows: 156
## Columns: 9
## $ overall_rank <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13…
## $ country_or_region <chr> "Finland", "Denmark", "Norway", "Iceland"…
## $ score <dbl> 7.769, 7.600, 7.554, 7.494, 7.488, 7.480,…
## $ gdp_per_capita <dbl> 1.340, 1.383, 1.488, 1.380, 1.396, 1.452,…
## $ social_support <dbl> 1.587, 1.573, 1.582, 1.624, 1.522, 1.526,…
## $ healthy_life_expectancy <dbl> 0.986, 0.996, 1.028, 1.026, 0.999, 1.052,…
## $ freedom_to_make_life_choices <dbl> 0.596, 0.592, 0.603, 0.591, 0.557, 0.572,…
## $ generosity <dbl> 0.153, 0.252, 0.271, 0.354, 0.322, 0.263,…
## $ perceptions_of_corruption <dbl> 0.393, 0.410, 0.341, 0.118, 0.298, 0.343,…
## overall_rank country_or_region score gdp_per_capita
## Min. : 1.00 Length:156 Min. :2.853 Min. :0.0000
## 1st Qu.: 39.75 Class :character 1st Qu.:4.545 1st Qu.:0.6028
## Median : 78.50 Mode :character Median :5.380 Median :0.9600
## Mean : 78.50 Mean :5.407 Mean :0.9051
## 3rd Qu.:117.25 3rd Qu.:6.184 3rd Qu.:1.2325
## Max. :156.00 Max. :7.769 Max. :1.6840
## social_support healthy_life_expectancy freedom_to_make_life_choices
## Min. :0.000 Min. :0.0000 Min. :0.0000
## 1st Qu.:1.056 1st Qu.:0.5477 1st Qu.:0.3080
## Median :1.272 Median :0.7890 Median :0.4170
## Mean :1.209 Mean :0.7252 Mean :0.3926
## 3rd Qu.:1.452 3rd Qu.:0.8818 3rd Qu.:0.5072
## Max. :1.624 Max. :1.1410 Max. :0.6310
## generosity perceptions_of_corruption
## Min. :0.0000 Min. :0.0000
## 1st Qu.:0.1087 1st Qu.:0.0470
## Median :0.1775 Median :0.0855
## Mean :0.1848 Mean :0.1106
## 3rd Qu.:0.2482 3rd Qu.:0.1412
## Max. :0.5660 Max. :0.4530
file_tahun <- c(
"2015" = "data/2015.csv",
"2016" = "data/2016.csv",
"2017" = "data/2017.csv",
"2018" = "data/2018.csv",
"2019" = "data/2019.csv"
)
file_tahun <- file_tahun[file.exists(file_tahun)]
file_tahun## 2015 2016 2017 2018 2019
## "data/2015.csv" "data/2016.csv" "data/2017.csv" "data/2018.csv" "data/2019.csv"
kolom_per_tahun <- purrr::map(
file_tahun,
~ names(read_csv(.x, n_max = 0, show_col_types = FALSE) |> clean_names())
)
kolom_per_tahun## $`2015`
## [1] "country" "region"
## [3] "happiness_rank" "happiness_score"
## [5] "standard_error" "economy_gdp_per_capita"
## [7] "family" "health_life_expectancy"
## [9] "freedom" "trust_government_corruption"
## [11] "generosity" "dystopia_residual"
##
## $`2016`
## [1] "country" "region"
## [3] "happiness_rank" "happiness_score"
## [5] "lower_confidence_interval" "upper_confidence_interval"
## [7] "economy_gdp_per_capita" "family"
## [9] "health_life_expectancy" "freedom"
## [11] "trust_government_corruption" "generosity"
## [13] "dystopia_residual"
##
## $`2017`
## [1] "country" "happiness_rank"
## [3] "happiness_score" "whisker_high"
## [5] "whisker_low" "economy_gdp_per_capita"
## [7] "family" "health_life_expectancy"
## [9] "freedom" "generosity"
## [11] "trust_government_corruption" "dystopia_residual"
##
## $`2018`
## [1] "overall_rank" "country_or_region"
## [3] "score" "gdp_per_capita"
## [5] "social_support" "healthy_life_expectancy"
## [7] "freedom_to_make_life_choices" "generosity"
## [9] "perceptions_of_corruption"
##
## $`2019`
## [1] "overall_rank" "country_or_region"
## [3] "score" "gdp_per_capita"
## [5] "social_support" "healthy_life_expectancy"
## [7] "freedom_to_make_life_choices" "generosity"
## [9] "perceptions_of_corruption"
ganti_nama <- function(data, dari, ke) {
if (dari %in% names(data) && !(ke %in% names(data))) {
names(data)[names(data) == dari] <- ke
}
data
}
baca_happiness_tahun <- function(path, tahun) {
df <- read_csv(path, show_col_types = FALSE) |> clean_names()
df <- df |>
ganti_nama("country", "country_or_region") |>
ganti_nama("happiness_score", "score") |>
ganti_nama("economy_gdp_per_capita", "gdp_per_capita") |>
ganti_nama("family", "social_support") |>
ganti_nama("health_life_expectancy", "healthy_life_expectancy") |>
ganti_nama("freedom", "freedom_to_make_life_choices")
df |>
mutate(year = tahun) |>
select(
year, country_or_region, score, gdp_per_capita,
social_support, healthy_life_expectancy, freedom_to_make_life_choices
)
}happiness_multi_tahun <- purrr::map2_dfr(
file_tahun,
as.integer(names(file_tahun)),
baca_happiness_tahun
)
glimpse(happiness_multi_tahun)## Rows: 782
## Columns: 7
## $ year <int> 2015, 2015, 2015, 2015, 2015, 2015, 2015,…
## $ country_or_region <chr> "Switzerland", "Iceland", "Denmark", "Nor…
## $ score <dbl> 7.587, 7.561, 7.527, 7.522, 7.427, 7.406,…
## $ gdp_per_capita <dbl> 1.39651, 1.30232, 1.32548, 1.45900, 1.326…
## $ social_support <dbl> 1.34951, 1.40223, 1.36058, 1.33095, 1.322…
## $ healthy_life_expectancy <dbl> 0.94143, 0.94784, 0.87464, 0.88521, 0.905…
## $ freedom_to_make_life_choices <dbl> 0.66557, 0.62877, 0.64938, 0.66973, 0.632…
##
## 2015 2016 2017 2018 2019
## 158 157 155 156 156
## [1] 14
for (i in seq_along(tabel)) {
cat("\n====================\n")
cat("Tabel", i, "\n")
print(head(tabel[[i]], 3))
}##
## ====================
## Tabel 1
## # A tibble: 3 × 3
## Dimensions Indicators `Dimension index`
## <chr> <chr> <chr>
## 1 Long and healthy life Life expectancy at birth Life expectancy …
## 2 Knowledge Expected years of schoolingMean… Education index
## 3 A decent standard of living GNI per capita (PPP $) GNI index
##
## ====================
## Tabel 2
## # A tibble: 3 × 5
## Rank Changesince2015 `Country or territory` `HDI value`
## <int> <chr> <chr> <dbl>
## 1 1 "(2)" Iceland 0.972
## 2 2 "(1)" Norway 0.97
## 3 2 "" Switzerland 0.97
## # ℹ 1 more variable: `%annual growth(2010–2023)` <chr>
##
## ====================
## Tabel 3
## # A tibble: 3 × 10
## `Region or group` `1990` `2000` `2010` `2015` `2020` `2021` `2022` `2023`
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 OECD 0.801 0.846 0.883 0.899 0.903 0.904 0.91 0.916
## 2 Very high human devel… 0.797 0.838 0.879 0.898 0.901 0.903 0.908 0.914
## 3 Europe and Central As… 0.674 0.686 0.753 0.789 0.802 0.803 0.815 0.818
## # ℹ 1 more variable: `Annualgrowth(1990-2023)` <chr>
##
## ====================
## Tabel 4
## # A tibble: 3 × 6
## .mw-parser-output .navbar{dis…¹ .mw-parser-output .n…² `` `` `` ``
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Social "Topics:\nActing out\… Topi… "Act… Meas… Soci…
## 2 Topics: "Acting out\nChild ab… <NA> <NA> <NA> <NA>
## 3 Measures: "Social Progress Inde… <NA> <NA> <NA> <NA>
## # ℹ abbreviated names:
## # ¹`.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}vteDeprivation and poverty indicators`,
## # ²`.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}vteDeprivation and poverty indicators`
##
## ====================
## Tabel 5
## # A tibble: 2 × 2
## X1 X2
## <chr> <chr>
## 1 Topics: "Acting out\nChild abuse\nDisadvantaged\nDiseases of poverty\nEnvir…
## 2 Measures: "Social Progress Index"
##
## ====================
## Tabel 6
## # A tibble: 1 × 2
## X1 X2
## <chr> <chr>
## 1 Topics: "Cruel, inhuman or degrading treatment\nLearned helplessness\nPsychol…
##
## ====================
## Tabel 7
## # A tibble: 2 × 2
## X1 X2
## <chr> <chr>
## 1 Topics: "Asset poverty\nCulture of poverty\nDebt bondage\nEnergy poverty\nE…
## 2 Measures: "Below Poverty Line (India)\nHomeless Vulnerability Index\nMisery i…
##
## ====================
## Tabel 8
## # A tibble: 2 × 2
## X1 X2
## <chr> <chr>
## 1 Topics: "Disability and poverty\nFood insecurity\nPhysical abuse\nSex traff…
## 2 Measures: "India State Hunger Index\nGlobal Hunger Index\nDisability-adjusted…
##
## ====================
## Tabel 9
## # A tibble: 2 × 2
## X1 X2
## <chr> <chr>
## 1 Topics: "Feminization of poverty"
## 2 Measures: "Gender-related Development Index (GDI)\nGender Parity Index"
##
## ====================
## Tabel 10
## # A tibble: 3 × 6
## vteEconomic classification of…¹ vteEconomic classifi…² `` `` `` ``
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 "Developed country\nAdvanced e… "Developed country\nA… <NA> <NA> <NA> <NA>
## 2 "Three/Four-World Model" "First World\nSecond … <NA> <NA> <NA> <NA>
## 3 "Gross domestic product (GDP)" "Nominal\nBy country\… Nomi… "By … Purc… "By …
## # ℹ abbreviated names: ¹`vteEconomic classification of countries`,
## # ²`vteEconomic classification of countries`
##
## ====================
## Tabel 11
## # A tibble: 2 × 2
## X1 X2
## <chr> <chr>
## 1 Nominal "By country\npast and projected\nper capita\np…
## 2 Purchasing power parity (PPP) "By country\nfuture estimates\nper capita\nper…
##
## ====================
## Tabel 12
## # A tibble: 3 × 2
## `vteLists of countries by population statistics` vteLists of countries by po…¹
## <chr> <chr>
## 1 Global "Current population\nUnited …
## 2 Continents/subregions "Africa\nAntarctica\nAsia\nE…
## 3 Intercontinental "Americas\nArab world\nCommo…
## # ℹ abbreviated name: ¹`vteLists of countries by population statistics`
##
## ====================
## Tabel 13
## # A tibble: 3 × 2
## `vteLists of countries by quality of life rankings` vteLists of countries by…¹
## <chr> <chr>
## 1 General "Life expectancy\nAfrica\…
## 2 Economic "Net take-home pay\nLong-…
## 3 Environment "Greenhouse gas emissions…
## # ℹ abbreviated name: ¹`vteLists of countries by quality of life rankings`
##
## ====================
## Tabel 14
## # A tibble: 3 × 2
## vteLists of subnational entities by Human Development…¹ vteLists of subnatio…²
## <chr> <chr>
## 1 Africa "Algeria\nAngola\nBen…
## 2 Asia "Afghanistan\nArmenia…
## 3 Europe "Albania\nAustria\nBa…
## # ℹ abbreviated names:
## # ¹`vteLists of subnational entities by Human Development Index rankings`,
## # ²`vteLists of subnational entities by Human Development Index rankings`
hdi <- tabel[[2]] |>
clean_names() |>
rename(
country_name = country_or_territory,
hdi = hdi_value
) |>
select(country_name, hdi)
head(hdi)## Rows: 193
## Columns: 2
## $ country_name <chr> "Iceland", "Norway", "Switzerland", "Denmark", "Germany",…
## $ hdi <dbl> 0.972, 0.970, 0.970, 0.962, 0.959, 0.959, 0.958, 0.955, 0…
Kedua dataset dibaca kembali dari folder output/ agar
proses integrasi dapat dijalankan ulang secara independen.
hdi_final <- hdi_final |>
mutate(
country_name = str_trim(country_name),
country_name = recode(
country_name,
"Korea (Republic of)" = "South Korea",
"Russian Federation" = "Russia",
"Czechia" = "Czech Republic",
"Türkiye" = "Turkey",
"Viet Nam" = "Vietnam",
"Iran (Islamic Republic of)" = "Iran",
"Bolivia (Plurinational State of)" = "Bolivia",
"Venezuela (Bolivarian Republic of)" = "Venezuela",
"Tanzania (United Republic of)" = "Tanzania",
"Moldova (Republic of)" = "Moldova",
"Lao People's Democratic Republic" = "Laos",
"Syrian Arab Republic" = "Syria",
"Congo (Democratic Republic of the)" = "Congo (Kinshasa)",
"Congo" = "Congo (Brazzaville)",
"Hong Kong, China (SAR)" = "Hong Kong",
"Eswatini (Kingdom of)" = "Swaziland",
"Palestine, State of" = "Palestinian Territories",
"Cabo Verde" = "Cape Verde",
"Gambia (Republic of the)" = "Gambia",
"North Macedonia" = "Macedonia"
)
)happiness_hdi <- happiness_final |>
left_join(hdi_final, by = c("country_or_region" = "country_name"))
head(happiness_hdi)tidak_match <- happiness_hdi |>
filter(is.na(hdi)) |>
select(country_or_region)
n_tidak_match <- nrow(tidak_match)
n_tidak_match## [1] 9
Terdapat 9 negara yang belum berhasil dipadankan dengan data HDI. Baris tersebut dikeluarkan agar variabel HDI tidak mengandung nilai kosong pada analisis selanjutnya.
## [1] 147 10
happiness_hdi <- happiness_hdi |>
rename(
country_name = country_or_region,
happiness_score = score
) |>
select(
country_name,
happiness_score,
gdp_per_capita,
social_support,
healthy_life_expectancy,
freedom_to_make_life_choices,
hdi
)
head(happiness_hdi)Dataset hasil integrasi disimpan sebagai satu file CSV
final, happiness_hdi_merged.csv, yang menjadi
dataset utama untuk seluruh analisis pada bagian selanjutnya.
Dataset Kaggle multitahun digabungkan dengan HDI berdasarkan nama negara, sehingga setiap kombinasi negara × tahun memiliki seluruh variabel lengkap: happiness score, GDP per capita, social support, healthy life expectancy, freedom, dan HDI.
happiness_hdi_multi <- happiness_multi_tahun |>
left_join(hdi_final, by = c("country_or_region" = "country_name")) |>
filter(!is.na(hdi)) |>
rename(
country_name = country_or_region,
happiness_score = score
) |>
select(
country_name,
year,
happiness_score,
gdp_per_capita,
social_support,
healthy_life_expectancy,
freedom_to_make_life_choices,
hdi
) |>
arrange(year, country_name)
glimpse(happiness_hdi_multi)## Rows: 743
## Columns: 8
## $ country_name <chr> "Afghanistan", "Albania", "Algeria", "Ang…
## $ year <int> 2015, 2015, 2015, 2015, 2015, 2015, 2015,…
## $ happiness_score <dbl> 3.575, 4.959, 5.605, 4.033, 6.574, 4.350,…
## $ gdp_per_capita <dbl> 0.31982, 0.87867, 0.93929, 0.75778, 1.053…
## $ social_support <dbl> 0.30285, 0.80434, 1.07772, 0.86040, 1.248…
## $ healthy_life_expectancy <dbl> 0.30335, 0.81325, 0.61766, 0.16683, 0.787…
## $ freedom_to_make_life_choices <dbl> 0.23414, 0.35733, 0.28579, 0.10384, 0.449…
## $ hdi <dbl> 0.496, 0.810, 0.763, 0.616, 0.865, 0.811,…
if (!dir.exists("output")) dir.create("output", recursive = TRUE)
write_csv(
happiness_hdi_multi,
here("output", "happiness_hdi_merged_2015_2019.csv")
)
list_per_tahun <- happiness_hdi_multi |>
dplyr::group_split(year) |>
purrr::set_names(
happiness_hdi_multi |>
dplyr::distinct(year) |>
dplyr::arrange(year) |>
dplyr::pull(year) |>
as.character()
)
writexl::write_xlsx(
list_per_tahun,
here("output", "happiness_hdi_per_tahun.xlsx")
)## [1] 147 7
## Rows: 147
## Columns: 7
## $ country_name <chr> "Finland", "Denmark", "Norway", "Iceland"…
## $ happiness_score <dbl> 7.769, 7.600, 7.554, 7.494, 7.488, 7.480,…
## $ gdp_per_capita <dbl> 1.340, 1.383, 1.488, 1.380, 1.396, 1.452,…
## $ social_support <dbl> 1.587, 1.573, 1.582, 1.624, 1.522, 1.526,…
## $ healthy_life_expectancy <dbl> 0.986, 0.996, 1.028, 1.026, 0.999, 1.052,…
## $ freedom_to_make_life_choices <dbl> 0.596, 0.592, 0.603, 0.591, 0.557, 0.572,…
## $ hdi <dbl> 0.948, 0.962, 0.970, 0.972, 0.955, 0.970,…
## country_name happiness_score gdp_per_capita social_support
## Length:147 Min. :2.853 Min. :0.0000 Min. :0.000
## Class :character 1st Qu.:4.541 1st Qu.:0.5760 1st Qu.:1.047
## Mode :character Median :5.386 Median :0.9600 Median :1.277
## Mean :5.413 Mean :0.9064 Mean :1.208
## 3rd Qu.:6.190 3rd Qu.:1.2290 3rd Qu.:1.454
## Max. :7.769 Max. :1.6840 Max. :1.624
## healthy_life_expectancy freedom_to_make_life_choices hdi
## Min. :0.1050 Min. :0.0000 Min. :0.3880
## 1st Qu.:0.5530 1st Qu.:0.3070 1st Qu.:0.6130
## Median :0.7950 Median :0.4260 Median :0.7760
## Mean :0.7302 Mean :0.3944 Mean :0.7477
## 3rd Qu.:0.8825 3rd Qu.:0.5080 3rd Qu.:0.8895
## Max. :1.1410 Max. :0.6310 Max. :0.9720
| Name | happiness_hdi |
| Number of rows | 147 |
| Number of columns | 7 |
| _______________________ | |
| Column type frequency: | |
| character | 1 |
| numeric | 6 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| country_name | 0 | 1 | 4 | 24 | 0 | 147 | 0 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| happiness_score | 0 | 1 | 5.41 | 1.13 | 2.85 | 4.54 | 5.39 | 6.19 | 7.77 | ▂▇▇▇▅ |
| gdp_per_capita | 0 | 1 | 0.91 | 0.40 | 0.00 | 0.58 | 0.96 | 1.23 | 1.68 | ▃▃▆▇▃ |
| social_support | 0 | 1 | 1.21 | 0.30 | 0.00 | 1.05 | 1.28 | 1.45 | 1.62 | ▁▁▂▅▇ |
| healthy_life_expectancy | 0 | 1 | 0.73 | 0.24 | 0.10 | 0.55 | 0.80 | 0.88 | 1.14 | ▁▃▃▇▅ |
| freedom_to_make_life_choices | 0 | 1 | 0.39 | 0.15 | 0.00 | 0.31 | 0.43 | 0.51 | 0.63 | ▁▃▅▇▆ |
| hdi | 0 | 1 | 0.75 | 0.16 | 0.39 | 0.61 | 0.78 | 0.89 | 0.97 | ▂▃▃▇▇ |
happiness_hdi |>
select(where(is.numeric)) |>
pivot_longer(everything(), names_to = "variabel", values_to = "nilai") |>
group_by(variabel) |>
summarise(
n = sum(!is.na(nilai)),
mean = mean(nilai, na.rm = TRUE),
median = median(nilai, na.rm = TRUE),
sd = sd(nilai, na.rm = TRUE),
min = min(nilai, na.rm = TRUE),
max = max(nilai, na.rm = TRUE)
) |>
kable(digits = 3, caption = "Statistik Deskriptif Variabel Numerik (2019)") |>
kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))| variabel | n | mean | median | sd | min | max |
|---|---|---|---|---|---|---|
| freedom_to_make_life_choices | 147 | 0.394 | 0.426 | 0.146 | 0.000 | 0.631 |
| gdp_per_capita | 147 | 0.906 | 0.960 | 0.400 | 0.000 | 1.684 |
| happiness_score | 147 | 5.413 | 5.386 | 1.130 | 2.853 | 7.769 |
| hdi | 147 | 0.748 | 0.776 | 0.161 | 0.388 | 0.972 |
| healthy_life_expectancy | 147 | 0.730 | 0.795 | 0.237 | 0.105 | 1.141 |
| social_support | 147 | 1.208 | 1.277 | 0.305 | 0.000 | 1.624 |
ggplot(happiness_hdi, aes(x = hdi)) +
geom_histogram(aes(y = after_stat(density), fill = after_stat(x)),
bins = 20, color = "white") +
geom_density(color = "#1B5E20", linewidth = 1) +
scale_fill_gradient(low = "#E74C3C", high = "#27AE60", guide = "none") +
labs(
title = "Distribusi Nilai Human Development Index (HDI)",
x = "HDI", y = "Densitas"
) +
theme_praktikum()Pilih salah satu tab tahun di bawah ini untuk melihat distribusi Happiness Score pada tahun tersebut. Tab 2019 ditampilkan sebagai tampilan awal (default).
| Statistik | Nilai |
|---|---|
| Jumlah Negara | 150.000 |
| Rata-rata | 5.391 |
| Median | 5.261 |
| SD | 1.162 |
| Minimum | 2.839 |
| Maksimum | 7.587 |
| Statistik | Nilai |
|---|---|
| Jumlah Negara | 149.000 |
| Rata-rata | 5.383 |
| Median | 5.314 |
| SD | 1.152 |
| Minimum | 2.905 |
| Maksimum | 7.526 |
| Statistik | Nilai |
|---|---|
| Jumlah Negara | 148.000 |
| Rata-rata | 5.362 |
| Median | 5.283 |
| SD | 1.146 |
| Minimum | 2.693 |
| Maksimum | 7.537 |
| Statistik | Nilai |
|---|---|
| Jumlah Negara | 149.000 |
| Rata-rata | 5.376 |
| Median | 5.358 |
| SD | 1.133 |
| Minimum | 2.905 |
| Maksimum | 7.632 |
| Statistik | Nilai |
|---|---|
| Jumlah Negara | 147.000 |
| Rata-rata | 5.413 |
| Median | 5.386 |
| SD | 1.130 |
| Minimum | 2.853 |
| Maksimum | 7.769 |
Pilih salah satu tab tahun di bawah ini untuk melihat lima negara paling bahagia, scatter plot HDI vs Happiness Score, dan nilai korelasinya pada tahun tersebut. Tab 2019 ditampilkan sebagai tampilan awal (default).
Dataset tahun 2015 setelah digabungkan dengan HDI memuat 150 negara.
| country_name | happiness_score | hdi |
|---|---|---|
| Switzerland | 7.587 | 0.970 |
| Iceland | 7.561 | 0.972 |
| Denmark | 7.527 | 0.962 |
| Norway | 7.522 | 0.970 |
| Canada | 7.427 | 0.939 |
Korelasi HDI dengan Happiness Score pada tahun 2015 adalah r = 0.79.
Dataset tahun 2016 setelah digabungkan dengan HDI memuat 149 negara.
| country_name | happiness_score | hdi |
|---|---|---|
| Denmark | 7.526 | 0.962 |
| Switzerland | 7.509 | 0.970 |
| Iceland | 7.501 | 0.972 |
| Norway | 7.498 | 0.970 |
| Finland | 7.413 | 0.948 |
Korelasi HDI dengan Happiness Score pada tahun 2016 adalah r = 0.8.
Dataset tahun 2017 setelah digabungkan dengan HDI memuat 148 negara.
| country_name | happiness_score | hdi |
|---|---|---|
| Norway | 7.537 | 0.970 |
| Denmark | 7.522 | 0.962 |
| Iceland | 7.504 | 0.972 |
| Switzerland | 7.494 | 0.970 |
| Finland | 7.469 | 0.948 |
Korelasi HDI dengan Happiness Score pada tahun 2017 adalah r = 0.82.
Dataset tahun 2018 setelah digabungkan dengan HDI memuat 149 negara.
| country_name | happiness_score | hdi |
|---|---|---|
| Finland | 7.632 | 0.948 |
| Norway | 7.594 | 0.970 |
| Denmark | 7.555 | 0.962 |
| Iceland | 7.495 | 0.972 |
| Switzerland | 7.487 | 0.970 |
Korelasi HDI dengan Happiness Score pada tahun 2018 adalah r = 0.82.
Dataset tahun 2019 setelah digabungkan dengan HDI memuat 147 negara.
| country_name | happiness_score | hdi |
|---|---|---|
| Finland | 7.769 | 0.948 |
| Denmark | 7.600 | 0.962 |
| Norway | 7.554 | 0.970 |
| Iceland | 7.494 | 0.972 |
| Netherlands | 7.488 | 0.955 |
Korelasi HDI dengan Happiness Score pada tahun 2019 adalah r = 0.81.
hdi_top20 <- hdi_final |>
slice_max(order_by = hdi, n = 20) |>
arrange(hdi) |>
mutate(country_name = factor(country_name, levels = unique(country_name)))p_dot <- hdi_top20 |>
ggplot(aes(x = hdi, y = country_name)) +
geom_segment(
aes(x = 0, xend = hdi, y = country_name, yend = country_name),
color = "grey80", linewidth = 0.8
) +
geom_point(
aes(color = hdi, text = paste0("<b>", country_name, "</b>", "<br>HDI : ", round(hdi, 3))),
size = 4
) +
scale_color_gradient(low = "#E74C3C", high = "#27AE60", name = "HDI") +
scale_x_continuous(limits = c(0, 1.05), breaks = seq(0, 1, 0.1), labels = number_format(accuracy = 0.01)) +
labs(
title = "20 Negara dengan Human Development Index (HDI) Tertinggi",
subtitle = "Data hasil Web Scraping dari Wikipedia",
x = "Nilai Human Development Index (HDI)", y = NULL
) +
theme_praktikum() +
theme(panel.grid.major.y = element_blank())
ggplotly(p_dot, tooltip = "text") |>
layout(title = list(x = 0, xanchor = "left", font = list(size = 15)))world_map <- map_data("world")
hdi_map <- hdi_final |>
mutate(
country_name = recode(
country_name,
"United States" = "USA",
"United Kingdom" = "UK"
)
)
peta_hdi <- left_join(world_map, hdi_map, by = c("region" = "country_name"))p_map <- ggplot(peta_hdi, aes(x = long, y = lat, group = group)) +
geom_polygon(
aes(
fill = hdi,
text = paste0(
"<b>", region, "</b>",
"<br>HDI : ", ifelse(is.na(hdi), "Data tidak tersedia", round(hdi, 3))
)
),
color = "white", linewidth = 0.15
) +
coord_fixed(1.3) +
scale_fill_gradient(low = "#E74C3C", high = "#27AE60",
na.value = "grey90", name = "HDI") +
labs(
title = "Persebaran Human Development Index (HDI) Dunia",
subtitle = "Data hasil Web Scraping dari Wikipedia",
x = NULL, y = NULL
) +
theme_void(base_size = 12) +
theme(legend.position = "bottom",
plot.title = element_text(face = "bold", color = "#1B5E20"))
ggplotly(p_map, tooltip = "text") |>
layout(
annotations = list(
x = 1, y = -0.10,
text = "Sumber : Wikipedia (Human Development Index)",
showarrow = FALSE, xref = "paper", yref = "paper", xanchor = "right",
font = list(size = 10, color = "gray40")
)
)var_korelasi <- happiness_hdi |>
select(hdi, happiness_score, gdp_per_capita, social_support)
cor_matrix <- cor(var_korelasi, use = "complete.obs")
cor_matrix |>
round(3) |>
kable(caption = "Matriks Korelasi antar Variabel (2019)") |>
kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))| hdi | happiness_score | gdp_per_capita | social_support | |
|---|---|---|---|---|
| hdi | 1.000 | 0.806 | 0.949 | 0.775 |
| happiness_score | 0.806 | 1.000 | 0.796 | 0.781 |
| gdp_per_capita | 0.949 | 0.796 | 1.000 | 0.763 |
| social_support | 0.775 | 0.781 | 0.763 | 1.000 |
cor_df <- as.data.frame(as.table(cor_matrix))
names(cor_df) <- c("var1", "var2", "korelasi")
ggplot(cor_df, aes(x = var1, y = var2, fill = korelasi)) +
geom_tile(color = "white") +
geom_text(aes(label = round(korelasi, 2)), color = "white", size = 4, fontface = "bold") +
scale_fill_gradient(
low = "#E74C3C", high = "#27AE60", name = "Korelasi"
) +
labs(
title = "Heatmap Korelasi: HDI, Happiness Score, GDP per Capita, Social Support (2019)",
x = NULL, y = NULL
) +
theme_praktikum() +
theme(
panel.grid = element_blank(),
axis.text.x = element_text(angle = 45, hjust = 1)
)Pilih tahun pada tab di bawah ini untuk melihat interpretasi hasil analisis pada tahun tersebut. Tab 2019 ditampilkan sebagai tampilan awal (default).
a. Negara dengan HDI tertinggi berasal dari kawasan mana?
Lima negara dengan HDI tertinggi pada tahun 2015 adalah Iceland, Norway, Switzerland, Denmark, Germany, Sweden.
Berdasarkan Cleveland dot plot (7d) dan peta dunia (7e), negara dengan
HDI tertinggi secara umum berasal dari kawasan Eropa Barat/Utara
serta sebagian negara maju di Asia Timur dan Oseania.
b. Apakah negara dengan HDI tinggi selalu memiliki Happiness Score tinggi?
Korelasi antara HDI dan Happiness Score pada tahun 2015 adalah
r = 0.79, menunjukkan hubungan yang cukup kuat. Negara dengan HDI
tinggi cenderung memiliki Happiness Score yang tinggi pula,
meskipun tidak selalu berlaku mutlak — terlihat pada scatter plot (7c)
masih terdapat variasi di sekitar garis regresi.
c. Bagaimana hubungan GDP per Capita terhadap Happiness Score?
Korelasi GDP per Capita dan Happiness Score pada tahun 2015 adalah
r = 0.79, menunjukkan hubungan yang cukup kuat dan positif.
d. Bagaimana hubungan Social Support terhadap Happiness Score?
Korelasi Social Support dan Happiness Score pada tahun 2015 adalah
r = 0.74, mengindikasikan hubungan cukup kuat. Dukungan sosial
turut berkontribusi terhadap tingkat kebahagiaan suatu negara.
e. Variabel apa yang paling berhubungan dengan tingkat kebahagiaan?
Berdasarkan matriks korelasi (Nomor 8), variabel dengan korelasi absolut
tertinggi terhadap Happiness Score pada tahun 2015 adalah
gdp_per_capita dengan nilai korelasi sebesar 0.79.
a. Negara dengan HDI tertinggi berasal dari kawasan mana?
Lima negara dengan HDI tertinggi pada tahun 2016 adalah Iceland, Norway, Switzerland, Denmark, Germany, Sweden.
Berdasarkan Cleveland dot plot (7d) dan peta dunia (7e), negara dengan
HDI tertinggi secara umum berasal dari kawasan Eropa Barat/Utara
serta sebagian negara maju di Asia Timur dan Oseania.
b. Apakah negara dengan HDI tinggi selalu memiliki Happiness Score tinggi?
Korelasi antara HDI dan Happiness Score pada tahun 2016 adalah
r = 0.80, menunjukkan hubungan yang cukup kuat. Negara dengan HDI
tinggi cenderung memiliki Happiness Score yang tinggi pula,
meskipun tidak selalu berlaku mutlak — terlihat pada scatter plot (7c)
masih terdapat variasi di sekitar garis regresi.
c. Bagaimana hubungan GDP per Capita terhadap Happiness Score?
Korelasi GDP per Capita dan Happiness Score pada tahun 2016 adalah
r = 0.79, menunjukkan hubungan yang cukup kuat dan positif.
d. Bagaimana hubungan Social Support terhadap Happiness Score?
Korelasi Social Support dan Happiness Score pada tahun 2016 adalah
r = 0.74, mengindikasikan hubungan cukup kuat. Dukungan sosial
turut berkontribusi terhadap tingkat kebahagiaan suatu negara.
e. Variabel apa yang paling berhubungan dengan tingkat kebahagiaan?
Berdasarkan matriks korelasi (Nomor 8), variabel dengan korelasi absolut
tertinggi terhadap Happiness Score pada tahun 2016 adalah
hdi dengan nilai korelasi sebesar 0.80.
a. Negara dengan HDI tertinggi berasal dari kawasan mana?
Lima negara dengan HDI tertinggi pada tahun 2017 adalah Iceland, Norway, Switzerland, Denmark, Germany, Sweden.
Berdasarkan Cleveland dot plot (7d) dan peta dunia (7e), negara dengan
HDI tertinggi secara umum berasal dari kawasan Eropa Barat/Utara
serta sebagian negara maju di Asia Timur dan Oseania.
b. Apakah negara dengan HDI tinggi selalu memiliki Happiness Score tinggi?
Korelasi antara HDI dan Happiness Score pada tahun 2017 adalah
r = 0.82, menunjukkan hubungan yang cukup kuat. Negara dengan HDI
tinggi cenderung memiliki Happiness Score yang tinggi pula,
meskipun tidak selalu berlaku mutlak — terlihat pada scatter plot (7c)
masih terdapat variasi di sekitar garis regresi.
c. Bagaimana hubungan GDP per Capita terhadap Happiness Score?
Korelasi GDP per Capita dan Happiness Score pada tahun 2017 adalah
r = 0.82, menunjukkan hubungan yang cukup kuat dan positif.
d. Bagaimana hubungan Social Support terhadap Happiness Score?
Korelasi Social Support dan Happiness Score pada tahun 2017 adalah
r = 0.75, mengindikasikan hubungan cukup kuat. Dukungan sosial
turut berkontribusi terhadap tingkat kebahagiaan suatu negara.
e. Variabel apa yang paling berhubungan dengan tingkat kebahagiaan?
Berdasarkan matriks korelasi (Nomor 8), variabel dengan korelasi absolut
tertinggi terhadap Happiness Score pada tahun 2017 adalah
hdi dengan nilai korelasi sebesar 0.82.
a. Negara dengan HDI tertinggi berasal dari kawasan mana?
Lima negara dengan HDI tertinggi pada tahun 2018 adalah Iceland, Norway, Switzerland, Denmark, Germany, Sweden.
Berdasarkan Cleveland dot plot (7d) dan peta dunia (7e), negara dengan
HDI tertinggi secara umum berasal dari kawasan Eropa Barat/Utara
serta sebagian negara maju di Asia Timur dan Oseania.
b. Apakah negara dengan HDI tinggi selalu memiliki Happiness Score tinggi?
Korelasi antara HDI dan Happiness Score pada tahun 2018 adalah
r = 0.82, menunjukkan hubungan yang cukup kuat. Negara dengan HDI
tinggi cenderung memiliki Happiness Score yang tinggi pula,
meskipun tidak selalu berlaku mutlak — terlihat pada scatter plot (7c)
masih terdapat variasi di sekitar garis regresi.
c. Bagaimana hubungan GDP per Capita terhadap Happiness Score?
Korelasi GDP per Capita dan Happiness Score pada tahun 2018 adalah
r = 0.80, menunjukkan hubungan yang cukup kuat dan positif.
d. Bagaimana hubungan Social Support terhadap Happiness Score?
Korelasi Social Support dan Happiness Score pada tahun 2018 adalah
r = 0.75, mengindikasikan hubungan cukup kuat. Dukungan sosial
turut berkontribusi terhadap tingkat kebahagiaan suatu negara.
e. Variabel apa yang paling berhubungan dengan tingkat kebahagiaan?
Berdasarkan matriks korelasi (Nomor 8), variabel dengan korelasi absolut
tertinggi terhadap Happiness Score pada tahun 2018 adalah
hdi dengan nilai korelasi sebesar 0.82.
a. Negara dengan HDI tertinggi berasal dari kawasan mana?
Lima negara dengan HDI tertinggi pada tahun 2019 adalah Iceland, Norway, Switzerland, Denmark, Germany, Sweden.
Berdasarkan Cleveland dot plot (7d) dan peta dunia (7e), negara dengan
HDI tertinggi secara umum berasal dari kawasan Eropa Barat/Utara
serta sebagian negara maju di Asia Timur dan Oseania.
b. Apakah negara dengan HDI tinggi selalu memiliki Happiness Score tinggi?
Korelasi antara HDI dan Happiness Score pada tahun 2019 adalah
r = 0.81, menunjukkan hubungan yang cukup kuat. Negara dengan HDI
tinggi cenderung memiliki Happiness Score yang tinggi pula,
meskipun tidak selalu berlaku mutlak — terlihat pada scatter plot (7c)
masih terdapat variasi di sekitar garis regresi.
c. Bagaimana hubungan GDP per Capita terhadap Happiness Score?
Korelasi GDP per Capita dan Happiness Score pada tahun 2019 adalah
r = 0.80, menunjukkan hubungan yang cukup kuat dan positif.
d. Bagaimana hubungan Social Support terhadap Happiness Score?
Korelasi Social Support dan Happiness Score pada tahun 2019 adalah
r = 0.78, mengindikasikan hubungan cukup kuat. Dukungan sosial
turut berkontribusi terhadap tingkat kebahagiaan suatu negara.
e. Variabel apa yang paling berhubungan dengan tingkat kebahagiaan?
Berdasarkan matriks korelasi (Nomor 8), variabel dengan korelasi absolut
tertinggi terhadap Happiness Score pada tahun 2019 adalah
hdi dengan nilai korelasi sebesar 0.81.
Pilih tahun pada tab di bawah ini untuk melihat tabel integrasi World Happiness Report dan Human Development Index pada tahun tersebut.
## [1] "happiness_2015_2019.csv" "happiness_2019.csv"
## [3] "happiness_clean.csv" "happiness_hdi_merged.csv"
## [5] "happiness_hdi_merged_2015_2019.csv" "happiness_hdi_per_tahun.xlsx"
## [7] "happiness_kaggle_2015_2019.csv" "hdi_wikipedia.csv"
## [9] "hdi_wikipedia_2015_2019.csv"
Praktikum Data Mining · Data Acquisition & Exploratory Data Analysis