In this analysis we will tackle two main question. The first is which events are the most harmful for the population, while the second is which events have a higher impact on the economy.
For the first part we decided that fatalities and injuries caused by a certain event will be our measuring metric. This way we can find the events with a higher number of fatalities/injuries across the US, and these will be the events with a more harmful effect on the population.
For the second part we used the property and crop damage as the measuring metric. Then we used a similar analysis to the previous part to compute the types of event with a higher impact on the economy.
The data was obtained from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database via this link. A documentation file for such data can also be found following the National Weather Service Storm Data Documentation following this link.
After decompressing the data folder, we can read the CSV file using the read.csv() function and load it into R.
library(tidyverse)
library(gridExtra)
stormData = read.csv("repdata_data_StormData.csv")
After this, we prepared the data to address the two problems explained above. For this, we transformed the “EVTYPE” column into a factor and created two smaller and more manageable data frames for the individual questions, to speed up computations.
stormData$EVTYPE = as.factor(stormData$EVTYPE)
dataHealth = stormData[, c("EVTYPE", "FATALITIES", "INJURIES"), drop = FALSE]
dataEcon = stormData[, c("EVTYPE", "PROPDMG", "PROPDMGEXP", "CROPDMG",
"CROPDMGEXP"), drop = FALSE]
In this section we will address the question of which events are the most harmful for the population. For this, we will use two metrics: number of fatalities and number of injuries. We will start by grouping fatalities/injuries by event and sorting in decreasing order.
fat = aggregate(FATALITIES ~ EVTYPE, data = dataHealth, sum)
fat = fat %>% arrange(desc(FATALITIES))
inj = aggregate(INJURIES ~ EVTYPE, data = dataHealth, sum)
inj = inj %>% arrange(desc(INJURIES))
Once this is done, we will create a plot of the top 7 events with the highest number of injuries and fatalities.
fat_7 = head(fat, 7)
gg1 = ggplot(fat_7, aes(x = reorder(EVTYPE, -FATALITIES), y = FATALITIES)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "Type of Event", y = "Total Fatalities", title = "Top 7 Event Types by Fatalities") +
geom_text(aes(label = FATALITIES), vjust = -0.5, size = 3, color = "black") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5)) +
coord_cartesian(ylim = c(0, max(fat_7$FATALITIES) * 1.05))
inj_7 = head(inj, 7)
gg2 = ggplot(inj_7, aes(x = reorder(EVTYPE, -INJURIES), y = INJURIES)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "Type of Event", y = "Total Injuries", title = "Top 7 Event Types by Injuries") +
geom_text(aes(label = INJURIES), vjust = -0.5, size = 3, color = "black") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5)) +
coord_cartesian(ylim = c(0, max(inj_7$INJURIES) * 1.05))
grid.arrange(gg1, gg2, ncol = 2)
In this section we will address the question of which types of event have a higher impact on the economy. As in the previous section, we will choose two variables to guide the analysis: Property damage and crop damage.
First, we transform the values of these columns to be in the same unit, so we can compare them within each column. For this, we transform the unit columns “PROPDMGEXP” and “PROPDMGEXP” to the corresponding exponents in the powers of 10 needed for the conversion.
## Transforming property damage
dataEcon$PROPDMGEXP = gsub("[Hh]", 2, dataEcon$PROPDMGEXP)
dataEcon$PROPDMGEXP = gsub("[Kk]", 3, dataEcon$PROPDMGEXP)
dataEcon$PROPDMGEXP = gsub("[Mm]", 6, dataEcon$PROPDMGEXP)
dataEcon$PROPDMGEXP = gsub("[Bb]", 9, dataEcon$PROPDMGEXP)
dataEcon$PROPDMGEXP = as.numeric(dataEcon$PROPDMGEXP)
## Warning: NAs introducidos por coerción
dataEcon$PROPDMGEXP[is.na(dataEcon$PROPDMGEXP)] = 1
## Transforming crop damage
dataEcon$CROPDMGEXP = gsub("[Hh]", 2, dataEcon$CROPDMGEXP)
dataEcon$CROPDMGEXP = gsub("[Kk]", 3, dataEcon$CROPDMGEXP)
dataEcon$CROPDMGEXP = gsub("[Mm]", 6, dataEcon$CROPDMGEXP)
dataEcon$CROPDMGEXP = gsub("[Bb]", 9, dataEcon$CROPDMGEXP)
dataEcon$CROPDMGEXP = as.numeric(dataEcon$CROPDMGEXP)
## Warning: NAs introducidos por coerción
dataEcon$CROPDMGEXP[is.na(dataEcon$PROPDMGEXP)] = 1
## Converting the damage values
dataEcon = dataEcon %>%
mutate(propDmg = PROPDMG * 10^PROPDMGEXP) %>%
mutate(cropDmg = CROPDMG * 10^CROPDMGEXP)
Once we have done this, we can proceed as before; grouping by event type and sorting to get the events with the most property/crop damage.
prop = aggregate(propDmg ~ EVTYPE, data = dataEcon, sum)
prop = prop %>% arrange(desc(propDmg))
crop = aggregate(cropDmg ~ EVTYPE, data = dataEcon, sum)
crop = crop %>% arrange(desc(cropDmg))
Finally, we create a similar figure showing the events which caused the most damage in billions of dollar for both categories; property and crop damage.
prop_7 = head(prop, 7)
prop_7$propDmg = round(prop_7$propDmg/1e9, 2)
gg1 = ggplot(prop_7, aes(x = reorder(EVTYPE, -propDmg), y = propDmg)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "Type of Event", y = "Total Property Damage ($10^9)", title = "Top 7 Event Types by Property Damage") +
geom_text(aes(label = propDmg), vjust = -0.5, size = 3, color = "black") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5, size = 12)) +
coord_cartesian(ylim = c(0, max(prop_7$propDmg) * 1.05))
crop_7 = head(crop, 7)
crop_7$cropDmg = round(crop_7$cropDmg/1e9, 2)
gg2 = ggplot(crop_7, aes(x = reorder(EVTYPE, -cropDmg), y = cropDmg)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(x = "Type of Event", y = "Total Crop Damage ($10^9)", title = "Top 7 Event Types by Crop Damage") +
geom_text(aes(label = cropDmg), vjust = -0.5, size = 3, color = "black") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5, size = 12)) +
coord_cartesian(ylim = c(0, max(crop_7$cropDmg) * 1.05))
grid.arrange(gg1, gg2, ncol = 2)
As can be seen in the plots above, we were able to devise a strategy for computing the event types with the most impact on both population health and the economy. This was done by introducing some metrics and seeing which events ranked highest within these chosen variables.
In the first part we see that tornados are the most dangerous to the population by far, both in terms of injuries and fatalities. Floods, heat and lightning also rank high in both lists.
For the last part it can be seen in the figure that floods have the highest total impact, followed by typhoons and tornados. However, although droughts are not specially impactful in asbolute terms, they are extremely detrimental to the crops.