Assignment 1 — Quantitative Methods

Author

Javad Vasheghani Farahani

1 This is a title I added

This section shows how to format text I AM BOLD HERE and some in and ITALIC HERE.

1.1 Unordered and Numbered Lists are here

2 Life Expect

3 Load the gapminder package

library(tidyverse)

library(gapminder)

head(gapminder)
# A tibble: 6 × 6
  country     continent  year lifeExp      pop gdpPercap
  <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
1 Afghanistan Asia       1952    28.8  8425333      779.
2 Afghanistan Asia       1957    30.3  9240934      821.
3 Afghanistan Asia       1962    32.0 10267083      853.
4 Afghanistan Asia       1967    34.0 11537966      836.
5 Afghanistan Asia       1972    36.1 13079460      740.
6 Afghanistan Asia       1977    38.4 14880372      786.

Here is an unordered (bulleted) list:

  • Apples
  • Bananas
  • Cherries

Here is a numbered list (1, 2, 3):

  1. First
  2. Second
  3. Third

Here is an alphabetic list (A, B, C):

A. Alpha
B. Bravo
C. Charlie

3.1 Average Life Expectancy per Country

4 Calculate average life expectancy for each country (across all years)

avg_lifeexp <- gapminder %>%
  group_by(country) %>%
  summarise(avg_lifeExp = mean(lifeExp))

5 Show the top 5 countries with highest average life expectancy

avg_lifeexp %>%
  arrange(desc(avg_lifeExp)) %>%
  head(5)
# A tibble: 5 × 2
  country     avg_lifeExp
  <fct>             <dbl>
1 Iceland            76.5
2 Sweden             76.2
3 Norway             75.8
4 Netherlands        75.6
5 Switzerland        75.6

6 Show the bottom 5 countries with lowest average life expectancy

avg_lifeexp %>%
  arrange(avg_lifeExp) %>%
  head(5)
# A tibble: 5 × 2
  country       avg_lifeExp
  <fct>               <dbl>
1 Sierra Leone         36.8
2 Afghanistan          37.5
3 Angola               37.9
4 Guinea-Bissau        39.2
5 Mozambique           40.4

6.1 Life Expectancy Over Time: Afghanistan, Mexico, Sweden

countries <- c("Afghanistan", "Mexico", "Sweden")

7 Filter and plot

gapminder %>%
  filter(country %in% countries) %>%
  ggplot(aes(x = year, y = lifeExp, color = country)) +
  geom_line(size = 1.2) +
  geom_point(size = 2) +
  labs(
    title = "Life Expectancy Over Time: Afghanistan, Mexico, and Sweden",
    x = "Year",
    y = "Life Expectancy (years)",
    color = "Country"
  ) +
  theme_minimal()

7.1 GDP per Capita vs Life Expectancy by Continent

gapminder %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, color = continent)) +
  geom_point(alpha = 0.6, size = 2) +
  scale_x_log10() +
  labs(
    title = "GDP per Capita vs Life Expectancy by Continent (Minimal Theme)",
    x = "GDP per Capita (log scale)",
    y = "Life Expectancy (years)",
    color = "Continent"
  ) +
  theme_minimal()

gapminder %>%
  ggplot(aes(x = gdpPercap, y = lifeExp, color = continent)) +
  geom_point(alpha = 0.6, size = 2) +
  scale_x_log10() +
  labs(
    title = "GDP per Capita vs Life Expectancy by Continent (Classic Theme)",
    x = "GDP per Capita (log scale)",
    y = "Life Expectancy (years)",
    color = "Continent"
  ) +
  theme_classic()

7.2 Ranking Continents by Life Expectancy: year 1952 vs year 2007

lifeexp_1952 <- gapminder %>%
  filter(year == 1952) %>%
  group_by(continent) %>%
  summarise(mean_lifeExp = mean(lifeExp)) %>%
  arrange(desc(mean_lifeExp))

8 SRanking for 1952

lifeexp_1952
# A tibble: 5 × 2
  continent mean_lifeExp
  <fct>            <dbl>
1 Oceania           69.3
2 Europe            64.4
3 Americas          53.3
4 Asia              46.3
5 Africa            39.1

9 Average life expectancy per continent for 2007

lifeexp_2007 <- gapminder %>%
  filter(year == 2007) %>%
  group_by(continent) %>%
  summarise(mean_lifeExp = mean(lifeExp)) %>%
  arrange(desc(mean_lifeExp))

10 Ranking for 2007

lifeexp_2007
# A tibble: 5 × 2
  continent mean_lifeExp
  <fct>            <dbl>
1 Oceania           80.7
2 Europe            77.6
3 Americas          73.6
4 Asia              70.7
5 Africa            54.8