Synopses

This analysis shows high-level summary of the impact of different types of natural disaster types by deaths, injuries and economic damages. The data is sourced from the National Weather Service (NWS).

Per the results, tornadoes are responsible by a wide margin for the most injuries and deaths compared to any other natural disasters. However, floods are responsbile for the most economic damage

Data Processing

Pulls dplyr library and suppresses warning messages

knitr::opts_chunk$set(warning = FALSE, message = FALSE) 
library(dplyr)

Load the csv file into a dataframe and filter on the most relevant rows as most columns from the raw data are not needed

raw_df <- read.csv("repdata_data_StormData.csv")
filtered_df <- raw_df %>% select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP)

Then a dataframe was created of fatalities by disaster type. To do this, first all rows with NA values were omitted. Then the raw dataframe was transformed to just include the disaster type (EVTYPE) and fatalities columns so that the data could then be grouped-by and summed by disaster types. Finally, the dataframe was filtered to just show the 10 disaster types with the most fatalities (since the quantity of disaster types were too large)

event_by_fatalities <- filtered_df %>%
  na.omit() %>%
  mutate(FATALITIES = as.numeric(FATALITIES)) %>% # Convert FATALITIES to numeric
  select(EVTYPE, FATALITIES) %>%                 # Select relevant columns
  group_by(EVTYPE) %>%
  summarise(totalFatalities = sum(FATALITIES, na.rm = TRUE)) %>% # Summarize with safety
  arrange(desc(totalFatalities)) %>%
  slice_head(n=10)

A similar dataframe was created for injuries by disaster type following a similar process as the above, replacing fatalities with injuries

event_by_injuries <- filtered_df %>%
  na.omit() %>%
  mutate(INJURIES = as.numeric(INJURIES)) %>% # Convert FATALITIES to numeric
  select(EVTYPE, INJURIES) %>%                 # Select relevant columns
  group_by(EVTYPE) %>%
  summarise(totalInjuries = sum(INJURIES, na.rm = TRUE)) %>% # Summarize with safety
  arrange(desc(totalInjuries)) %>%
  slice_head(n=10)

The process for transforming the raw data for pulling the economic damage by disaster type was a bit different that fatalities & injuries since economic damage was represent across two separate columns in the NWS CSV, PROPDMG & PROPDMGEXP. PROPDMG contained raw numeric values while PROPDMGEXP contained alphabetical values which represented a multiplier to apply to the values in PROPDMG (‘K’ representing thousands,‘M’ representing millions, ‘B’ representing billions).

multiplier_converter <- function(x) {
    if (x == "K") {x <- 10^3}
    else if (x== "M") {x <- 10^6}
    else if (x=="B") {x <- 10^9}
    else {x <- NA}
}


economic_damage_df_helper <- filtered_df
economic_damage_df_helper$PROPDMGEXP <- sapply(economic_damage_df_helper$PROPDMGEXP, multiplier_converter)
economic_damage_df <- economic_damage_df_helper %>%
    na.omit() %>%
    mutate(PROPDMG = as.numeric(PROPDMG)*as.numeric(PROPDMGEXP)) %>%
    select(EVTYPE,PROPDMG) %>%
    group_by(EVTYPE) %>%
    summarise(EconomicDamage = sum(PROPDMG, na.rm = TRUE)/(10^6)) %>%
    arrange(desc(EconomicDamage)) %>%
    slice_head(n=10)

Results

Create barplot of fatalities by disaster type

par(mar = c(10, 4, 4, 2))
with(event_by_fatalities, barplot(height = totalFatalities, names.arg = EVTYPE, las=2, main = "Fatalities by Event"))

Create barplot of injuries by disaster type

par(mar = c(10, 4, 4, 2))
with(event_by_injuries, barplot(height = totalInjuries, names.arg = EVTYPE, las=2, main = "Injuries by Event"))

Create barplot of economic damage by disaster type

par(mar = c(10, 4, 4, 2))
with(economic_damage_df, barplot(height = EconomicDamage, names.arg = EVTYPE, las=2, main = "Economic Damage by Event (by millons of USD)"))