STAT 1080 - Fall 2026
  • Course Info
    • Overview
    • Syllabus
    • Support
    • Schedule
    • Useful links
  • Weekly Materials
    • W1. Introduction
    • W2. RStudio
    • W3. Correlation
    • W4. Programming
    • W5. Tidyverse
    • W6. Dates/Times and Distributions
    • W7. Data Visualization
    • W8. Statistics & Probability
    • W9. Data & Probability
    • W10. Random Variables
    • W11. Parameters & Estimates
    • W12. Statistical Inference
    • W13. Regression
    • W14. Regression
    • W15. Project Meetings

On this page

  • 1 Problem
  • 2 Problem
  • 3 Problem
  • 4 Problem
  • 5 Problem
  • Report an issue

6.1.i - Class Activity

This assignment is intended to get you familiar with the tidyverse using real COVID-19 data.

library(tidyverse)

The following code chunk scrapes the .csv files we will be analyzing from the web renames and selects the subset of columns that we will be using for analysis.

url <- "https://srhdpeuwpubsa.blob.core.windows.net/whdh/COVID/"
url_case <- paste0(url, "WHO-COVID-19-global-table-data.csv")

covid_case <- read_csv(url_case) |>
  select(name = Name, region = `WHO Region`, 
         case_total = `Cases - cumulative total`,
         case_pop = `Cases - cumulative total per 100000 population`,
         death_total = `Deaths - cumulative total`,
         death_pop = `Deaths - cumulative total per 100000 population`)

The renamed columns that remain are:

  • name: Country name
  • region: World Health Organization (WHO) region.
  • case_total: Cumulative number of reported COVID cases since Jan 2020
  • case_pop: Cumulative number of reported COVID cases per 100,000 people since Jan 2020
  • death_total: Cumulative number of reported COVID deaths since Jan 2020
  • death_pop: Cumulative number of reported COVID deaths per 100,000 people since Jan 2020

1 Problem

We want to know how the different regions of the world fared in terms of their covid case rates per 100,000 people. To get started with this, create a new dataframe called covid_case_region that contains the country-level averages (i.e., mean()) for both cases and deaths per 100,000 people by region. Call the variable containing the averages mean_case_pop. Be sure to remove missing values prior to calculating the averages. Question for Canvas: What is the mean deaths per 100,000 people in the “Africa” region, rounded to the nearest whole number?

covid_case_region <- covid_case |>
  group_by(region) |> 
  summarize(mean_case_pop = mean(case_pop, na.rm = TRUE), 
            mean_death_pop = mean(death_pop, na.rm = TRUE))

covid_case_region
# A tibble: 8 × 3
  region                mean_case_pop mean_death_pop
  <chr>                         <dbl>          <dbl>
1 Africa                        3202.           28.0
2 Americas                     17782.          187. 
3 Eastern Mediterranean         8384.           67.1
4 Europe                       35224.          256. 
5 Other                          NaN           NaN  
6 South-East Asia               6730.           39.3
7 Western Pacific              26132.           58.6
8 <NA>                        296708.         2109. 

2 Problem

Notice that we have two issues with our summary. The “other” region has no non-missing observations (indicated by the NaN values) and there is an NA region that contains an unknown number of countries. Please update the covid_case_region dataframe to exclude any rows that contain NaN values for mean_case_pop, as well as any rows with missing region information. Hint: check out the is.nan() and is.na() function for help in excluding a row that contain NaN or NA values in a particular column. Your updated dataset should have precisely 6 rows.

covid_case_region <- covid_case_region |>
  filter(!is.nan(mean_case_pop) & !is.na(region))

covid_case_region
# A tibble: 6 × 3
  region                mean_case_pop mean_death_pop
  <chr>                         <dbl>          <dbl>
1 Africa                        3202.           28.0
2 Americas                     17782.          187. 
3 Eastern Mediterranean         8384.           67.1
4 Europe                       35224.          256. 
5 South-East Asia               6730.           39.3
6 Western Pacific              26132.           58.6

3 Problem

Arrange the covid_case_region dataframe so that the average deaths per 100,000 people go from smallest to largest. Question for Canvas: which region has the second largest deaths per 100,000 people due to COVID?

covid_case_region |>
  arrange(mean_death_pop)
# A tibble: 6 × 3
  region                mean_case_pop mean_death_pop
  <chr>                         <dbl>          <dbl>
1 Africa                        3202.           28.0
2 South-East Asia               6730.           39.3
3 Western Pacific              26132.           58.6
4 Eastern Mediterranean         8384.           67.1
5 Americas                     17782.          187. 
6 Europe                       35224.          256. 

4 Problem

Discuss with a partner: The deaths per 100,000 people in the Europe region appears to be nearly 10 times larger than the deaths per 100,000 people in the Africa region. Does this imply that COVID was 10 times more deadly for Europeans? Explain why or why not, knowing that this course will not provide a definitive answer.

Likely not. It is likely the case that the European countries were much more aggressive in monitoring and reporting deaths. It is perhaps the case that COVID cases in Africa were more likely to go unreported due to less developed infrastructure for reporting cases. This highlights a crucial point that data can only tell the stories of measured information, which may or may not be reflective of what actually happened!

5 Problem

Write a new and single R statement (using pipes |>) that starts from the original covid_case dataframe and does the following:

  • Calculates the average of case_pop and death_pop by region (as previously done)
  • Omits the NaN rows and NA rows (as previously done)
  • Calculates the deaths per reported case (i.e., death_rate) using \(100*\frac{\text{mean\_death\_pop}}{\text{mean\_case\_pop}}\) using mutate
  • Retains only rows with death_rate exceeding 0.8.

Question for Canvas: How many regions have death rates exceeding 0.8?

covid_case |>
  group_by(region) |> 
  summarize(mean_case_pop = mean(case_pop, na.rm = TRUE), 
            mean_death_pop = mean(death_pop, na.rm = TRUE)) |>
  filter(!is.nan(mean_case_pop) & !is.na(region)) |>
  mutate(death_rate = 100 * (mean_death_pop / mean_case_pop)) |> 
  filter(death_rate > 0.8)
# A tibble: 3 × 4
  region                mean_case_pop mean_death_pop death_rate
  <chr>                         <dbl>          <dbl>      <dbl>
1 Africa                        3202.           28.0      0.874
2 Americas                     17782.          187.       1.05 
3 Eastern Mediterranean         8384.           67.1      0.800

© Copyright 2026, Susan Vanderplas

 
  • Report an issue