2025-04-18

Introduction

This project analyzes the life expectancy of people from various countries around the world using several socioeconomic factors with the purpose of understanding how these factors relate to life expectancy.

Dataset

The data set used for this project originates from WHO and UN data compiled in a csv file. It pulls data from 193 different countries between the years of 2000 and 2015. In general, it contains 22 columns and 2938 rows, with 20 predicting variables.

These variables include the following key factors: adult mortality, infant deaths, alcohol consumption per capita, expenditure on health as percentage of Gross Domestic Product (GDP), Hepatitis B immunization records, number of measles cases, average body mass index (BMI) of entire population, number of deaths under 5 years old, polio immunization records, total expenditure on health, diphtheria immunization records, HIV/AIDS related deaths, GDP, total population, adolescent weights between the ages of 1-19 and 5-9, income composition of resources, and number of years of schooling.

Data Cleaning

Since the data set contains an expansive set of predicting variables, this project will limit the scope to how schooling, GDP and BMI are related to life expectancy. To this end, missing values for key predictors were removed from the data set.

life_data = read.csv("Life Expectancy Data.csv")
before = nrow(life_data)
life_data = life_data %>% drop_na(Life.expectancy, Schooling, GDP, BMI)
#life_data = na.omit(life_data)
after = nrow(life_data)
print(before)
## [1] 2938
print(after)
## [1] 2458

Data Distribution

Key Predictors vs Life Expectancy

Schooling vs Life Expectancy

Schooling vs Life Expectancy Code

fig = plot_ly(data = life_data, x = ~Schooling, y = ~Life.expectancy, 
              type = "scatter",
              mode = "markers",
              marker = list(size = 5))
fig = fig %>%  add_trace(x = ~Schooling,
            y = ~fitted,
            mode = "lines",
            name = "Linear Regression",
            line = list(color = "red", width = 2))
fig = fig %>% layout(title = "Life Expectancy and Schooling",
                     xaxis = list(title = "Schooling (in years)"),
                     yaxis = list(title = "Life Expectancy (in years)"))

Residuals Plot

Residuals Code

model = lm(Life.expectancy ~ Schooling, data = life_data)
life_data$residuals = residuals(model)

r = ggplot(life_data, aes(x = Schooling, y = residuals)) + 
  geom_point(alpha = 0.5) + 
  geom_hline(yintercept = 0, 
             linetype = "dashed", color = "red") + 
  labs(title = "Residual Plot for Schooling",
       x = "Schooling (in years)",
       y = "Residuals")

Multiple Linear Regression

Summary of multiple linear regression for key predictors:

Standardized Beta Coefficients

In order to analyze the strength of each predictor’s effect on life expectancy, I calculated standardized beta coefficients for each predictor. Doing so allows for direct comparison.

## 
## Call:
## lm(formula = Life.expectancy ~ Schooling + GDP + BMI, data = life_data)
## 
## Standardized Coefficients::
## (Intercept)   Schooling         GDP         BMI 
##          NA   0.5730120   0.1376304   0.2087803

For example, it can be seen that an increase of one standard deviation in schooling relates to a 0.57 standard deviation increase in life expectancy. Meanwhile, GDP and BMI are only responsible for 0.14 and 0.21 standard deviation increase in life expectancy respectively.

Life Expectancy vs Schooling vs BMI (Colored by GDP)

Conclusion

Of the three key predictors chosen for this project, schooling has the greatest impact on life expectancy while BMI and GDP are more moderate predictors. Thus, it is recommended that countries should invest in furthering education since this correlates with greater life expectancy.

Source