Through this project we intend to analyze the correlation between the health expenditure (SH.XPD.CHEX.GD.ZS) of the different countries throughout the world and the life expectancy (SP.DYN.LE00.IN) of the citizens of those countries, from 2015 onwards. All the data has been collected from the World Bank dataset. Our main hypothesis consists of considering that the more money spent in strengthening the health system, the better life expectancy the citizens of the country are going to enjoy. We specially want to focus on the period of time concerning the period of time between Covid-19 pandemic and after the same, due to the fact that is an especially vulnerable period of time worldwide in which the conditions of the health system of a country play a critical role. At the same time, for this project to be data feasible, we have grouped the countries into different geographical regions which are the following ones: Europe & Central Asia, Middle East and North Africa, South Asia, East Asia and the Pacific, Latin America and the Caribbean, North America, and Sub-Saharan Africa. For this purpose, we have considered relevant to expose data in different and variated ways for it to be visually accessible and easily interpreted. In this sense, we have created tables, graphic plots and maps which represent the desired correlations.
It is undoubtful that health plays an important role in every society. Just to put ourselves in perspective, according to the Health Policy Watch, the world spent 10% of its PIB or which is the same 9.8 trillion of dollars in health during 2021 (Health Policy Watch, 2023). Nevertheless, according to the World Health Organization annual report, in 2023 there are still several difficulties in variated countries in relation with maternal and child mortality (227/100.000 maternal mortality and 76/1000 deaths concerning child mortality) specially in Africa, infectious diseases such as HIV (1.5 million infections in 2021), Tuberculosis (10.6 million infections) or Malaria (247 million cases in 2021) or even concerning problems regarding child malnutrition (22.3% of child under five suffering from malnutrition) (World Health Organization, 2023). It is also important to highlight the presence of this topic within the SDG goals which have been designed as part of the 2030 worldwide strategy by the United Nations Conference on Sustainable Development during the conference hold in Rio de Janeiro in 2012. Concretely the health SDG corresponds to SDG 3 which is presented until the name “Good Health and Well-being” and which main objective consist of “Ensuring healthy lives and promote well-being for all at all ages” (United Nations, n.d.).
knitr::opts_chunk$set(echo = TRUE, message=FALSE, warning=FALSE)
# We load required packages
library(tidyverse)
library(wbstats)
library(knitr)
library(countrycode)
library(flextable)
library(plotly)
library(tmap)
# Defining our indicators
my_indicators <- c(
life_exp = "SP.DYN.LE00.IN",
health_expenditure ="SH.XPD.CHEX.GD.ZS"
)
# Load country data
countries <- wb_countries()
# Fetch World Bank data
wbind <- wb_data(my_indicators, start_date = 2015)
# Join 'wbind' with 'countries' dataframe to add region information
wbind <- left_join(wbind, select(countries, country, region), by = "country")
# Join 'wbind' with 'countries' dataframe to add region information based on ISO3 country code
wbind <- left_join(wbind, select(countries, iso3c, region), by = c("country" = "iso3c"))
# Perform the join based on the common column 'region' in 'countries' and 'region.x' in 'wbind'
result <- left_join(wbind, countries, by = c("region.x" = "region"))
# Check the result
str(result)
## tibble [9,315 × 25] (S3: tbl_df/tbl/data.frame)
## $ iso2c.x : chr [1:9315] "AW" "AW" "AW" "AW" ...
## $ iso3c.x : chr [1:9315] "ABW" "ABW" "ABW" "ABW" ...
## $ country.x : chr [1:9315] "Aruba" "Aruba" "Aruba" "Aruba" ...
## $ date : num [1:9315] 2015 2015 2015 2015 2015 ...
## $ health_expenditure: num [1:9315] NA NA NA NA NA NA NA NA NA NA ...
## ..- attr(*, "label")= chr "Current health expenditure (% of GDP)"
## $ life_exp : num [1:9315] 75.7 75.7 75.7 75.7 75.7 ...
## ..- attr(*, "label")= chr "Life expectancy at birth, total (years)"
## $ region.x : chr [1:9315] "Latin America & Caribbean" "Latin America & Caribbean" "Latin America & Caribbean" "Latin America & Caribbean" ...
## $ region.y : chr [1:9315] NA NA NA NA ...
## $ iso3c.y : chr [1:9315] "ABW" "ARG" "ATG" "BHS" ...
## $ iso2c.y : chr [1:9315] "AW" "AR" "AG" "BS" ...
## $ country.y : chr [1:9315] "Aruba" "Argentina" "Antigua and Barbuda" "Bahamas, The" ...
## $ capital_city : chr [1:9315] "Oranjestad" "Buenos Aires" "Saint John's" "Nassau" ...
## $ longitude : num [1:9315] -70 -58.4 -61.8 -77.3 -88.8 ...
## $ latitude : num [1:9315] 12.5 -34.6 17.1 25.1 17.3 ...
## $ region_iso3c : chr [1:9315] "LCN" "LCN" "LCN" "LCN" ...
## $ region_iso2c : chr [1:9315] "ZJ" "ZJ" "ZJ" "ZJ" ...
## $ admin_region_iso3c: chr [1:9315] NA "LAC" NA NA ...
## $ admin_region_iso2c: chr [1:9315] NA "XJ" NA NA ...
## $ admin_region : chr [1:9315] NA "Latin America & Caribbean (excluding high income)" NA NA ...
## $ income_level_iso3c: chr [1:9315] "HIC" "UMC" "HIC" "HIC" ...
## $ income_level_iso2c: chr [1:9315] "XD" "XT" "XD" "XD" ...
## $ income_level : chr [1:9315] "High income" "Upper middle income" "High income" "High income" ...
## $ lending_type_iso3c: chr [1:9315] "LNX" "IBD" "IBD" "LNX" ...
## $ lending_type_iso2c: chr [1:9315] "XX" "XF" "XF" "XX" ...
## $ lending_type : chr [1:9315] "Not classified" "IBRD" "IBRD" "Not classified" ...
# Check for duplicate values in 'region.x' column of 'wbind'
duplicated_regions_wbind <- any(duplicated(wbind$region.x))
# Check for duplicate values in 'region' column of 'countries'
duplicated_regions_countries <- any(duplicated(countries$region))
duplicated_regions_wbind
## [1] TRUE
duplicated_regions_countries
## [1] TRUE
# Unique values in 'region.x' column of 'wbind'
unique_regions_wbind <- unique(wbind$region.x)
# Unique values in 'region' column of 'countries'
unique_regions_countries <- unique(countries$region)
unique_regions_wbind
## [1] "Latin America & Caribbean" "South Asia"
## [3] "Sub-Saharan Africa" "Europe & Central Asia"
## [5] "Middle East & North Africa" "East Asia & Pacific"
## [7] "North America"
unique_regions_countries
## [1] "Latin America & Caribbean" "Aggregates"
## [3] "South Asia" "Sub-Saharan Africa"
## [5] "Europe & Central Asia" "Middle East & North Africa"
## [7] "East Asia & Pacific" "North America"
# Join country data with World Bank data and store it in a new variable
region <- wbind |>
left_join(countries, by = c("iso2c", "iso3c", "country"))
# Join country data with World Bank data
wbind <- wbind |>
left_join(countries, by=c("iso2c", "iso3c", "country"))
We will start by addressing the average data concerning life expectancy and health expenditure, in which we will present data grouped by the regions previously mentioned. In this case we can clearly see that countries spending the most money are the countries enjoying a better life expectancy, like for example North America in which the spend 13.6 billion dollars in reinforcing the health system and consequently they have a life expectancy of 80.47 years while South Asia spend 5 billion dollars and enjoy a life expectancy of only 70.11 years. Therefore, at first sight we could advance, through this data, that the average health expenditure is a determinant factor at the time of considering the average life expectancy or, which is the same, the variable average health expenditure has a positive correlation regarding average life expectancy. On the other hand, we will continue by exposing the data obtained from the plot we have generated. In this case we can observe in a more visual way, and divided by countries classified in regions, the conclusions we have reached in the previous section, with some exceptions. In this case we can see that countries from East Asia and the Pacific alongside with Asia spend the least in health and, on average they have the less life expectancy. On the other hand, regions like Sub Saharan Africa have the same issue, the expenditure is really low and consequently the life expectancy is low as well. On comparison other regions like Europe and central Asia have focused their efforts on reinforcing the expenditure in health which have provoked life expectancy to skyrocket. As we could suppose, there are always exceptions that outstand and are really interesting to analyze. In this case, several East Asia & Pacific as well as Sub Saharan countries dedicate a great part of their funds to reinforce the health system although they still have a low life expectancy. This is mainly provoked because of proportions. We are calculating the health expenditure in % of GDP which could give us the illusion that several countries have spent great quantities of money in their health system while analyzing the actual expenditure it is not as big as it could seem. A simple example is the following one: in South Africa the health expenditure in GDP % in 2020 was of 8.58% which is of 28 billion euros while the Italy expenditure the same year was of 9.6% of the GDP which is the same as 159 billion euros within its economy. Finally, we will represent this conclusions through the exhibition of a map that summarizes the investigation carried out.
# Create a flextable for the country with the lowest life expectancy in each region
lowest_life_exp_table <- tryCatch({
wbind %>%
group_by(region) %>%
arrange(life_exp) %>%
slice(1) %>%
select(country, life_exp) %>%
flextable() %>%
colformat_double(digits = 0) # No decimal digits.
}, error = function(e) {
cat("An error occurred:", conditionMessage(e), "\n")
NULL
})
if (!is.null(lowest_life_exp_table)) {
print(lowest_life_exp_table)
}
## a flextable object.
## col_keys: `region`, `country`, `life_exp`
## header has 1 row(s)
## body has 7 row(s)
## original dataset sample:
## region country life_exp
## 1 East Asia & Pacific Nauru 62.26900
## 2 Europe & Central Asia Turkmenistan 68.78200
## 3 Latin America & Caribbean Haiti 63.23700
## 4 Middle East & North Africa Djibouti 61.95700
## 5 North America United States 78.69024
# Create a flextable for the country with the lowest health expenditure in each region
lowest_health_exp_table <- tryCatch({
wbind %>%
group_by(region) %>%
arrange(health_expenditure) %>%
slice(1) %>%
select(country, health_expenditure) %>%
flextable() %>%
colformat_double(digits = 0) # No decimal digits.
}, error = function(e) {
cat("An error occurred:", conditionMessage(e), "\n")
NULL
})
if (!is.null(lowest_health_exp_table)) {
print(lowest_health_exp_table)
}
## a flextable object.
## col_keys: `region`, `country`, `health_expenditure`
## header has 1 row(s)
## body has 7 row(s)
## original dataset sample:
## region country health_expenditure
## 1 East Asia & Pacific Papua New Guinea 1.818817
## 2 Europe & Central Asia Monaco 2.028468
## 3 Latin America & Caribbean Guyana 4.022648
## 4 Middle East & North Africa Djibouti 3.075565
## 5 North America Canada 10.743625
# Create a flextable for the country with the lowest health expenditure and highest life expectancy in each region
lowest_health_exp_highest_life_exp_table <- tryCatch({
wbind %>%
group_by(region) %>%
arrange(health_expenditure) %>%
slice(1) %>%
arrange(desc(life_exp)) %>%
slice(1) %>%
select(country, health_expenditure, life_exp) %>%
flextable() %>%
colformat_double(digits = 0) # No decimal digits.
}, error = function(e) {
cat("An error occurred:", conditionMessage(e), "\n")
NULL
})
if (!is.null(lowest_health_exp_highest_life_exp_table)) {
print(lowest_health_exp_highest_life_exp_table)
}
## a flextable object.
## col_keys: `region`, `country`, `health_expenditure`, `life_exp`
## header has 1 row(s)
## body has 7 row(s)
## original dataset sample:
## region country health_expenditure life_exp
## 1 East Asia & Pacific Papua New Guinea 1.818817 64.70100
## 2 Europe & Central Asia Monaco 2.028468 NA
## 3 Latin America & Caribbean Guyana 4.022648 68.20100
## 4 Middle East & North Africa Djibouti 3.075565 61.95700
## 5 North America Canada 10.743625 81.81561
# Aggregate data to region level
region_data <- wbind %>%
group_by(region) %>%
summarise(avg_life_exp = mean(life_exp, na.rm = TRUE),
avg_health_expenditure = mean(health_expenditure, na.rm = TRUE))
# Display the first few rows of the aggregated data
head(region_data)
## # A tibble: 6 × 3
## region avg_life_exp avg_health_expenditure
## <chr> <dbl> <dbl>
## 1 East Asia & Pacific 73.2 6.61
## 2 Europe & Central Asia 77.5 7.65
## 3 Latin America & Caribbean 74.5 6.51
## 4 Middle East & North Africa 74.7 5.55
## 5 North America 80.5 13.6
## 6 South Asia 70.1 5.09
# Create a scatter plot
scatter_plot <- ggplot(data = wbind, aes(x = health_expenditure, y = life_exp, color = region)) +
geom_point(size = 3) + # Plot points
labs(x = "Health Expenditure (% of GDP)",
y = "Life Expectancy (years)",
title = "Life Expectancy vs. Health Expenditure by Region") + # Set axis labels and title
theme_minimal() + # Minimal theme
theme(legend.position = "bottom") # Move legend to the bottom
# Display the scatter plot
scatter_plot
# We aggregate the data to the region level, calculating the average life expectancy and health expenditure for each region.
# We provide summarized information that can help identify trends and patterns at a higher level of analysis.
# Aggregate data to region level
region_data <- wbind %>%
group_by(region) %>%
summarise(avg_life_exp = mean(life_exp, na.rm = TRUE),
avg_health_expenditure = mean(health_expenditure, na.rm = TRUE))
# Create a scatter plot to analyze the relationship between health expenditure and life expectancy by region
scatter_plot <- ggplot(data = wbind, aes(x = health_expenditure, y = life_exp, color = region)) +
geom_point() + # Plot points
geom_smooth(se = FALSE) + # Add smoothed line
scale_x_log10(
labels = scales::percent_format(scale = 1),
breaks = scales::log_breaks(n = 4)
) +
theme_minimal() + # Minimal theme
labs(
title = "Relationship Between Health Expenditure and Life Expectancy",
x = "Health Expenditure (% of GDP)",
y = "Life Expectancy (years)",
color = "Region",
caption = "Source: World Bank, through `wbstats`"
)
# Display the scatter plot
scatter_plot
This scatter plot represents even in a more specific way, the tendencies of each region in study, following the regression line.
Health Policy Watch. (18 December, 2023). Health Spending Reached Record Level During COVID. Health Policy Watch. https://healthpolicy-watch.news/health-spending-reached-record-level-during-covid/ World Health Organization. (2023). WHO COVID-19 Strategic Preparedness and Response Plan: Operational Planning Guidelines to Support Country Preparedness and Response (Publication No. 9789240074323). World Health Organization. https://iris.who.int/bitstream/handle/10665/367912/9789240074323-eng.pdf?sequence=1 United Nations. (n.d.). Health. United Nations Sustainable Development Goals. https://www.un.org/sustainabledevelopment/health/