Synopsis

I set out to explore the NOAA Storm Database to answer questions about how the health impacts and
economic consequences of severe weather events across the United States. The analysis shows that
tornado events have the greatest health impacts on communities (as measured by loss of life and number of people injured) while flooding related events cause the most economic damage.

The data and analysis is a starting points for governments to prioritize efforts and resources
in an effort to mitigate impacts from storms.


Background on Data

Data and documentation on how variables are constructed/defined can be found at:

NOAA raw storm data https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2
National Weather Service https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf
Storm Data Documentation FAQ https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2FNCDC%20Storm%20Events-FAQ%20Page.pdf

The events in the database start in the year 1950 and end in November 2011. From 1950 through 1954, only tornado events were recorded. From 1955 through 1992, only tornado, thunderstorm wind and hail events were keyed from the paper publications into digital data. From 1993 to 1995, only tornado, thunderstorm wind and hail events have been extracted from the Unformatted Text Files. From 1996 to present, 48 event types are recorded as defined in NWS Directive 10-1605. https://www.ncdc.noaa.gov/stormevents/details.jsp


Data Processing

Download and read in the dataset for exploration and analysis in R

setwd("C:/Users/rattl/OneDrive/Documents/RStudio_files/datasciencecoursera/NOAA_Storm_Data_Project/")
zipurl <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(zipurl, destfile="./StormData.csv.bz2", mode="wb")
library(data.table)
library(R.utils)
## Warning: package 'R.utils' was built under R version 4.3.2
## Loading required package: R.oo
## Loading required package: R.methodsS3
## R.methodsS3 v1.8.2 (2022-06-13 22:00:14 UTC) successfully loaded. See ?R.methodsS3 for help.
## R.oo v1.25.0 (2022-06-12 02:20:02 UTC) successfully loaded. See ?R.oo for help.
## 
## Attaching package: 'R.oo'
## The following object is masked from 'package:R.methodsS3':
## 
##     throw
## The following objects are masked from 'package:methods':
## 
##     getClasses, getMethods
## The following objects are masked from 'package:base':
## 
##     attach, detach, load, save
## R.utils v2.12.3 (2023-11-18 01:00:02 UTC) successfully loaded. See ?R.utils for help.
## 
## Attaching package: 'R.utils'
## The following object is masked from 'package:utils':
## 
##     timestamp
## The following objects are masked from 'package:base':
## 
##     cat, commandArgs, getOption, isOpen, nullfile, parse, warnings
StormData <- fread("StormData.csv.bz2", header=TRUE, stringsAsFactors=FALSE)

The dataset was downloaded on Nov 30, 2023 at 8:33pm EST. Downloading the data prior to reading it in was done to ensure reproducibility in the event the online dataset was amended or taken down in the future.

After reviewing the raw dataset and backgorund documentation, I will:
1. Determine health impacts from different storm events by assessing the number of fatalities and injuries.
2. Determine economic consequences of different storm events by assessing estimated costs of property and crop damage.

Clean and parse StormData for analysis

In exploring the dataset outside of this report, you can see that it is quite messy. The event types (EVTYPE) column for example, has 985 unique entries for the 902,297 observations in the data. Some of these are duplicates that can be combined once you correct for capitalization. I’ll make all entries lower case. This single correction bring the number of unique event type entries to 898. Within the 898 unique event types, there are misspelled words (e.g. avalance, beach erosin) that are separate from entries with the correct spellings (avalanche, beach erosion).

More concerning are the multiple variations of entries for common elements like “wind”. In fact, there are 166 different event types containing the word “wind”. Some of these entries combine wind with other common events such as cold and flood.

Decisions made on how to combine entries to fewer events may impact results as health and economic impacts of event types are explored. Ultimately, I used the below code to group observations into 49 broader event types. This is nearly 95% fewer event types than the 898 we started with!

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::between()     masks data.table::between()
## ✖ tidyr::extract()     masks R.utils::extract()
## ✖ dplyr::filter()      masks stats::filter()
## ✖ dplyr::first()       masks data.table::first()
## ✖ lubridate::hour()    masks data.table::hour()
## ✖ lubridate::isoweek() masks data.table::isoweek()
## ✖ dplyr::lag()         masks stats::lag()
## ✖ dplyr::last()        masks data.table::last()
## ✖ lubridate::mday()    masks data.table::mday()
## ✖ lubridate::minute()  masks data.table::minute()
## ✖ lubridate::month()   masks data.table::month()
## ✖ lubridate::quarter() masks data.table::quarter()
## ✖ lubridate::second()  masks data.table::second()
## ✖ purrr::transpose()   masks data.table::transpose()
## ✖ lubridate::wday()    masks data.table::wday()
## ✖ lubridate::week()    masks data.table::week()
## ✖ lubridate::yday()    masks data.table::yday()
## ✖ lubridate::year()    masks data.table::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## 
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## 
## The following object is masked from 'package:purrr':
## 
##     compact
StormData1 <- StormData %>% mutate(event_count = 1) %>%
               select(EVTYPE, FATALITIES, INJURIES, PROPDMG:CROPDMGEXP, event_count)
