Synopsis

The analysis is based on U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. The records were collected in years 1950-2011 and contain data regarding the type, location of the events as well as fatalities, injuries, crop and property damage. The aim of this analysis is to identify the weather events which were most harmful with respect to population health and types of events have the greatest economic consequences. To answer the first question, the top 10 events which caused the highest number of deaths and injuries were identified, whereas for the second question, the total damage in US”$” was calculated for each type of event, and 10 top events for the crop and property damage were identified.

Data processing

Loading necessary packages

Two packages were used - tidyverse to work with data and ggpubr to prepare figures.

library(readr)
library(tidyverse)
library(ggpubr)

Loading and preprocessing the data

Data were unzipped to read and transformed to a tibble.

# unzip the file, read the data from .csv file and transform to a tibble
bz2_file <- "repdata_data_StormData.csv.bz2"
df_data <- read_csv(bz2_file)
## Rows: 902297 Columns: 37
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): BGN_DATE, BGN_TIME, TIME_ZONE, COUNTYNAME, STATE, EVTYPE, BGN_AZI,...
## dbl (18): STATE__, COUNTY, BGN_RANGE, COUNTY_END, END_RANGE, LENGTH, WIDTH, ...
## lgl  (1): COUNTYENDN
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data <- as_tibble(df_data)

Because of the size of the dataset, the data were first filtered to leave only the events for which the deaths/injuries, crop damage or property damage were reported.

filter_data <- data %>%
        filter((!is.na(FATALITIES) & FATALITIES != "0") | 
        (!is.na(INJURIES) & INJURIES != "0") |
        (!is.na(CROPDMG) & CROPDMG != "0") | 
        (!is.na(PROPDMG) & PROPDMG != "0"))

Next, the vector with the types of events from the database manual was created and used to check how many records have listed events.

events <- c('Astronomical Low Tide', 'Avalanche', 'Blizzard', 'Coastal Flood',
            'Cold/Wind Chill', 'Debris Flow', 'Dense Fog', 'Dense Smoke', 
            'Drought', 'Dust Devil', 'Dust Storm', 'Excessive Heat', 
            'Extreme Cold/Wind Chill', 'Flash Flood', 'Flood', 'Freezing Fog',
            'Frost/Freeze', 'Funnel Cloud', 'Hail', 'Heat', 'Heavy Rain',
            'Heavy Snow', 'High Surf', 'High Wind', 'Hurricane/Typhoon', 
            'Ice Storm', 'Lakeshore Flood', 'Lake-Effect Snow', 'Lightning',
            'Marine Hail', 'Marine High Wind', 'Marine Strong Wind', 
            'Marine Thunderstorm Wind', 'Rip Current', 'Seiche', 'Sleet',
            'Storm Tide', 'Strong Wind', 'Thunderstorm Wind', 'Tornado',
            'Tropical Depression', 'Tropical Storm', 'Tsunami', 'Volcanic Ash',
            'Waterspout', 'Wildfire', 'Winter Storm', 'Winter Weather')
view_ev <- filter_data %>%
        filter(grepl(paste0(events, collapse = "|"), EVTYPE, ignore.case = TRUE))

Since a significant part of the records did not have any of the listed event names, a list of all recorded event names was generated.

unique <- filter_data %>%
        distinct(EVTYPE)
sorted_unique <- filter_data %>%
        count(EVTYPE) %>%
        arrange(desc(n))
View(sorted_unique)

A lot of record had different names than in the official manual, so some of the names were corrected to be properly classified.

