Assignment-05

Author

Stan Xu

Published

February 25, 2026

2

Code
library(knitr)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Code
wdi<- read.csv('wdi.csv')

3

Code
# Summary of selected indicators
wdi %>%
  select(gdp_per_capita, inflation_rate, life_expectancy) %>%
  summary()
 gdp_per_capita   inflation_rate    life_expectancy
 Min.   :   303   Min.   : -6.687   Min.   :18.82  
 1st Qu.:  2899   1st Qu.:  5.362   1st Qu.:67.79  
 Median :  7656   Median :  7.985   Median :74.16  
 Mean   : 21143   Mean   : 12.645   Mean   :73.11  
 3rd Qu.: 28360   3rd Qu.: 12.260   3rd Qu.:78.53  
 Max.   :226052   Max.   :171.205   Max.   :85.75  
 NA's   :8        NA's   :39                       

3,4

GDP growth rate

4

Relationship between GDP per Capita and Life Expectancy

`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 8 rows containing non-finite values (`stat_smooth()`).
Warning: Removed 8 rows containing missing values (`geom_point()`).
Figure 1: Relationship between GDP per Capita and Life Expectancy.(Source:WDI, 2022)

Findings: The scatter plot shows a clear positive relationship between GDP per capita and life expectancy in 2022. Countries with higher GDP per capita generally have higher life expectancy. The upward-sloping regression line indicates that as income increases, life expectancy tends to increase as well. However, the relationship appears to flatten at higher income levels

Education Expenditure (% GDP)

Code
ggplot(wdi, aes(x = gdp_growth_rate)) +
  geom_histogram(fill = "steelblue", bins = 20) +
  labs(
    title = "Distribution of GDP Growth Rate",
    x = "GDP Growth Rate (%)",
    y = "Count"
  ) +
  theme_minimal()
Warning: Removed 8 rows containing non-finite values (`stat_bin()`).
Figure 2: Distribution of GDP Growth Rate (Source:WDI, 2022)

The boxplot compares education expenditure as a share of GDP between high-growth and low-growth countries. It shows that both groups allocate a similar proportion of GDP to education, with medians around 3–5%.

Findings: The histogram of GDP growth rates shows that most countries cluster around modest positive growth between approximately –5% and 10%. However, the distribution has small number of countries experiencing extremely high growth rates (above 20% and even near 60%) and a few cases of severe economic contraction (around –30%).

5

Code
wdi_summary <- wdi %>%
  summarise(
    Avg_GDP_Capita = mean(gdp_per_capita, na.rm = TRUE),
    Avg_GDP_Growth = mean(gdp_growth_rate, na.rm = TRUE),
    Avg_Inflation = mean(inflation_rate, na.rm = TRUE),
    Avg_Life_Exp = mean(life_expectancy, na.rm = TRUE)
  )

kable(wdi_summary, digits = 2)
Table 1: Average Global Indicators for 2022
Avg_GDP_Capita Avg_GDP_Growth Avg_Inflation Avg_Life_Exp
21142.75 4.51 12.65 73.11

7

The data for this analysis is sourced from the World Bank (2022). The second research by Rosling, Rönnlund, and Rosling (2011) shows that the historical gap between wealth and health outcomes is gradually closing as shown in Figure 1.

References

Rosling, Hans, Anna Rosling Rönnlund, and Ola Rosling. 2011. “Health and Wealth: The Gap Is Closing.” Journal of Global Development 2 (1): 1–15.
World Bank. 2022. “World Development Indicators 2022.” https://databank.worldbank.org/source/world-development-indicators.