# creation of the event count variable allows for the sum of the # of events once data is grouped by event type. The select function creates a new data frame with only the variables within the dataset that will be explored.

StormData1$EVTYPE <- tolower(StormData1$EVTYPE) 
# making all event type observation lower case corrects for multiple entries with different capitalization once items are grouped.

StormData1$EVTYPE <- as.factor(StormData1$EVTYPE)
StormData1$PROPDMGEXP <- toupper(StormData1$PROPDMGEXP)
StormData1$CROPDMGEXP <- toupper(StormData1$CROPDMGEXP)
# the majority of entries are capitalized so toupper standardizes capitalization across observations options(scipen = 999). This function suppresses scientific notation of values.

StormData1$PROPDMGEXP <- revalue(StormData1$PROPDMGEXP, c("K"=1000, "M"=1000000, "B"=1000000000))
# revalue makes a numerical represenation of thousands (K), millions (M), and billions (B).

StormData1$PROPDMGEXP <- StormData1$PROPDMGEXP %>%
     sub("^$", "0", .) %>%
     sub("\\?", "0", .) %>%
     sub("H", "0", .) %>%
     sub("\\+", "0", .) %>%
     sub("\\-", "0", .)
# some entries within the variable column were typos that didn't match the notation (K, M, B) standard. These and blank observations were all set to zero.

StormData1$CROPDMGEXP <- revalue(StormData1$CROPDMGEXP, c("K"=1000, "M"=1000000, "B"=1000000000))
StormData1$CROPDMGEXP <- StormData1$CROPDMGEXP %>% 
     sub("^$", "0", .) %>%
     sub("\\?", "0", .) 
# same issues as we corrected PROPDMGEXP for

StormData2 <- StormData1 %>% 
     mutate(property_damage = as.numeric(PROPDMG) * as.numeric(PROPDMGEXP), 
                              crop_damage = as.numeric(CROPDMG) * as.numeric(CROPDMGEXP)) %>% 
     select(EVTYPE, event_count, FATALITIES, INJURIES, property_damage, crop_damage) 
# creation of the property damage and crop damage variables allows to for damage amounts to exist in a single column for property damage and a single column for crop damage.

StormData3 <- aggregate(cbind(event_count, FATALITIES, INJURIES, property_damage, crop_damage)
                        ~ EVTYPE, StormData2, FUN=sum)
# creates a new data frame from that sums data by each unique event type.

library(stringr)
Consolidated <- StormData3[rowSums(StormData3[,3:6])>0,]  
# removes rows with no fatalities, injuries, property damage or crop damage. This removed 456 of 898 unique event types.

