Question: Is there a difference in life expectancy between developed and undeveloped countries? (Compare other variables across developed countries vs undeveloped countries.)

Import Libraries

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.0     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.2.0     
## ── 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
library(ggplot2)
library(dplyr)
library(corrplot)
## corrplot 0.95 loaded
library(GGally)

Step 1: Random Split Data (70/30)

LE <- na.omit(read.csv("Life Expectancy Data.csv"))

set.seed(127) 
n <- nrow(LE)
train_index <- sample(1:n, size = 0.7*n)
train_data <- LE[train_index, ]
test_data  <- LE[-train_index, ]

Step 2: Data Description

Dataset source and context:

  • The data used in this study come from the World Health Organization (WHO) and report life expectancy and related health, demographic, and economic indicators for countries worldwide from 2000 to 2015 with 2938 observations (before the cleaning of the dataset). The dataset provides a cross-section of public health conditions across both Developed and Developing countries. Each row represents a specific country-year observation.

Definitions, types, and units of all variables:

str(LE)
## 'data.frame':    1649 obs. of  22 variables:
##  $ Country                        : chr  "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
##  $ Year                           : int  2015 2014 2013 2012 2011 2010 2009 2008 2007 2006 ...
##  $ Status                         : chr  "Developing" "Developing" "Developing" "Developing" ...
##  $ Life.expectancy                : num  65 59.9 59.9 59.5 59.2 58.8 58.6 58.1 57.5 57.3 ...
##  $ Adult.Mortality                : int  263 271 268 272 275 279 281 287 295 295 ...
##  $ infant.deaths                  : int  62 64 66 69 71 74 77 80 82 84 ...
##  $ Alcohol                        : num  0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.03 0.02 0.03 ...
##  $ percentage.expenditure         : num  71.3 73.5 73.2 78.2 7.1 ...
##  $ Hepatitis.B                    : int  65 62 64 67 68 66 63 64 63 64 ...
##  $ Measles                        : int  1154 492 430 2787 3013 1989 2861 1599 1141 1990 ...
##  $ BMI                            : num  19.1 18.6 18.1 17.6 17.2 16.7 16.2 15.7 15.2 14.7 ...
##  $ under.five.deaths              : int  83 86 89 93 97 102 106 110 113 116 ...
##  $ Polio                          : int  6 58 62 67 68 66 63 64 63 58 ...
##  $ Total.expenditure              : num  8.16 8.18 8.13 8.52 7.87 9.2 9.42 8.33 6.73 7.43 ...
##  $ Diphtheria                     : int  65 62 64 67 68 66 63 64 63 58 ...
##  $ HIV.AIDS                       : num  0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 ...
##  $ GDP                            : num  584.3 612.7 631.7 670 63.5 ...
##  $ Population                     : num  33736494 327582 31731688 3696958 2978599 ...
##  $ thinness..1.19.years           : num  17.2 17.5 17.7 17.9 18.2 18.4 18.6 18.8 19 19.2 ...
##  $ thinness.5.9.years             : num  17.3 17.5 17.7 18 18.2 18.4 18.7 18.9 19.1 19.3 ...
##  $ Income.composition.of.resources: num  0.479 0.476 0.47 0.463 0.454 0.448 0.434 0.433 0.415 0.405 ...
##  $ Schooling                      : num  10.1 10 9.9 9.8 9.5 9.2 8.9 8.7 8.4 8.1 ...
##  - attr(*, "na.action")= 'omit' Named int [1:1289] 33 45 46 47 48 49 58 59 60 61 ...
##   ..- attr(*, "names")= chr [1:1289] "33" "45" "46" "47" ...
  • Country (Categorical): Name of the country.
  • Year (Numerical/Integer): Year observed.
  • Status (Categorical/Binary): Developed or Developing status.
  • Life.expectancy (Numerical): Average expected lifespan at birth in age.
  • Adult.Mortality (Numerical/Integer): Adult Mortality Rates of both sexes (probability of dying between 15 and 60 years per 1000 population).
  • infant.deaths (Numerical/Integer): Number of Infant Deaths per 1000 population.
  • Alcohol (Numerical): Alcohol, recorded per capita (15+) consumption (in litres of pure alcohol).
  • percentage.expenditure (Numerical): Expenditure on health as a percentage of Gross Domestic Product per capita(%).
  • Hepatitis.B (Numerical/Integer): Hepatitis B (HepB) immunization coverage among 1-year-olds (%).
  • Measles (Numerical/Integer): number of reported cases of measels per 1000 population.
  • BMI (Numerical): Average Body Mass Index of entire population.
  • under.five.deaths (Numerical/Integer): Number of under-five deaths per 1000 population.
  • Polio (Numerical/Integer): Polio (Pol3) immunization coverage among 1-year-olds (%).
  • Total.expenditure (Numerical): General government expenditure on health as a percentage of total government expenditure (%).
  • Diphtheria (Numerical/Integer): Diphtheria tetanus toxoid and pertussis (DTP3) immunization coverage among 1-year-olds (%).
  • HIV.AIDS (Numerical): Deaths per 1 000 live births HIV/AIDS (0-4 years).
  • GDP (Numerical): Gross Domestic Product per capita (in USD).
  • Population (Numerical): Population of the country.
  • thinness..1.19.years (Numerical): Prevalence of thinness among children and adolescents for Age 10 to 19 (%).
  • thinness.5.9.years (Numerical): Prevalence of thinness among children for Age 5 to 9(%).
  • Income.composition.of.resources (Numerical): Human Development Index in terms of income composition of resources (index ranging from 0 to 1).
  • Schooling (Numerical): Number of years of Schooling(years).

