This report aims to find which weather events in the United States between the years 1950 and 2011 are the most damaging to public health and economic well being. Data was obtained from the National Centers for Environmental Information Storm Events Database for the years 1950 till 2011. To measure health impacts, two metric were examined: total injuries caused by a weather event and total fatalities caused by a weather event. To measure economic impacts, one metric was used: total dollar amount of damage (property damage plus crop damage). Tornadoes were the most damaging event to public health in both injuries and fatalities. Flooding was the most detrimental event economically.
The data for this project is obtained from the National Weather Service.
For data import, we have two immediate tasks: first to download the
stormdata.csv file from the source.
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", "stormdata.csv")
And secondly to import the data into R.
data <- read_csv("stormdata.csv", show_col_types = FALSE)
When read_csv() is used on the url to download the data
directly, an error was generated that “Reading from remote ‘bz2’
compressed files is not supported, download the files locally first”
leading to the two step process above.
Since we are interested in economic data, we need to transform the
variables PROPDMG and CROPDMG to incorporate
their modifiers PROPDMGEXP and CROPDMGEXP
respectively. These two modifiers are K, M,
and B denoting thousands, millions, and billions of
dollars. Before completing this, I checked whether there were other
modifiers present in significant amounts.
# What is the distribution of event classifications?
data_EXP <- data %>%
summarize("KMB" = sum(PROPDMGEXP %in% c("K", "M", "B")),
"num_NA" = sum(is.na(PROPDMGEXP)),
"misc" = nrow(data) - KMB - num_NA,
"total" = nrow(data))
data_EXP
## # A tibble: 1 × 4
## KMB num_NA misc total
## <int> <int> <int> <int>
## 1 436035 465934 328 902297
There are other modifiers present including “+”, “?”, “h”, “5” that were present in low quantities (0.036% of total data) and were ignored for this analysis.
# Incorportae the exponential modifiers.
data <- data %>%
mutate(PROPDMG = ifelse(is.na(PROPDMGEXP), PROPDMG,
ifelse(PROPDMGEXP == "K", PROPDMG * 10^3,
ifelse(PROPDMGEXP == "M", PROPDMG * 10^6,
ifelse(PROPDMGEXP == "B", PROPDMG * 10^9, PROPDMG)))),
CROPDMG = ifelse(is.na(CROPDMGEXP), CROPDMG,
ifelse(CROPDMGEXP == "K", CROPDMG * 10^3,
ifelse(CROPDMGEXP == "M", CROPDMG * 10^6,
ifelse(CROPDMGEXP == "B", CROPDMG * 10^9, CROPDMG)))))
Across the United States, which types of events (as indicated in the
EVTYPE variable) are most harmful with respect to population health? To
answer this question, we have two metrics from the dataset we can look
at: FATALITIES and INJURIES.
# Do NA's need to be filtered?
data %>%
select(EVTYPE, FATALITIES, INJURIES) %>%
# Apply sum(is.na(x)) across each column
summarize(across(everything(), function(x) sum(is.na(.))))
## # A tibble: 1 × 3
## EVTYPE FATALITIES INJURIES
## <int> <int> <int>
## 1 0 0 0
Since there are no NA’s to worry about, we can proceed to investigating which weather events are most harmful. For this analysis, I was interested in which weather events had the most cumulative fatalities and injuries over the span of the data.
health_totals <- data %>%
# Subset the data for ease of computation
select(EVTYPE, FATALITIES, INJURIES) %>%
group_by(EVTYPE) %>%
# Find total fatalities and injuries
summarize(TOTAL_FATALITIES = sum(FATALITIES),
TOTAL_INJURIES = sum(INJURIES))
health_totals %>%
# Find 10 worst types of weather events by fatalities
arrange(desc(TOTAL_FATALITIES)) %>%
slice_head(n = 10) %>%
# Note need to force ggplot to order EVTYPE, defaults to alphabetical
ggplot(aes(fct_inorder(EVTYPE), TOTAL_FATALITIES)) +
geom_col() +
# To aid clarity, label each column with total fatalities
geom_text(aes(label = TOTAL_FATALITIES), hjust = "left") +
coord_flip() +
# Extend scale slightly so largest bar's label fits.
scale_y_continuous(limits =
c(0, max(health_totals$TOTAL_FATALITIES)*1.08)) +
labs(
y = "Total Fatalities",
x = "Event Type",
title = "Tornadoes lead total fatalities",
subtitle = "Data from years 1950 till 2011"
)
This plot makes evident that the tornado weather event dominates fatalities.
# Same justifications
health_totals %>%
arrange(desc(TOTAL_INJURIES)) %>%
slice_head(n = 10) %>%
ggplot(aes(fct_inorder(EVTYPE), TOTAL_INJURIES)) +
geom_col() +
geom_text(aes(label = TOTAL_INJURIES), hjust = "left") +
coord_flip() +
scale_y_continuous(limits = c(0, max(health_totals$TOTAL_INJURIES)*1.08)) +
labs(
y = "Total Injuries",
x = "Event Type",
title = "Tornadoes lead total injuries as well",
subtitle = "Data from years 1950 till 2011")
And this second plot reinforces the first that Tornadoes are a dominant weather event for causing health harm for both fatalities and injuries. The remaining top 10 are largely the same across both plots with “Hail”, “Thunderstorm Wind”, and “Ice Storm” replacing “Avalanche”, “High Wind”, and “Rip Current” on injuries as these latter three tend to produce more fatalities.
To examine this question, we can look at a subset of the data that
looks at EVTYPE and measures of economic impact such as
PROPDMG and CROPDMG.
To examine a measure of economic consequences, I was interested in
finding which weather events had the largest sum of economic damages
from both sources. In the following analysis, the total damage (sum of
PROPDMG and CROPDMG for each event) is
computed, the resulting data is sorted in descending order, and the 10
events with the highest total cost are displayed.
econ_data <- data %>%
# group by event type
group_by(EVTYPE) %>%
# Compute, within each event, the total property damage, crop damage, and
# sum of both over the span of the data.
summarize(prop_dmg = sum(PROPDMG),
crop_dmg = sum(CROPDMG),
total_dmg = prop_dmg + crop_dmg,
total_dmg_lbl = sprintf("%.1fB", total_dmg / 10^9)) %>%
# Sort in descending order, highest total damage at the top
arrange(desc(total_dmg)) %>%
slice_head(n = 10) %>%
# I'd like the plot to reflect both damage types in a single bar, so the
# data needs to be pivoted longer to enable the `fill` aesthetic to map
# damage type. Note this is also "tidy" data.
pivot_longer(c(prop_dmg, crop_dmg), names_to = "dmg_type", values_to = "dmg")
econ_data %>%
# To keep order of event type from prior sorting, use `fct_inorder`
# Use fill = dmg_type to split plot both types of damage
ggplot(aes(x = fct_inorder(EVTYPE), y = dmg, fill = dmg_type)) +
geom_col() +
geom_text(aes(label = total_dmg_lbl, y = total_dmg),
data = econ_data,
hjust = "left",
size = 3) +
# Flip coordinates to aid in display of long EVTYPE names
coord_flip() +
# Extend scale to correctly display left justified labels
scale_y_continuous(limits = c(0, max(econ_data$total_dmg)*1.08)) +
labs(title = "Floods are the leading cause of economic damage",
y = "Damage (dollars)",
x = "Event Type") +
# Set a color-blindness resilient color scheme
scale_fill_brewer(palette = "Set1", name = "Damage Type", labels = c("Crop", "Property"))
The most economically damaging type of weather event in total dollars of damage caused is floods.