corrected_data <- filter_data %>%
        mutate(`evtype_corr` = case_when(
                grepl("Tornado", EVTYPE, ignore.case = TRUE) ~ "TORNADO",
                grepl("Thunderstorm", EVTYPE, ignore.case = TRUE) | 
                        grepl("TSTM Wind", EVTYPE, ignore.case = TRUE)
                ~ "THUNDERSTORM WINDS",
                grepl("Hurricane", EVTYPE, ignore.case = TRUE) ~ "HURRICANE",
                grepl("Lightning", EVTYPE, ignore.case = TRUE) ~ "LIGHTNING",
                grepl("Hail", EVTYPE, ignore.case = TRUE) ~ "HAIL",
                grepl("Snow", EVTYPE, ignore.case = TRUE) ~ "HEAVY SNOW",
                grepl("Heat", EVTYPE, ignore.case = TRUE) ~ "HEAT",
                grepl("Wind", EVTYPE, ignore.case = TRUE) ~ "STRONG WIND",
                grepl("Freeze", EVTYPE, ignore.case = TRUE) | 
                        grepl("Frost", EVTYPE, ignore.case = TRUE) ~ "FROST/FREEZE",
                grepl("Cold", EVTYPE, ignore.case = TRUE) ~ "COLD/WIND CHILL",
                grepl("Tropical Storm", EVTYPE, ignore.case = TRUE) ~ "TROPICAL STORM",
                grepl("surge", EVTYPE, ignore.case = TRUE) ~ "STORM TIDE",
                grepl("Fire", EVTYPE, ignore.case = TRUE) ~ "WILDFIRE",
                grepl("Flooding", EVTYPE, ignore.case = TRUE) ~ "FLOOD",
                grepl("UNSEASONABLY WARM", EVTYPE, ignore.case = TRUE) ~ "EXCESSIVE HEAT",
                grepl("Hurricane", EVTYPE, ignore.case = TRUE) | 
                        grepl("Typhoon", EVTYPE, ignore.case = TRUE) ~ "HURRICANE/TYPHOON",
                grepl("Coastal Flood", EVTYPE, ignore.case = TRUE) ~ "COASTAL FLOOD",
                grepl("Heavy rain", EVTYPE, ignore.case = TRUE) | 
                        grepl("Unseasonal rain", EVTYPE, ignore.case = TRUE) | 
                        grepl("Hvy rain", EVTYPE, ignore.case = TRUE) ~ "HEAVY RAIN",
                TRUE ~ EVTYPE
        ))

Results

Events which were most harmful with respect to population health

The data were filterd again to use only the events with records of fatalities or injuries, what significantly reduced the size of the tibble.

health <- corrected_data %>%
        filter((!is.na(FATALITIES) & FATALITIES != "0") | 
                       (!is.na(INJURIES) & INJURIES != "0")) 
unique_health <- health %>%
        distinct(evtype_corr)
unique_health
## # A tibble: 97 × 1
##    evtype_corr          
##    <chr>                
##  1 TORNADO              
##  2 THUNDERSTORM WINDS   
##  3 HAIL                 
##  4 ICE STORM/FLASH FLOOD
##  5 WINTER STORM         
##  6 HURRICANE            
##  7 DENSE FOG            
##  8 RIP CURRENT          
##  9 LIGHTNING            
## 10 HEAT                 
## # ℹ 87 more rows

To find the events which caused the most deaths or injuries firstly the data were grouped by event type and summarised, top 10 events for the highest number of deaths and injuries were identified and plotted.

sorted_health <- health %>%
        group_by(evtype_corr) %>%
        select(evtype_corr, INJURIES, FATALITIES) %>%
        summarise(across(c(INJURIES, FATALITIES), sum, na.rm = TRUE))
## Warning: There was 1 warning in `summarise()`.
## ℹ In argument: `across(c(INJURIES, FATALITIES), sum, na.rm = TRUE)`.
## ℹ In group 1: `evtype_corr = "AVALANCE"`.
## Caused by warning:
## ! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
## Supply arguments directly to `.fns` through an anonymous function instead.
## 
##   # Previously
##   across(a:b, mean, na.rm = TRUE)
## 
##   # Now
##   across(a:b, \(x) mean(x, na.rm = TRUE))
View(sorted_health)
top_10_inj <- sorted_health %>%
        top_n(10, INJURIES)
top_10_fat <- sorted_health %>%
        top_n(10, FATALITIES)
plot1 <- ggplot(top_10_inj, aes(x = evtype_corr, y = INJURIES)) +
        geom_bar(stat = "identity") +
        theme_minimal() +
        aes(x = reorder(evtype_corr, desc(INJURIES))) +
        theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
        labs(x = "Type of event", y = "number of injuries",
             title = "Events causing the most injuries")
plot2 <- ggplot(top_10_fat, aes(x = evtype_corr, y = FATALITIES)) +
        geom_bar(stat = "identity") +
        theme_minimal() +
        aes(x = reorder(evtype_corr, desc(FATALITIES))) +
        theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
        labs(x = "Type of event", y = "number of fatalities",
             title = "Events causing the most fatalities")
ggarrange(plot1, plot2,
        labels = c("A", "B"),
        ncol = 2, nrow = 1)


The damage to human healt might be assesed by two factors - number of injuries and number of fatalities. As seen on the first figure, the events that cause the harm to humans are tornados, both in terms of injuries (A) and deaths (B). In case of injuries, tornados are causing more injuries than all other events from the top 10. In case of fatalities, the second most dangerous event is heat, which causes almost twice less fatalities than tornados. Other death causingh events are connected with rain, thunderstorms and wind, but the number of the deaths caused by those events is signifficantly smaller than for tornados and heat.