Identify the response variable (Y) and candidate predictors:

  • Response Variable (Y): Life.expectancy
  • Candidate Predictors (X_i): Status, Adult.Mortality, infant.deaths, Schooling, Population

Sample size (after split & removal of na values):

nrow(train_data)
## [1] 1154
  • There are 1,649 observations after removing missing entries. We will be using the train_data as our sample size, which is 70% of the LE data and has 1,154 observations. The seed being used is 127.

Step 3: Descriptive Statistics

Numerical Variables

# Year Summary Stats 
train_data %>%
  summarise(
    Year_mean  = mean(Year, na.rm = TRUE),
    Year_median = median(Year, na.rm = TRUE),
    Year_sd    = sd(Year, na.rm = TRUE),
    Year_min   = min(Year, na.rm = TRUE),
    Year_Q1    = quantile(Year, 0.25, na.rm = TRUE),
    Year_Q3    = quantile(Year, 0.75, na.rm = TRUE),
    Year_max   = max(Year, na.rm = TRUE)
)
##   Year_mean Year_median Year_sd Year_min Year_Q1 Year_Q3 Year_max
## 1  2007.879        2008  4.1054     2000    2005    2011     2015
# Life Expectancy Summary Stats
train_data %>%
  summarise(
    Life.expectancy_mean  = mean(Life.expectancy, na.rm = TRUE),
    Life.expectancy_median = median(Life.expectancy, na.rm = TRUE),
    Life.expectancy_sd    = sd(Life.expectancy, na.rm = TRUE),
    Life.expectancy_min   = min(Life.expectancy, na.rm = TRUE),
    Life.expectancy_Q1    = quantile(Life.expectancy, 0.25, na.rm = TRUE),
    Life.expectancy_Q3    = quantile(Life.expectancy, 0.75, na.rm = TRUE),
    Life.expectancy_max   = max(Life.expectancy, na.rm = TRUE)
)
##   Life.expectancy_mean Life.expectancy_median Life.expectancy_sd
## 1             69.28735                   71.7           8.708508
##   Life.expectancy_min Life.expectancy_Q1 Life.expectancy_Q3 Life.expectancy_max
## 1                  44               64.3               74.9                  89
# Adult Mortality Summary Stats
train_data %>%
  summarise(
    Adult.Mortality_mean  = mean(Adult.Mortality, na.rm = TRUE),
    Adult.Mortality_median = median(Adult.Mortality, na.rm = TRUE),
    Adult.Mortality_sd    = sd(Adult.Mortality, na.rm = TRUE),
    Adult.Mortality_min   = min(Adult.Mortality, na.rm = TRUE),
    Adult.Mortality_Q1    = quantile(Adult.Mortality, 0.25, na.rm = TRUE),
    Adult.Mortality_Q3    = quantile(Adult.Mortality, 0.75, na.rm = TRUE),
    Adult.Mortality_max   = max(Adult.Mortality, na.rm = TRUE)
)
##   Adult.Mortality_mean Adult.Mortality_median Adult.Mortality_sd
## 1             164.3068                    148           120.8728
##   Adult.Mortality_min Adult.Mortality_Q1 Adult.Mortality_Q3 Adult.Mortality_max
## 1                   1                 74                225                 723
# Infant Deaths Summary Stats
train_data %>%
  summarise(
    infant.deaths_mean  = mean(infant.deaths, na.rm = TRUE),
    infant.deaths_median = median(infant.deaths, na.rm = TRUE),
    infant.deaths_sd    = sd(infant.deaths, na.rm = TRUE),
    infant.deaths_min   = min(infant.deaths, na.rm = TRUE),
    infant.deaths_Q1    = quantile(infant.deaths, 0.25, na.rm = TRUE),
    infant.deaths_Q3    = quantile(infant.deaths, 0.75, na.rm = TRUE),
    infant.deaths_max   = max(infant.deaths, na.rm = TRUE)
)
##   infant.deaths_mean infant.deaths_median infant.deaths_sd infant.deaths_min
## 1           33.12132                    3         124.7535                 0
##   infant.deaths_Q1 infant.deaths_Q3 infant.deaths_max
## 1                1               23              1600
# Alcohol Summary Stats
train_data %>%
  summarise(
    Alcohol_mean  = mean(Alcohol, na.rm = TRUE),
    Alcohol_median = median(Alcohol, na.rm = TRUE),
    Alcohol_sd    = sd(Alcohol, na.rm = TRUE),
    Alcohol_min   = min(Alcohol, na.rm = TRUE),
    Alcohol_Q1    = quantile(Alcohol, 0.25, na.rm = TRUE),
    Alcohol_Q3    = quantile(Alcohol, 0.75, na.rm = TRUE),
    Alcohol_max   = max(Alcohol, na.rm = TRUE)
)
##   Alcohol_mean Alcohol_median Alcohol_sd Alcohol_min Alcohol_Q1 Alcohol_Q3
## 1      4.39753           3.69   3.942453        0.01      0.685     7.1375
##   Alcohol_max
## 1       17.87
# Percentage Ependiture Summary Stats
train_data %>%
  summarise(
    percentage.expenditure_mean  = mean(percentage.expenditure, na.rm = TRUE),
    percentage.expenditure_median = median(percentage.expenditure, na.rm = TRUE),
    percentage.expenditure_sd    = sd(percentage.expenditure, na.rm = TRUE),
    percentage.expenditure_min   = min(percentage.expenditure, na.rm = TRUE),
    percentage.expenditure_Q1    = quantile(percentage.expenditure, 0.25, na.rm = TRUE),
    percentage.expenditure_Q3    = quantile(percentage.expenditure, 0.75, na.rm = TRUE),
    percentage.expenditure_max   = max(percentage.expenditure, na.rm = TRUE)
)
##   percentage.expenditure_mean percentage.expenditure_median
## 1                    651.3056                      145.0437
##   percentage.expenditure_sd percentage.expenditure_min
## 1                  1629.372                          0
##   percentage.expenditure_Q1 percentage.expenditure_Q3
## 1                   38.1045                   501.721
##   percentage.expenditure_max
## 1                   18961.35
# Hepatitis B Summary Stats
train_data %>%
  summarise(
    Hepatitis.B_mean  = mean(Hepatitis.B, na.rm = TRUE),
    Hepatitis.B_median = median(Hepatitis.B, na.rm = TRUE),
    Hepatitis.B_sd    = sd(Hepatitis.B, na.rm = TRUE),
    Hepatitis.B_min   = min(Hepatitis.B, na.rm = TRUE),
    Hepatitis.B_Q1    = quantile(Hepatitis.B, 0.25, na.rm = TRUE),
    Hepatitis.B_Q3    = quantile(Hepatitis.B, 0.75, na.rm = TRUE),
    Hepatitis.B_max   = max(Hepatitis.B, na.rm = TRUE)
)
##   Hepatitis.B_mean Hepatitis.B_median Hepatitis.B_sd Hepatitis.B_min
## 1         79.08232                 89       25.74104               2
##   Hepatitis.B_Q1 Hepatitis.B_Q3 Hepatitis.B_max
## 1             74             96              99
# Measles Summary Stats
train_data %>%
  summarise(
    Measles_mean  = mean(Measles, na.rm = TRUE),
    Measles_median = median(Measles, na.rm = TRUE),
    Measles_sd    = sd(Measles, na.rm = TRUE),
    Measles_min   = min(Measles, na.rm = TRUE),
    Measles_Q1    = quantile(Measles, 0.25, na.rm = TRUE),
    Measles_Q3    = quantile(Measles, 0.75, na.rm = TRUE),
    Measles_max   = max(Measles, na.rm = TRUE)
)
##   Measles_mean Measles_median Measles_sd Measles_min Measles_Q1 Measles_Q3
## 1     2192.435             18   9995.222           0          0        394
##   Measles_max
## 1      131441
# BMI Summary Stats
train_data %>%
  summarise(
    BMI_mean  = mean(BMI, na.rm = TRUE),
    BMI_median = median(BMI, na.rm = TRUE),
    BMI_sd    = sd(BMI, na.rm = TRUE),
    BMI_min   = min(BMI, na.rm = TRUE),
    BMI_Q1    = quantile(BMI, 0.25, na.rm = TRUE),
    BMI_Q3    = quantile(BMI, 0.75, na.rm = TRUE),
    BMI_max   = max(BMI, na.rm = TRUE)
)
##   BMI_mean BMI_median   BMI_sd BMI_min BMI_Q1 BMI_Q3 BMI_max
## 1 37.92998      43.55 19.82661     2.1 19.025   55.7    77.1
# Under Five Deaths Summary Stats
train_data %>%
  summarise(
    under.five.deaths_mean  = mean(under.five.deaths, na.rm = TRUE),
    under.five.deaths_median = median(under.five.deaths, na.rm = TRUE),
    under.five.deaths_sd    = sd(under.five.deaths, na.rm = TRUE),
    under.five.deaths_min   = min(under.five.deaths, na.rm = TRUE),
    under.five.deaths_Q1    = quantile(under.five.deaths, 0.25, na.rm = TRUE),
    under.five.deaths_Q3    = quantile(under.five.deaths, 0.75, na.rm = TRUE),
    under.five.deaths_max   = max(under.five.deaths, na.rm = TRUE)
)
##   under.five.deaths_mean under.five.deaths_median under.five.deaths_sd
## 1               44.94627                        4             167.3134
##   under.five.deaths_min under.five.deaths_Q1 under.five.deaths_Q3
## 1                     0                    1                   32
##   under.five.deaths_max
## 1                  2100
# Polio Summary Stats
train_data %>%
  summarise(
    Polio_mean  = mean(Polio, na.rm = TRUE),
    Polio_median = median(Polio, na.rm = TRUE),
    Polio_sd    = sd(Polio, na.rm = TRUE),
    Polio_min   = min(Polio, na.rm = TRUE),
    Polio_Q1    = quantile(Polio, 0.25, na.rm = TRUE),
    Polio_Q3    = quantile(Polio, 0.75, na.rm = TRUE),
    Polio_max   = max(Polio, na.rm = TRUE)
  )
