This report explores the NOAA storm database covering events from 1950 to November 2011. The raw compressed csv.bz2 file is loaded directly in R without external pre-processing. We aggregate fatalities, injuries, property and crop damages grouped by weather event type. Tornadoes are the most harmful event to human health. Floods create the largest total economic losses. All analysis can be reproduced by running the provided code. ## Data Processing We read the original compressed storm data file and clean damage values for later aggregation.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
# Load raw bz2 dataset
storm_data <- read.csv(bzfile("repdata_data_StormData.csv.bz2"))
# Keep only required columns
storm_sub <- storm_data %>%
select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
# Function to convert damage exponent to real dollar amount
convert_exp <- function(val, exp){
exp <- toupper(exp)
multiplier <- 1
multiplier[exp=="H"] <- 100
multiplier[exp=="K"] <- 1000
multiplier[exp=="M"] <- 1000000
multiplier[exp=="B"] <- 1000000000
return(val * multiplier)
}
# Calculate real economic damage and total human harm
storm_sub <- storm_sub %>%
mutate(
prop_dmg_real = convert_exp(PROPDMG, PROPDMGEXP),
crop_dmg_real = convert_exp(CROPDMG, CROPDMGEXP),
total_econ_dmg = prop_dmg_real + crop_dmg_real,
total_harm = FATALITIES + INJURIES
)
# Aggregate health harm by event type
agg_health <- storm_sub %>%
group_by(EVTYPE) %>%
summarise(
total_fatal = sum(FATALITIES, na.rm = TRUE),
total_inj = sum(INJURIES, na.rm = TRUE),
total_harm = sum(total_harm, na.rm = TRUE)
) %>%
arrange(desc(total_harm))
## `summarise()` ungrouping output (override with `.groups` argument)
# Aggregate economic damage by event type
agg_econ <- storm_sub %>%
group_by(EVTYPE) %>%
summarise(total_econ = sum(total_econ_dmg, na.rm = TRUE)) %>%
arrange(desc(total_econ))
## `summarise()` ungrouping output (override with `.groups` argument)
## Results
### Question 1: Which events cause the greatest harm to population health?
top10_health <- head(agg_health,10)
ggplot(top10_health, aes(x = reorder(EVTYPE, total_harm), y = total_harm)) +
geom_col(fill="#E74C3C") +
coord_flip() +
labs(x="Event Type", y="Total Harm (Fatalities + Injuries)") +
theme_bw()
Total human harm (fatalities plus injuries) for top weather events
### Question 2: Which events lead to the largest economic consequences?
top10_econ <- head(agg_econ,10)
ggplot(top10_econ, aes(x = reorder(EVTYPE, total_econ), y = total_econ)) +
geom_col(fill="#3498DB") +
coord_flip() +
labs(x="Event Type", y="Total Economic Damage (USD)") +
theme_bw()
Total human harm (fatalities plus injuries) for top weather events