We used the US Storm data to identify the weather events that caused the most death, injury, and destruction. As with many hazards, the worst event is many times worse than the 2nd worst event. As a result, if we want to prevent death and injury, we should target areas prone to tornadoes, with almost 100,000 people harmed. If we want to prevent destruction to crops and property, we should target flood-prone areas, with $150 billion of damage.
To ensure reproducibility, we’ll download the original file directly from the web, if it’s not already in the working directory. We’ll then import it to r without any preprocessing.
fileloc <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
if(!exists("d")){
if(!file.exists("stormdata.csv.bz2")){
download.file(fileloc, "stormdata.csv.bz2", method = "curl")
}
d <- read.csv("stormdata.csv.bz2")
}
While injuries and fatalies are in numerical format, financial damage is reported such that 1.5B = $1.5 billion or $1.5*10^9. Also, some of the events titles vary between upper and lower case, and most are very rare: there are less than 1 per decade. As a result, we’ll transform the data by:
1. calculating the damage per record in dollars
2. summarise the total damage, injuries and fatalies per event type
names(d) <- tolower(names(d))
exponentiate <- function(dmg, exponent){
dollars <- vector(mode = "numeric", length = 902297)
dollars[exponent == "B"] <- dmg[exponent == "B"] * 10^9
dollars[exponent == "m"] <- dmg[exponent == "m"] * 10^6
dollars[exponent == "M"] <- dmg[exponent == "M"] * 10^6
dollars[exponent == "K"] <- dmg[exponent == "K"] * 10^3
numeric.exponents <- !is.na(as.numeric(as.character(exponent)))
dollars[numeric.exponents] <-
dmg[numeric.exponents] *
10 ^ as.numeric(as.character(exponent[numeric.exponents]))
dollars
}
d$property.damage <- exponentiate(d$propdmg, d$propdmgexp)
## Warning in exponentiate(d$propdmg, d$propdmgexp): NAs introduced by
## coercion
d$crop.damage <- exponentiate(d$cropdmg, d$cropdmgexp)
## Warning in exponentiate(d$cropdmg, d$cropdmgexp): NAs introduced by
## coercion
d$evtype <- factor(toupper(as.character(d$evtype)))
event.summaries <- aggregate(d$property.damage, list(d$evtype), sum)
names(event.summaries) <- c("event", "property.damage")
event.summaries$number.recorded <- table(d$evtype)
event.summaries$crop.damage <- aggregate(d$crop.damage, list(d$evtype), sum)[,2]
event.summaries$total.deaths <- aggregate(d$fatalities, list(d$evtype), sum)[,2]
event.summaries$total.injuries <- aggregate(d$injuries, list(d$evtype), sum)[,2]
As a government official, we are not interested in rates of harm (injuries per event) but total harms. This is because sharknadoes could have a high rate of harm (100 deaths per sharknado) but would be very rare (There have only been 5, thank god: https://www.rottentomatoes.com/m/sharknado_5_global_swarming/).
Therefore, start by sorting the events in terms of the total number of deaths and injuries (combined) and choose the top ten.
event.summaries <- event.summaries[order(event.summaries$total.deaths
+event.summaries$total.injuries,
decreasing = TRUE),]
top.ten.risks <- event.summaries[1:10,]
require(ggplot2)
## Loading required package: ggplot2
require(reshape2)
## Loading required package: reshape2
top.ten.risks$event <- factor(top.ten.risks$event, levels = top.ten.risks$event)
molten.risks <- melt(top.ten.risks, id.vars = "event", measure.vars = c("total.deaths", "total.injuries"))
ggplot(data = molten.risks, aes(x = event, y = value, fill = variable)) +
geom_bar(stat = "identity") + scale_fill_manual(values = c("black", "red")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) + labs(x = "Weather Event", y = "Population Harmed")
Based on these data, if we want to prevent death and injury, the most important weather events to prepare for are:
1) Tornado (without sharks)
2) Excessive heat
3) Thunderstorm winds
4) Flooding
5) Lightning
Using the same logic as above, lets plot the costs to crops and property.
event.summaries <- event.summaries[order(event.summaries$property.damage
+event.summaries$crop.damage,
decreasing = TRUE),]
top.ten.costs <- event.summaries[1:10,]
top.ten.costs$event <- factor(top.ten.costs$event, levels = top.ten.costs$event)
molten.costs <- melt(top.ten.costs, id.vars = "event", measure.vars = c("property.damage", "crop.damage"))
require(scales)
## Loading required package: scales
ggplot(data = molten.costs, aes(x = event, y = value, fill = variable)) +
geom_bar(stat = "identity") + scale_fill_manual(values = c("orange", "red")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_y_continuous(labels = dollar) + labs(x = "Weather Event", y = "Economic Consequences")
Based on these data, if we want to prevent damage to crops and property, the most important weather events to prepare for are:
1) Flood
2) Hurricane
3) Tornado (no sharks)
4) Storm Surge
5) Hail