##   Polio_mean Polio_median Polio_sd Polio_min Polio_Q1 Polio_Q3 Polio_max
## 1   82.79289           93 23.54729         3       79       97        99
# Total Expenditure Summary Stats
train_data %>%
  summarise(
    Total.expenditure_mean  = mean(Total.expenditure, na.rm = TRUE),
    Total.expenditure_median = median(Total.expenditure, na.rm = TRUE),
    Total.expenditure_sd    = sd(Total.expenditure, na.rm = TRUE),
    Total.expenditure_min   = min(Total.expenditure, na.rm = TRUE),
    Total.expenditure_Q1    = quantile(Total.expenditure, 0.25, na.rm = TRUE),
    Total.expenditure_Q3    = quantile(Total.expenditure, 0.75, na.rm = TRUE),
    Total.expenditure_max   = max(Total.expenditure, na.rm = TRUE)
)
##   Total.expenditure_mean Total.expenditure_median Total.expenditure_sd
## 1               5.982045                     5.89             2.305812
##   Total.expenditure_min Total.expenditure_Q1 Total.expenditure_Q3
## 1                  0.74                 4.39               7.5225
##   Total.expenditure_max
## 1                 14.39
# Diptheria Summary Stats
train_data %>%
  summarise(
    Diphtheria_mean  = mean(Diphtheria, na.rm = TRUE),
    Diphtheria_median = median(Diphtheria, na.rm = TRUE),
    Diphtheria_sd    = sd(Diphtheria, na.rm = TRUE),
    Diphtheria_min   = min(Diphtheria, na.rm = TRUE),
    Diphtheria_Q1    = quantile(Diphtheria, 0.25, na.rm = TRUE),
    Diphtheria_Q3    = quantile(Diphtheria, 0.75, na.rm = TRUE),
    Diphtheria_max   = max(Diphtheria, na.rm = TRUE)
)
##   Diphtheria_mean Diphtheria_median Diphtheria_sd Diphtheria_min Diphtheria_Q1
## 1        83.83016                92      21.90112              2            81
##   Diphtheria_Q3 Diphtheria_max
## 1            97             99
# HIV AIDS Summary Stats
train_data %>%
  summarise(
    HIV.AIDS_mean  = mean(HIV.AIDS, na.rm = TRUE),
    HIV.AIDS_median = median(HIV.AIDS, na.rm = TRUE),
    HIV.AIDS_sd    = sd(HIV.AIDS, na.rm = TRUE),
    HIV.AIDS_min   = min(HIV.AIDS, na.rm = TRUE),
    HIV.AIDS_Q1    = quantile(HIV.AIDS, 0.25, na.rm = TRUE),
    HIV.AIDS_Q3    = quantile(HIV.AIDS, 0.75, na.rm = TRUE),
    HIV.AIDS_max   = max(HIV.AIDS, na.rm = TRUE)
)
##   HIV.AIDS_mean HIV.AIDS_median HIV.AIDS_sd HIV.AIDS_min HIV.AIDS_Q1
## 1      1.880069             0.1     5.69773          0.1         0.1
##   HIV.AIDS_Q3 HIV.AIDS_max
## 1         0.7         50.6
# GDP Summary Stats
train_data %>%
  summarise(
    GDP_mean  = mean(GDP, na.rm = TRUE),
    GDP_median = median(GDP, na.rm = TRUE),
    GDP_sd    = sd(GDP, na.rm = TRUE),
    GDP_min   = min(GDP, na.rm = TRUE),
    GDP_Q1    = quantile(GDP, 0.25, na.rm = TRUE),
    GDP_Q3    = quantile(GDP, 0.75, na.rm = TRUE),
    GDP_max   = max(GDP, na.rm = TRUE)
)
##   GDP_mean GDP_median  GDP_sd GDP_min   GDP_Q1   GDP_Q3  GDP_max
## 1  5274.42   1522.676 10656.6 1.68135 455.3507 4674.074 114293.8
# Population Summary Stats
train_data %>%
  summarise(
    Population_mean  = mean(Population, na.rm = TRUE),
    Population_median = median(Population, na.rm = TRUE),
    Population_sd    = sd(Population, na.rm = TRUE),
    Population_min   = min(Population, na.rm = TRUE),
    Population_Q1    = quantile(Population, 0.25, na.rm = TRUE),
    Population_Q3    = quantile(Population, 0.75, na.rm = TRUE),
    Population_max   = max(Population, na.rm = TRUE)
)
##   Population_mean Population_median Population_sd Population_min Population_Q1
## 1        14819584           1344918      72573412             36        182596
##   Population_Q3 Population_max
## 1       7524793     1179681239
# Thinness 10-19 Summary Stats
train_data %>%
  summarise(
    thinness..1.19.years_mean  = mean(thinness..1.19.years, na.rm = TRUE),
    thinness..1.19.years_median = median(thinness..1.19.years, na.rm = TRUE),
    thinness..1.19.years_sd    = sd(thinness..1.19.years, na.rm = TRUE),
    thinness..1.19.years_min   = min(thinness..1.19.years, na.rm = TRUE),
    thinness..1.19.years_Q1    = quantile(thinness..1.19.years, 0.25, na.rm = TRUE),
    thinness..1.19.years_Q3    = quantile(thinness..1.19.years, 0.75, na.rm = TRUE),
    thinness..1.19.years_max   = max(thinness..1.19.years, na.rm = TRUE)
)
##   thinness..1.19.years_mean thinness..1.19.years_median thinness..1.19.years_sd
## 1                  4.863692                           3                4.642256
##   thinness..1.19.years_min thinness..1.19.years_Q1 thinness..1.19.years_Q3
## 1                      0.1                     1.6                       7
##   thinness..1.19.years_max
## 1                     27.2
# Thinness 5-9 Summary Stats
train_data %>%
  summarise(
    thinness.5.9.years_mean  = mean(thinness.5.9.years, na.rm = TRUE),
    thinness.5.9.years_median = median(thinness.5.9.years, na.rm = TRUE),
    thinness.5.9.years_sd    = sd(thinness.5.9.years, na.rm = TRUE),
    thinness.5.9.years_min   = min(thinness.5.9.years, na.rm = TRUE),
    thinness.5.9.years_Q1    = quantile(thinness.5.9.years, 0.25, na.rm = TRUE),
    thinness.5.9.years_Q3    = quantile(thinness.5.9.years, 0.75, na.rm = TRUE),
    thinness.5.9.years_max   = max(thinness.5.9.years, na.rm = TRUE)
)
##   thinness.5.9.years_mean thinness.5.9.years_median thinness.5.9.years_sd
## 1                4.941334                       3.1              4.716583
##   thinness.5.9.years_min thinness.5.9.years_Q1 thinness.5.9.years_Q3
## 1                    0.1                   1.6                   7.1
##   thinness.5.9.years_max
## 1                   28.2
# Income Composition of Resources Summary Stats
train_data %>%
  summarise(
    Income.composition.of.resources_mean  = mean(Income.composition.of.resources, na.rm = TRUE),
    Income.composition.of.resources_median = median(Income.composition.of.resources, na.rm = TRUE),
    Income.composition.of.resources_sd    = sd(Income.composition.of.resources, na.rm = TRUE),
    Income.composition.of.resources_min   = min(Income.composition.of.resources, na.rm = TRUE),
    Income.composition.of.resources_Q1    = quantile(Income.composition.of.resources, 0.25, na.rm = TRUE),
    Income.composition.of.resources_Q3    = quantile(Income.composition.of.resources, 0.75, na.rm = TRUE),
    Income.composition.of.resources_max   = max(Income.composition.of.resources, na.rm = TRUE)
)
##   Income.composition.of.resources_mean Income.composition.of.resources_median
## 1                            0.6311144                                  0.673
##   Income.composition.of.resources_sd Income.composition.of.resources_min
## 1                          0.1803673                                   0
##   Income.composition.of.resources_Q1 Income.composition.of.resources_Q3
## 1                            0.50625                              0.748
##   Income.composition.of.resources_max
## 1                               0.936
# Schooling Summary Stats
train_data %>%
  summarise(
    Schooling_mean  = mean(Schooling, na.rm = TRUE),
    Schooling_median = median(Schooling, na.rm = TRUE),
    Schooling_sd    = sd(Schooling, na.rm = TRUE),
    Schooling_min   = min(Schooling, na.rm = TRUE),
    Schooling_Q1    = quantile(Schooling, 0.25, na.rm = TRUE),
    Schooling_Q3    = quantile(Schooling, 0.75, na.rm = TRUE),
    Schooling_max   = max(Schooling, na.rm = TRUE)
)
##   Schooling_mean Schooling_median Schooling_sd Schooling_min Schooling_Q1
## 1        12.0714             12.2     2.817797           4.4         10.4
##   Schooling_Q3 Schooling_max
## 1       13.875          20.7
Numerical Variable Interpretations:
  • Year – median year 2008; no skew in data.
  • Life expectancy – median ~ 71.7 years & mean 69.28; normally distributed.
  • Adult Mortality – sd ~ 120.87 deaths/1000; large cross-country differences.
  • Infant deaths – median ~ 3, but max 1600; strongly right-skewed.
  • Alcohol – sd ~ 3.94; wide variation across countries.
  • Percentage expenditure – median 145, but max 18,961; strongly right-skewed.
  • Hepatitis B – median 89% vaccinated; generally high but inconsistent.
  • Measles – median 18 cases, but outbreaks raise max >130,000.
  • BMI – median 43.6; reflects differences in nutrition and development.
  • Under-five deaths – median 4, but can exceed 2000; strongly right-skewed.
  • Polio – median 93% coverage; high immunization overall.
  • Total expenditure – median 5.9% of government spending; moderate variation.
  • Diphtheria – median 92% coverage; parallels Polio and Hep B patterns.
  • HIV/AIDS deaths – median 0.1 but max 50.6; right-skewed burden.
  • GDP – median $1,523, mean ~ $5,274; indicates strong right-skew and inequality.
  • Population – median 1.34 million, max >1 billion; extremely skewed.
  • Thinness (1–19 yrs) – median 3%; higher rates in lower-income regions.
  • Thinness (5–9 yrs) – median 3.1%; similar pattern to age 1–19 group.
  • Income composition of resources – median 0.67 on a 0–1 scale; reflects developmental variation.
  • Schooling – median 12.2 years; indicates differing education access globally.

