1. Synopsis

This report analyzed a data set that records storm from 1950 to the end of November 2011. The report identifies Tornado as the most dangerous storm type that inflicts human casualties, and Flood as the most destructive storm type that damages economies. In addition, the analysis also identities the top 5 most destructive storm types with the following effects: (1) Casualties caused, including injuries and fatalities. (2) Economic loss, including damages to properties and crops in USD.

The analysis is conducted per the requirement of Reproducible Research Peer-graded Assignment: Course Project 2 The dataset and relevant information can be found on this course page.

2. Data Processing

This a section describes how the data were loaded into R and processed for analysis.

  1. Libraries and data set are loaded in the following chunk of codes.
# load libraries
library(tidyverse)
library(cowplot)
library(scales)

#### Download files #### 
# URL of the zip file
file_url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"

# Destination file path
destination_path <- "./data"

# Create the destination folder if it does not exist
if (!file.exists(destination_path)) {
      dir.create(destination_path, recursive = TRUE)
}

# Download and unzip the file if it does not exist
if (!file.exists(paste0(destination_path, "/repdata_data_StormData.csv.bz2"))) {
      download.file(file_url, destfile = file.path(destination_path, "repdata_data_StormData.csv.bz2"), mode = "wb")
}

StormData <- read_csv(file.path(destination_path, "repdata_data_StormData.csv.bz2"))
  1. In the R code chunk below, data tables are generated from the original data to calculate the casualties caused by different storm types.
  1. “total_injuries” is calculated as the sum of all injuries for a particular event type.
  2. “total_fatalities” is calculated as the sum of all fatalities for a particular event type.
  3. “total_casualties” is the sum of “total_injuries” and “total_fatalities”, and is used to evaluate the dangerous level of each event type.
  4. The top 5 most dangerous storm types are identified and the rest are aggregated into the “others” category.
# data tables to summarize danger to human population
storm_pupulation_casualty <- StormData %>% 
      group_by(EVTYPE) %>% 
      summarise(total_fatalities = sum(FATALITIES, na.rm = T),
                total_injuries = sum(INJURIES, na.rm = T),
                total_casualties = total_fatalities + total_injuries) %>% 
      arrange(desc(total_casualties)) %>% 
      mutate(casualty_percentage = total_casualties / sum(total_casualties))

storm_pupulation_casualty_top_5 <- storm_pupulation_casualty %>% 
      slice_head(n = 5) %>% 
      # aggregate the rest to others
      add_row(EVTYPE = "others", 
              total_fatalities = sum(storm_pupulation_casualty$total_fatalities[(5 + 1): nrow(storm_pupulation_casualty)]), 
              total_injuries = sum(storm_pupulation_casualty$total_injuries[(5 + 1): nrow(storm_pupulation_casualty)]), 
              total_casualties = sum(storm_pupulation_casualty$total_casualties[(5 + 1): nrow(storm_pupulation_casualty)]), 
              casualty_percentage = sum(storm_pupulation_casualty$casualty_percentage[(5 + 1): nrow(storm_pupulation_casualty)])
      ) %>% 
      #add a rank
      mutate(rank = row_number(), 
             #order EVTYPE by rank
             EVTYPE = fct_reorder(EVTYPE, rank)
      )  
  1. In the R code chunk below, data tables are generated from the original data to calculate the economic damages caused by different storm types.
  1. “propdmg” is calculated as the sum of all “PROPDMG” for a particular event type per “PROPDMGEXP”.
  2. “PROPDMGEXP” is converted to corresponding “propdmg_unit” per the Storm Data Documentation and online discussion.
  3. “total_propdmg” is calculated as the product of “propdmg” and “propdmg_unit”.
  4. “cropdmg” is calculated as the sum of all “CROPDMG” for a particular event type per “CROPDMGEXP”.
  5. “CROPDMGEXP” is converted to corresponding “cropdmg_unit” similar to how “PROPDMGEXP” is converted to corresponding “propdmg_unit”.
  6. “total_cropdmg” is calculated as the product of “cropdmg” and “cropdmg_unit”.
  7. The “total_economic_impact” is calculated as the sum of “sum_propdmg” and “sum_cropdmg”, and is used to evaluate the economic loss.
  8. The top 5 most damaging storm types are identified and the rest are aggregated into the “others” category.