Consolidated <- Consolidated %>% mutate(EVTYPE = case_when(
     str_detect(EVTYPE, "heat") ~ "heat and drought", 
     str_detect(EVTYPE, "thunderstorm wind") ~ "wind", 
     str_detect(EVTYPE, "tstm wind") ~ "wind", 
     str_detect(EVTYPE, "flood") ~ "flood", 
     str_detect(EVTYPE, "dam break") ~ "flood",
     str_detect(EVTYPE, "torn") ~ "tornado", 
     str_detect(EVTYPE, "funnel") ~ "tornado", 
     str_detect(EVTYPE, "cold") ~ "winter related", 
     str_detect(EVTYPE, "hail") ~ "hail",
     str_detect(EVTYPE, "ice") ~ "winter related",
     str_detect(EVTYPE, "fog") ~ "fog",
     str_detect(EVTYPE, "hurricane") ~ "tropical cyclones",
     str_detect(EVTYPE, "tropical") ~ "tropical cyclones",
     str_detect(EVTYPE, "typhoon") ~ "tropical cyclones",
     str_detect(EVTYPE, "^lightning") ~ "lightning",
     str_detect(EVTYPE, "blizzard") ~ "winter related",
     str_detect(EVTYPE, "sleet") ~ "winter related",
     str_detect(EVTYPE, "freezing rain") ~ "winter related",
     str_detect(EVTYPE, "freeze") ~ "winter related", 
     str_detect(EVTYPE, "snow") ~ "winter related", 
     str_detect(EVTYPE, "fire") ~ "fires", 
     str_detect(EVTYPE, "high wind") ~ "wind", 
     str_detect(EVTYPE, "rain") ~ "rain and thunderstorms", 
     str_detect(EVTYPE, "chill") ~ "winter related",
     str_detect(EVTYPE, "hypo") ~ "winter related", 
     str_detect(EVTYPE, "wind") ~ "wind", 
     str_detect(EVTYPE, "hot") ~ "heat and drought",
     str_detect(EVTYPE, "high temp") ~ "heat and drought",
     str_detect(EVTYPE, "record high") ~ "heat and drought",
     str_detect(EVTYPE, "high") ~ "storm surge, sea/coastal water conditions",
     str_detect(EVTYPE, "rip") ~ "storm surge, sea/coastal water conditions",
     str_detect(EVTYPE, "rough s") ~ "storm surge, sea/coastal water conditions",
     str_detect(EVTYPE, "surf") ~ "storm surge, sea/coastal water conditions",
     str_detect(EVTYPE, "swell") ~ "storm surge, sea/coastal water conditions",
     str_detect(EVTYPE, "surge") ~ "storm surge, sea/coastal water conditions",
     str_detect(EVTYPE, "icy") ~ "winter related",
     str_detect(EVTYPE, "glaze") ~ "winter related",
     str_detect(EVTYPE, "lig") ~ "lightning",
     str_detect(EVTYPE, "precip") ~ "rain and thunderstorms",
     str_detect(EVTYPE, "fld") ~ "flood", 
     str_detect(EVTYPE, "wa.*spout") ~ "waterspout", 
     str_detect(EVTYPE, "warm") ~ "heat and drought",
     str_detect(EVTYPE, "drought") ~ "heat and drought",
     str_detect(EVTYPE, "dry") ~ "heat and drought",
     str_detect(EVTYPE, "hyperthermia") ~ "heat and drought",
     str_detect(EVTYPE, "wint") ~ "winter related",
     str_detect(EVTYPE, "thun") ~ "rain and thunderstorms",
     str_detect(EVTYPE, "slide") ~ "landslides, rockslides, and mudslides",
     str_detect(EVTYPE, "dust") ~ "dust storm",
     str_detect(EVTYPE, "low temp") ~ "winter related",
     str_detect(EVTYPE, "free") ~ "winter related",
     str_detect(EVTYPE, "frost") ~ "winter related",
     str_detect(EVTYPE, "ava") ~ "avalanche",
                    TRUE ~ EVTYPE))
# I used StormData3 %>% filter(grepl("search term", EVTYPE)) to assess event type entries with common words or character strings and slowly consolidate common entries into a single event type. This sometimes involved making a choice about which group observations belonged in.

Consolidated <- aggregate(cbind(event_count, FATALITIES, INJURIES, property_damage, crop_damage)
                 ~ EVTYPE, Consolidated, FUN=sum)
# This recreates a cleaner dataset with the new groupings. At this point there are only 49 unique event types in the dataset (a reduction of nearly 95% of original unique event types!!).


Consolidated2 <- Consolidated %>% mutate(fatalities_ranking = rank(-FATALITIES, ties.method = 'first'))
Consolidated2 <- Consolidated2 %>% mutate(injuries_ranking = rank(-INJURIES, ties.method = 'first'))
Consolidated2 <- Consolidated2 %>% mutate(prop_damage_ranking = rank(-property_damage, ties.method = 'first'))
Consolidated2 <- Consolidated2 %>% mutate(crop_damage_ranking = rank(-crop_damage, ties.method = 'first'))
# These four commands create new columns to show the rankings (worst to least) for each variable selected.

Results

Which types of events are most harmful to population health?

Top 10 events causing fatalities

Fatalities_top5 <- Consolidated2 %>% select(EVTYPE, event_count, FATALITIES, fatalities_ranking) %>%
                                   arrange(desc(FATALITIES)) %>%
                                   slice(1:5)
print(Fatalities_top5)
##             EVTYPE event_count FATALITIES fatalities_ranking
## 1          tornado       67541       5636                  1
## 2 heat and drought        5458       3182                  2
## 3            flood       86052       1553                  3
## 4             wind      362907       1205                  4
## 5   winter related       46550       1139                  5
# this creates and prints a table of the top 5 event types that cause fatalities.

Top 10 events causing injuries