Categorical Variables

# Country 
## Frequency Table
country_freq <- table(train_data$Country)
country_freq
## 
##              Afghanistan                  Albania                  Algeria 
##                       15                       15                        9 
##                   Angola                Argentina                  Armenia 
##                        5                       11                       11 
##                Australia                  Austria               Azerbaijan 
##                       10                        7                       10 
##               Bangladesh                  Belarus                  Belgium 
##                        9                       11                        9 
##                   Belize                    Benin                   Bhutan 
##                       12                        9                        8 
##   Bosnia and Herzegovina                 Botswana                   Brazil 
##                        7                        9                        9 
##                 Bulgaria             Burkina Faso                  Burundi 
##                       12                        9                        9 
##               Cabo Verde                 Cambodia                 Cameroon 
##                        6                        7                        7 
##                   Canada Central African Republic                     Chad 
##                       11                        3                        6 
##                    Chile                    China                 Colombia 
##                        6                        9                       11 
##                  Comoros               Costa Rica                  Croatia 
##                        9                       11                        7 
##                   Cyprus                 Djibouti       Dominican Republic 
##                       11                        5                        7 
##                  Ecuador              El Salvador        Equatorial Guinea 
##                       11                        8                        1 
##                  Eritrea                  Estonia                 Ethiopia 
##                        9                        6                        6 
##                     Fiji                   France                    Gabon 
##                       11                       10                        6 
##                  Georgia                  Germany                    Ghana 
##                       13                        8                       10 
##                   Greece                Guatemala                   Guinea 
##                       11                        7                        5 
##            Guinea-Bissau                   Guyana                    Haiti 
##                        3                        9                        1 
##                 Honduras                    India                Indonesia 
##                        7                        8                       10 
##                     Iraq                  Ireland                   Israel 
##                       10                        3                       12 
##                    Italy                  Jamaica                   Jordan 
##                       11                        9                       13 
##               Kazakhstan                    Kenya                 Kiribati 
##                       12                       12                       11 
##                   Latvia                  Lebanon                  Lesotho 
##                       10                       12                        8 
##                  Liberia                Lithuania               Luxembourg 
##                        4                       10                        8 
##               Madagascar                   Malawi                 Malaysia 
##                        6                       11                       11 
##                 Maldives                     Mali                    Malta 
##                        9                        9                        8 
##               Mauritania                Mauritius                   Mexico 
##                        8                       13                       13 
##                 Mongolia               Montenegro                  Morocco 
##                       11                        6                        9 
##               Mozambique                  Myanmar                  Namibia 
##                        9                       10                        3 
##                    Nepal              Netherlands                Nicaragua 
##                       10                        2                       13 
##                    Niger                  Nigeria                 Pakistan 
##                        2                        6                        9 
##                   Panama         Papua New Guinea                 Paraguay 
##                       12                       13                        9 
##                     Peru              Philippines                   Poland 
##                        7                       11                        9 
##                 Portugal                  Romania       Russian Federation 
##                        9                       10                        5 
##                   Rwanda                    Samoa    Sao Tome and Principe 
##                       11                       10                        6 
##                  Senegal                   Serbia               Seychelles 
##                        6                        9                        9 
##             Sierra Leone          Solomon Islands             South Africa 
##                        4                        7                       12 
##                    Spain                Sri Lanka                 Suriname 
##                        8                        8                        9 
##                Swaziland                   Sweden     Syrian Arab Republic 
##                       11                        3                        6 
##               Tajikistan                 Thailand              Timor-Leste 
##                        6                       10                        5 
##                     Togo                    Tonga      Trinidad and Tobago 
##                        5                       12                        8 
##                  Tunisia                   Turkey             Turkmenistan 
##                       10                        6                       10 
##                   Uganda                  Ukraine                  Uruguay 
##                       10                       12                       12 
##               Uzbekistan                  Vanuatu                   Zambia 
##                       11                       13                        6 
##                 Zimbabwe 
##                        9
## Percentage Table
round(prop.table(country_freq) * 100, 2)
## 
##              Afghanistan                  Albania                  Algeria 
##                     1.30                     1.30                     0.78 
##                   Angola                Argentina                  Armenia 
##                     0.43                     0.95                     0.95 
##                Australia                  Austria               Azerbaijan 
##                     0.87                     0.61                     0.87 
##               Bangladesh                  Belarus                  Belgium 
##                     0.78                     0.95                     0.78 
##                   Belize                    Benin                   Bhutan 
##                     1.04                     0.78                     0.69 
##   Bosnia and Herzegovina                 Botswana                   Brazil 
##                     0.61                     0.78                     0.78 
##                 Bulgaria             Burkina Faso                  Burundi 
##                     1.04                     0.78                     0.78 
##               Cabo Verde                 Cambodia                 Cameroon 
##                     0.52                     0.61                     0.61 
##                   Canada Central African Republic                     Chad 
##                     0.95                     0.26                     0.52 
##                    Chile                    China                 Colombia 
##                     0.52                     0.78                     0.95 
##                  Comoros               Costa Rica                  Croatia 
##                     0.78                     0.95                     0.61 
##                   Cyprus                 Djibouti       Dominican Republic 
##                     0.95                     0.43                     0.61 
##                  Ecuador              El Salvador        Equatorial Guinea 
##                     0.95                     0.69                     0.09 
##                  Eritrea                  Estonia                 Ethiopia 
##                     0.78                     0.52                     0.52 
##                     Fiji                   France                    Gabon 
##                     0.95                     0.87                     0.52 
##                  Georgia                  Germany                    Ghana 
##                     1.13                     0.69                     0.87 
##                   Greece                Guatemala                   Guinea 
##                     0.95                     0.61                     0.43 
##            Guinea-Bissau                   Guyana                    Haiti 
##                     0.26                     0.78                     0.09 
##                 Honduras                    India                Indonesia 
##                     0.61                     0.69                     0.87 
##                     Iraq                  Ireland                   Israel 
##                     0.87                     0.26                     1.04 
##                    Italy                  Jamaica                   Jordan 
##                     0.95                     0.78                     1.13 
##               Kazakhstan                    Kenya                 Kiribati 
##                     1.04                     1.04                     0.95 
##                   Latvia                  Lebanon                  Lesotho 
##                     0.87                     1.04                     0.69 
##                  Liberia                Lithuania               Luxembourg 
##                     0.35                     0.87                     0.69 
##               Madagascar                   Malawi                 Malaysia 
##                     0.52                     0.95                     0.95 
##                 Maldives                     Mali                    Malta 
##                     0.78                     0.78                     0.69 
##               Mauritania                Mauritius                   Mexico 
##                     0.69                     1.13                     1.13 
##                 Mongolia               Montenegro                  Morocco 
##                     0.95                     0.52                     0.78 
##               Mozambique                  Myanmar                  Namibia 
##                     0.78                     0.87                     0.26 
##                    Nepal              Netherlands                Nicaragua 
##                     0.87                     0.17                     1.13 
##                    Niger                  Nigeria                 Pakistan 
##                     0.17                     0.52                     0.78 
##                   Panama         Papua New Guinea                 Paraguay 
##                     1.04                     1.13                     0.78 
##                     Peru              Philippines                   Poland 
##                     0.61                     0.95                     0.78 
##                 Portugal                  Romania       Russian Federation 
##                     0.78                     0.87                     0.43 
##                   Rwanda                    Samoa    Sao Tome and Principe 
##                     0.95                     0.87                     0.52 
##                  Senegal                   Serbia               Seychelles 
##                     0.52                     0.78                     0.78 
##             Sierra Leone          Solomon Islands             South Africa 
##                     0.35                     0.61                     1.04 
##                    Spain                Sri Lanka                 Suriname 
##                     0.69                     0.69                     0.78 
##                Swaziland                   Sweden     Syrian Arab Republic 
##                     0.95                     0.26                     0.52 
##               Tajikistan                 Thailand              Timor-Leste 
##                     0.52                     0.87                     0.43 
##                     Togo                    Tonga      Trinidad and Tobago 
##                     0.43                     1.04                     0.69 
##                  Tunisia                   Turkey             Turkmenistan 
##                     0.87                     0.52                     0.87 
##                   Uganda                  Ukraine                  Uruguay 
##                     0.87                     1.04                     1.04 
##               Uzbekistan                  Vanuatu                   Zambia 
##                     0.95                     1.13                     0.52 
##                 Zimbabwe 
##                     0.78
# Status
## Frequency Table
status_freq <- table(train_data$Status)
status_freq
## 
##  Developed Developing 
##        155        999
## Percentage Table
round(prop.table(status_freq) * 100, 2)
## 
##  Developed Developing 
##      13.43      86.57
Categorical Variable Interpretations:
  • Country - The frequency of a certain country ranges from 6-15, the frequency 15 indicating all the years from 2000-2015 of a country’s observations are included. Any less than 15 means certain observations were removed during data cleaning to get rid of the present NA values.
  • Status - Developing countries make up about 86.6% of the training data, while Developed countries make up about 13.4%. This means the dataset is weighted toward lower-income nations, which may affect comparisons of health indicators and life expectancy.

