This is a submission for the Reproducible Research course, which is part of the data science specialization. It consists of exploratory analysis performed using the explore the NOAA Storm Database. It aims to address two key questions: 1. Across the United States, which types of events are most harmful with respect to population health? 2. Across the United States, which types of events have the greatest economic consequences?
Based on the analysis of NOAA data between the year 1950 and end in November 2011: - it is revealed that across the United States, tornadoes, excessive heat, and flash floods are most detrimental to population health. - the biggest financial damages across the United States are due to tornadoes, thunderstorm winds, and flash floods.
The data for the analysis is obtained from the following location. https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2. This file is downloaded and stored in the project working directory. It consist of data in the year 1950 and end in November 2011. The processing stage is started off with loading the necessary libraries that shall be used to plot and process this document.
library(plyr)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.2
library(knitr)
## Warning: package 'knitr' was built under R version 3.4.3
The downloaded file is read in using load.csv. This will unzip the dataset, and since the data contains the header and we want to retain it, we set header = TRUE
storm.data = read.csv(bzfile("repdata_data_StormData.csv.bz2"), header = TRUE)
We sample view the data that was read in:
head(storm.data)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL
## 4 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL
## 5 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL
## 6 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL
## EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1 TORNADO 0 0
## 2 TORNADO 0 0
## 3 TORNADO 0 0
## 4 TORNADO 0 0
## 5 TORNADO 0 0
## 6 TORNADO 0 0
## COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1 NA 0 14.0 100 3 0 0
## 2 NA 0 2.0 150 2 0 0
## 3 NA 0 0.1 123 2 0 0
## 4 NA 0 0.0 100 2 0 0
## 5 NA 0 0.0 150 2 0 0
## 6 NA 0 1.5 177 2 0 0
## INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1 15 25.0 K 0
## 2 0 2.5 K 0
## 3 2 25.0 K 0
## 4 2 2.5 K 0
## 5 2 2.5 K 0
## 6 6 2.5 K 0
## LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1 3040 8812 3051 8806 1
## 2 3042 8755 0 0 2
## 3 3340 8742 0 0 3
## 4 3458 8626 0 0 4
## 5 3412 8642 0 0 5
## 6 3450 8748 0 0 6
But for the analysis objective not all the columns are needed, thus some of the columns are trimmed. The trimmed data is again sample viewed
reduced.storm.data <- storm.data[,c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG")]
head(reduced.storm.data)
## EVTYPE FATALITIES INJURIES PROPDMG
## 1 TORNADO 0 15 25.0
## 2 TORNADO 0 0 2.5
## 3 TORNADO 0 2 25.0
## 4 TORNADO 0 2 2.5
## 5 TORNADO 0 2 2.5
## 6 TORNADO 0 6 2.5
Some processing to normalize the event naming
reduced.storm.data$EVTYPE <-
gsub("^HEAT$", "EXCESSIVE HEAT", reduced.storm.data$EVTYPE)
reduced.storm.data$EVTYPE <-
gsub("^TSTM WIND$", "THUNDERSTORM WIND", reduced.storm.data$EVTYPE)
reduced.storm.data$EVTYPE <-
gsub("^THUNDERSTORM WIND$", "THUNDERSTORM WINDS", reduced.storm.data$EVTYPE)
The data is aggregated to determine the top fatalities:
agg.fatalities.data <-
aggregate(
reduced.storm.data$FATALITIES,
by=list(reduced.storm.data$EVTYPE), FUN=sum, na.rm=TRUE)
colnames(agg.fatalities.data) = c("event.type", "fatality.total")
fatalities.sorted <-
agg.fatalities.data[order(-agg.fatalities.data$fatality.total),]
top.fatalities <- fatalities.sorted[1:10,]
top.fatalities$event.type <-
factor(
top.fatalities$event.type, levels=top.fatalities$event.type,
ordered=TRUE)
The same is repeated for injuries:
agg.injuries.data <-
aggregate(
reduced.storm.data$INJURIES,
by=list(reduced.storm.data$EVTYPE), FUN=sum, na.rm=TRUE)
colnames(agg.injuries.data) = c("event.type", "injury.total")
injuries.sorted <- agg.injuries.data[order(-agg.injuries.data$injury.total),]
top.injuries <- injuries.sorted[1:10,]
top.injuries$event.type <-
factor(
top.injuries$event.type, levels=top.injuries$event.type,
ordered=TRUE)
And also for property damage:
agg.prop.dmg.data <-
aggregate(
reduced.storm.data$PROPDMG,
by=list(reduced.storm.data$EVTYPE), FUN=sum, na.rm=TRUE)
colnames(agg.prop.dmg.data) = c("event.type", "prop.dmg.total")
prop.dmg.sorted <- agg.prop.dmg.data[order(-agg.prop.dmg.data$prop.dmg.total),]
top.prop.dmg <- prop.dmg.sorted[1:10,]
top.prop.dmg$event.type <-
factor(
top.prop.dmg$event.type, levels=top.prop.dmg$event.type,
ordered=TRUE)
The aggregation gives us the top 10 fatalities based on population health (i.e. fatalities and injuries ) and greatest economic consequences (i.e. property damage). The aggregated data needs to be visualized to have a clearer view.
The plot to view the top fatalities
ggplot(data=top.fatalities, aes(x=event.type, y=fatality.total)) +
geom_bar(stat="identity") + xlab("Event type") + ylab("Total fatalities") +
ggtitle("Fatalities By Event Type") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
We plot the aggregated top injuries
ggplot(data=top.injuries, aes(x=event.type, y=injury.total)) +
geom_bar(stat="identity") + xlab("Event type") + ylab("Total injuries") +
ggtitle("Injuries By Event Type") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
And repeat the same for the economic damages
ggplot(data=top.prop.dmg, aes(x=event.type, y=prop.dmg.total)) +
geom_bar(stat="identity") + xlab("Event type") +
ylab("Total property damage") + ggtitle("Property Damage By Event Type") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
It can be seen from the plots that tornado causes the largest number of fatalities and injuries. As such it is most harmful to population health. Tornado also caused the highest property damange, while hail caused the highest crop damange. Therefore, tornado and hail had the greatest economic consequences.