# data tables to analyze economic consequences
storm_economic_impact <- StormData %>% 
      #select relevant columns
      select(EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP) %>% 
      #calculate sum under these groups
      group_by(EVTYPE, PROPDMGEXP, CROPDMGEXP) %>% 
      summarise(propdmg = sum(PROPDMG, na.rm = T),
                cropdmg = sum(CROPDMG, na.rm = T)) %>% 
      ungroup() %>% 
      # create unit of property damage
      # see post here https://rstudio-pubs-static.s3.amazonaws.com/58957_37b6723ee52b455990e149edde45e5b6.html 
      mutate(propdmg_unit = case_when(PROPDMGEXP == "H" ~ 100,
                                      PROPDMGEXP == "h" ~ 100,
                                      PROPDMGEXP == "K" ~ 1000,
                                      PROPDMGEXP == "M" ~ 1000000,
                                      PROPDMGEXP == "m" ~ 1000000,
                                      PROPDMGEXP == "B" ~ 1000000000,
                                      PROPDMGEXP == "+" ~ 1,
                                      PROPDMGEXP == "-" ~ 0,
                                      PROPDMGEXP == "?" ~ 0, 
                                      PROPDMGEXP == "0" ~ 10,
                                      PROPDMGEXP == "1" ~ 10,
                                      PROPDMGEXP == "2" ~ 10,
                                      PROPDMGEXP == "3" ~ 10,
                                      PROPDMGEXP == "4" ~ 10,
                                      PROPDMGEXP == "5" ~ 10,
                                      PROPDMGEXP == "6" ~ 10, 
                                      PROPDMGEXP == "7" ~ 10,
                                      PROPDMGEXP == "8" ~ 10,
                                      .default = 0)
      ) %>% 
      # create unit of crop damage
      mutate(cropdmg_unit = case_when( CROPDMGEXP == "K" ~ 1000,
                                       CROPDMGEXP == "k" ~ 1000,
                                       CROPDMGEXP == "M" ~ 1000000,
                                       CROPDMGEXP == "m" ~ 1000000,
                                       CROPDMGEXP == "B" ~ 1000000000,
                                       CROPDMGEXP == "?" ~ 0, 
                                       CROPDMGEXP == "0" ~ 10,
                                       CROPDMGEXP == "2" ~ 10,
                                       .default = 0)
      ) %>% 
      #calculate economic damage
      mutate(total_propdmg = propdmg * propdmg_unit, 
             total_cropdmg = cropdmg * cropdmg_unit) %>% 
      group_by(EVTYPE) %>% 
      #summarize the total economic impact
      summarise(sum_propdmg = sum(total_propdmg), 
                sum_cropdmg = sum(total_cropdmg), 
                .groups = "drop")  %>% 
      ungroup() %>% 
      #sum total impact
      mutate(total_economic_impact = sum_propdmg + sum_cropdmg,
             impact_percentage = total_economic_impact / sum(total_economic_impact, na.rm = T) * 100) %>% 
      #order the table
      arrange(desc(impact_percentage))


# select top 5, and aggregate the rest

storm_economic_impact_top_5 <- storm_economic_impact %>% 
      # select top 5
      arrange(desc(impact_percentage)) %>% 
      slice_head(n = 5) %>% 
      # aggregate the rest to others
      add_row(EVTYPE = "others",
              sum_propdmg = sum(storm_economic_impact$sum_propdmg[6: nrow(storm_economic_impact)]),
              sum_cropdmg = sum(storm_economic_impact$sum_cropdmg[6: nrow(storm_economic_impact)]),
              total_economic_impact = sum(storm_economic_impact$total_economic_impact[6: nrow(storm_economic_impact)]), 
              impact_percentage = sum(storm_economic_impact$impact_percentage[6: nrow(storm_economic_impact)])
      ) %>% 
      # rank rows and order EVTYPE for plotting
      mutate(rank = row_number(),
             EVTYPE = fct_reorder(EVTYPE, rank))

3. Results

The report has the following two major findings:

  1. Across the United States, Tornado is the most harmful type of storm event with respect to population health. During the duration of the data collection, Tornado inflicted 96979 human casulties, which consists of 62.3% of total casualties by all types of storms.
# add a column plot to show absolute size
Figure_1_1 <- storm_pupulation_casualty_top_5 %>% 
      ggplot(aes(x = EVTYPE, y = total_casualties, fill = EVTYPE)) +
      geom_col() +
      geom_label(aes(label = total_casualties), vjust = 0.5, show.legend = F) +
      labs(title = "Figure 1: Top 5 Event Types of Highest Casulties  (Fatalities + Injuries)",
           subtitle = "Real Numbers:",
           x = "", 
           y = "Total Casualties") +
      theme_classic()
      
      
      # a plot to summarize danger to population health by story types
Figure_1_2 <- storm_pupulation_casualty_top_5 %>% 
      ggplot(aes(x = "", y = casualty_percentage, fill = EVTYPE)) +
      geom_col() +
      geom_label(aes(label = round(casualty_percentage * 100, digits = 1)),
                 position = position_stack(vjust = 0.5),
                 show.legend = FALSE) +
      labs(subtitle = "Percentages:") +
      coord_polar(theta = "y") +
      theme_void() 

cowplot::plot_grid(Figure_1_1, Figure_1_2, nrow = 2)

  1. Across the United States, Flood has the greatest economic consequences. During the duration of the data collection, flood has caused $150.3B damage to properties and crops combined, which accounts for 31.6% of all economic loss due to all types of events.
# a column plot to show absolute size
Figure_2_1 <- storm_economic_impact_top_5 %>% 
      ggplot(aes(x = EVTYPE, y = total_economic_impact, fill = EVTYPE)) +
      geom_col() +
      geom_label(aes(label = round(total_economic_impact * 1e-9, digits = 1)), vjust = 0.5, show.legend = F) +
      labs(title = "Figure 2: Top 5 Event Types of Highest Economic Impact (Properties + Crops)",
           subtitle = "Real Numbers:",
           x = "", 
           y = "Total Economivs Damages") +
      theme_classic() +
      scale_y_continuous(labels = label_number(scale = 1e-9, prefix = "$", suffix = "B", accuracy = 1)) 


# a plot to summarize economic damage
Figure_2_2 <- storm_economic_impact_top_5 %>% 
      ggplot(aes(x = "", y = total_economic_impact, fill = EVTYPE)) +
      geom_col() +
      geom_label(aes(label = round(impact_percentage, digits = 1)),
                 position = position_stack(vjust = 0.5),
                 show.legend = FALSE) +
      labs(tsubitle = "Percentages:") +
      coord_polar(theta = "y") +
      labs(subtitle = "Percentages:") +
      theme_void() 

#compiling figures
cowplot::plot_grid(Figure_2_1, Figure_2_2, nrow = 2)