Step 4: Visual Exploration

Numerical Variable Histograms

par(mfrow = c(4, 5), mar = c(2, 2, 2, 1))

hist(train_data$Year, main = "Year")
hist(train_data$Life.expectancy, main = "Life Expectancy")
hist(train_data$Adult.Mortality, main = "Adult Mortality")
hist(train_data$infant.deaths, main = "Infant Deaths")
hist(train_data$Alcohol, main = "Alcohol")
hist(train_data$percentage.expenditure, main = "Percentage Expenditure")
hist(train_data$Hepatitis.B, main = "Hepatitis B")
hist(train_data$Measles, main = "Measles")
hist(train_data$BMI, main = "BMI")
hist(train_data$under.five.deaths, main = "Under-Five Deaths")
hist(train_data$Polio, main = "Polio")
hist(train_data$Total.expenditure, main = "Total Expenditure")
hist(train_data$Diphtheria, main = "Diphtheria")
hist(train_data$HIV.AIDS, main = "HIV/AIDS")
hist(train_data$GDP, main = "GDP")
hist(train_data$Population, main = "Population")
hist(train_data$thinness..1.19.years, main = "Thinness (10–19)")
hist(train_data$thinness.5.9.years, main = "Thinness (5–9)")
hist(train_data$Income.composition.of.resources, main = "Income Composition")
hist(train_data$Schooling, main = "Schooling")

Categorical Variable Bar Charts

barplot(table(train_data$Status), main = "Status", col = c("blue", "red"))

barplot(table(train_data$Country), main = "Country")

vars <- c("Life.expectancy", "Adult.Mortality", "Schooling", "infant.deaths", "Population") 
cor_matrix <- cor(train_data[, vars], use = "complete.obs") 
corrplot(cor_matrix,
         method = "color",
         type = "lower",
         addCoef.col = "black",
         number.cex = 0.7,
         tl.col = "black", 
         tl.srt = 45,
         diag = FALSE,
         title = "Correlation Matrix (Training Data)",
         mar = c(0, 0, 2, 0))