Injuries_top5 <- Consolidated2 %>% select(EVTYPE, event_count, INJURIES, injuries_ranking) %>%
                                   arrange(desc(INJURIES)) %>%
                                   slice(1:5) 
print(Injuries_top5)
##             EVTYPE event_count INJURIES injuries_ranking
## 1          tornado       67541    91410                1
## 2             wind      362907    11410                2
## 3 heat and drought        5458     9275                3
## 4            flood       86052     8683                4
## 5   winter related       46550     6689                5
# this creates and prints a table of the top 5 event types that cause injuries.
top5 <- Consolidated2 %>% select(EVTYPE, event_count, FATALITIES, INJURIES) %>%
                         arrange(desc(FATALITIES)) %>%
                         slice(1:5) 
plot(top5$INJURIES, top5$FATALITIES, pch = 19, col = factor(top5$EVTYPE), 
     xlab = "Total Injuries", xaxt = "n", xlim = c(0, 100000),
     ylab = "Total Fatalities", yaxt = "n", ylim = c(0, 6000),
     main = "Relation between Fatalities and Injuries
     across the Top 5 Storm Event Types")
axis(1, at = seq(0, 100000, by = 10000), labels = formatC(seq(0, 100000, by = 10000), format = "d", big.mark = ","))
axis(2, at = seq(0, 6000, by = 500), labels = formatC(seq(0, 6000, by = 500), format = "d", big.mark = ","))
grid(nx = NULL, ny = NULL, lty = 2, col = "gray", lwd =2)
legend("topleft", legend = levels(factor(top5$EVTYPE)), pch = 19, 
       col = factor(levels(factor(top5$EVTYPE))))

# This block of code creates a graph to show event types and the total fatalities and injuries caused.

In the two tables and graph, we see that tornadoes have caused the most fatalities and the most injuries to people. “Heat and drought” related events, “flood” related events, “wind” related events other than tornadoes, hurricanes, and tropical cyclones, and “winter related” events (cold temperatures, sleet, snow, blizzard, freezing rain, ice, etc) are in both the top 5 lists for fatalities and injuries. The data suggests that governments should focus public awareness campaigns and spending to mitigate impacts related to these storm events.

Which types of events have the greatest economic consequences?

Top 10 events by property damage costs

Consolidated2$property_damage <- format(Consolidated2$property_damage, big.mark = ",", scientific = FALSE) 
Prop_Damage_top5 <- Consolidated2 %>% select(EVTYPE, event_count, property_damage, prop_damage_ranking) %>%
                                   arrange(desc(property_damage)) %>%
                                   slice(1:5)
print(Prop_Damage_top5)
##                                      EVTYPE event_count property_damage
## 1                                     flood       86052 167,589,027,586
## 2                         tropical cyclones        1056  93,072,537,560
## 3                                   tornado       67541  56,993,293,341
## 4 storm surge, sea/coastal water conditions        2372  48,076,827,500
## 5                                      wind      362907  17,508,007,258
##   prop_damage_ranking
## 1                   1
## 2                   2
## 3                   3
## 4                   4
## 5                   5
# this creates and prints a table of the top 5 event types that cause property damage.

Top 10 events by crop damage costs

Consolidated2$crop_damage <- format(Consolidated2$crop_damage, big.mark = ",", scientific = FALSE) 
Crop_Damage_top5 <- Consolidated2 %>% select(EVTYPE, event_count, crop_damage, crop_damage_ranking) %>%
                                   arrange(desc(crop_damage)) %>%
                                   slice(1:5) 
print(Crop_Damage_top5)
##              EVTYPE event_count    crop_damage crop_damage_ranking
## 1  heat and drought        5458 14,877,060,280                   1
## 2             flood       86052 12,388,567,200                   2
## 3    winter related       46550  8,742,107,900                   3
## 4 tropical cyclones        1056  6,211,013,800                   4
## 5              hail      289251  3,046,937,600                   5
# this creates and prints a table of the top 5 event types that cause crop damage.

Flooding events cause the most property damage; while heat and drought events cause the most crop damage. Given that the total crop damage due to heat and drought events is less than total property damage caused by the top 5 storm related events, governments focus should prioritize mitigating property damage over crop damage.


System information for reproducibility

## $OS.type
## [1] "windows"
## 
## $file.sep
## [1] "/"
## 
## $dynlib.ext
## [1] ".dll"
## 
## $GUI
## [1] "RTerm"
## 
## $endian
## [1] "little"
## 
## $pkgType
## [1] "win.binary"
## 
## $path.sep
## [1] ";"
## 
## $r_arch
## [1] "x64"