Events which have the greatest economic consequences

The data were filterd again to use only the events with records of crop or property damage.

damage <- corrected_data %>%
        filter((!is.na(CROPDMG) & CROPDMG != "0") | (!is.na(PROPDMG) & PROPDMG != "0"))

The data of the cost of damage are placed in two different columns, both for crop and property damage - the number (value): PROPDMG/CROPDMG and its exponent value PROPDMGEXP/CROPDMGEXP. The exponent values are written using different symbols so they first needed to be unified (new column created propd/cropd) and then final damage (propd_fin/cropd_fin)value created by multiplying PROPDMG/CROPDMG by the propd/cropd.

unique_expc <- damage %>%
        distinct(CROPDMGEXP)
unique_expc
## # A tibble: 8 × 1
##   CROPDMGEXP
##   <chr>     
## 1 <NA>      
## 2 M         
## 3 K         
## 4 m         
## 5 B         
## 6 ?         
## 7 0         
## 8 k
unique_expp <- damage %>%
        distinct(PROPDMGEXP)
unique_expp
## # A tibble: 16 × 1
##    PROPDMGEXP
##    <chr>     
##  1 K         
##  2 M         
##  3 B         
##  4 m         
##  5 <NA>      
##  6 +         
##  7 0         
##  8 5         
##  9 6         
## 10 4         
## 11 h         
## 12 2         
## 13 7         
## 14 3         
## 15 H         
## 16 -
damage_calc <- damage %>%
        mutate(cropd = case_when(
                CROPDMGEXP %in% c("H", "h") ~ 100,
                CROPDMGEXP %in% c("K", "k") ~ 1000,
                CROPDMGEXP %in% c("M", "m") ~ 1000000,
                CROPDMGEXP %in% c("B", "m") ~ 1000000000,
                CROPDMGEXP %in% c("+") ~ 1,
                CROPDMGEXP %in% c("-", "?", " ") ~ 0,
                CROPDMGEXP %in% c(0,1,2,3,4,5,6,7,8,9) ~ 10)) %>%
        mutate(cropd_fin = CROPDMG*cropd) %>%
        mutate(propd = case_when(
                PROPDMGEXP %in% c("H", "h") ~ 100,
                PROPDMGEXP %in% c("K", "k") ~ 1000,
                PROPDMGEXP %in% c("M", "m") ~ 1000000,
                PROPDMGEXP %in% c("B", "b") ~ 1000000000,
                PROPDMGEXP %in% c("+") ~ 1,
                PROPDMGEXP %in% c("-", "?", " ") ~ 0,
                PROPDMGEXP %in% c(0,1,2,3,4,5,6,7,8,9) ~ 10)) %>%
        mutate(propd_fin = PROPDMG*propd)  
sorted_damage <- damage_calc %>%
        group_by(evtype_corr) %>%
        select(evtype_corr, cropd_fin, propd_fin) %>%
        summarise(across(c(cropd_fin, propd_fin), sum, na.rm = TRUE))

To find the events which caused the most economical damage firstly the data were grouped by event type and summarised, top 10 events for the highest number of crop and property damage were identified and plotted.

top_10_crop <- sorted_damage %>%
        top_n(10, cropd_fin)
top_10_prop <- sorted_damage %>%
        top_n(10, propd_fin)
plot3 <- ggplot(top_10_crop, aes(x = evtype_corr, y = cropd_fin)) +
        geom_bar(stat = "identity") +
        theme_minimal() +
        aes(x = reorder(evtype_corr, desc(cropd_fin))) +
        theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
        labs(x = "Type of event", y = "Total cost of damage [$]",
             title = "Events causing the most crop damage")
plot4 <- ggplot(top_10_prop, aes(x = evtype_corr, y = propd_fin)) +
        geom_bar(stat = "identity") +
        theme_minimal() +
        aes(x = reorder(evtype_corr, desc(propd_fin))) +
        theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
        labs(x = "Type of event", y = "Total cost of damage [$]",
             title = "Events causing the property damage")
ggarrange(plot3, plot4,
          labels = c("A", "B"),
          ncol = 2, nrow = 1)


As seen on the second figure, the event that causes the most damage to crops is drougt (A). The cost of damage caused by drought is two times higher thank the cost of damage caused by the second most damaging event - flood. The other crop damages causing events are connected with rain and wind - floods, hurricanes and ice storms. In case of property damage (B) the most damage causing events are floods. Other most seriuos damage causing evens are also connected with rain and wind - hurricanes, tornados and storm tides.