In this project, I analyzed the U.S. National Oceanic and Atmospheric Administration’s (NOAA) Storm Database from 1950 to 2011 in order to determine types of storm events that have the greatest impact to public health as well as events that have the greatest economic consequences. In the following R code, I analyzed health impact and economic impact by sorting, indexing, and totaling the number of fatalities, injuries, and damage amount per each storm event type. From this analysis, I was able to plot in a bar chart total fatalities vs. event type, total injuries vs. event type, and total economic impact vs. event type. Results indicate that the highest number of fatalities are caused by tornados, the highest number of injuries are also caused by tornados, and floods have the greatest economic impact.
Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. Many severe events can result in fatalities, injuries, and property damage, and preventing such outcomes to the extent possible is a key concern.
This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage.
The data analysis addresses the following questions:
The data for this assignment come in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size. The events in the database start in the year 1950 and end in November 2011. In the earlier years of the database there are generally fewer events recorded, most likely due to a lack of good records. More recent years should be considered more complete.
Download and unzip the data from URL provided in the prject rubric.
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(url, "/Users/dad/Documents/Coursera/Data-Science-Specialization/Course5ReproducibleResearch/CourseProject2/StormData.csv.bz2")
library(R.utils)
## Loading required package: R.oo
## Loading required package: R.methodsS3
## R.methodsS3 v1.7.1 (2016-02-15) successfully loaded. See ?R.methodsS3 for help.
## R.oo v1.22.0 (2018-04-21) successfully loaded. See ?R.oo for help.
##
## Attaching package: 'R.oo'
## The following objects are masked from 'package:methods':
##
## getClasses, getMethods
## The following objects are masked from 'package:base':
##
## attach, detach, gc, load, save
## R.utils v2.7.0 successfully loaded. See ?R.utils for help.
##
## Attaching package: 'R.utils'
## The following object is masked from 'package:utils':
##
## timestamp
## The following objects are masked from 'package:base':
##
## cat, commandArgs, getOption, inherits, isOpen, parse, warnings
bunzip2("StormData.csv.bz2", "StormData.csv")
Read the ‘csv’ file into a data frame.
df <- read.csv("StormData.csv")
To evaluate the overall health impact, the total fatalities and total injuries for each event type (EVTYPE) are calculated. R code for these calculations are as follows.
Load the appropiate package
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
Create a subset of the data frame (fatalities subset) by selecting the ‘FATALITIES’ column. Group by the storm event type and sum the total fatalities per event type. Display only the first 10 rows.
df.fatalities <- df %>% select(EVTYPE, FATALITIES) %>% group_by(EVTYPE) %>% summarise(total.fatalities = sum(FATALITIES)) %>% arrange(-total.fatalities)
head(df.fatalities, 10)
## # A tibble: 10 x 2
## EVTYPE total.fatalities
## <fct> <dbl>
## 1 TORNADO 5633
## 2 EXCESSIVE HEAT 1903
## 3 FLASH FLOOD 978
## 4 HEAT 937
## 5 LIGHTNING 816
## 6 TSTM WIND 504
## 7 FLOOD 470
## 8 RIP CURRENT 368
## 9 HIGH WIND 248
## 10 AVALANCHE 224
Create a subset of the data frame (injuries subset) by selecting the ‘INJURIES’ column. Group by the storm event type and sum the total injuries per event type. Display only the first 10 rows.
df.injuries <- df %>% select(EVTYPE, INJURIES) %>% group_by(EVTYPE) %>% summarise(total.injuries = sum(INJURIES)) %>% arrange(-total.injuries)
head(df.injuries, 10)
## # A tibble: 10 x 2
## EVTYPE total.injuries
## <fct> <dbl>
## 1 TORNADO 91346
## 2 TSTM WIND 6957
## 3 FLOOD 6789
## 4 EXCESSIVE HEAT 6525
## 5 LIGHTNING 5230
## 6 HEAT 2100
## 7 ICE STORM 1975
## 8 FLASH FLOOD 1777
## 9 THUNDERSTORM WIND 1488
## 10 HAIL 1361
The above results indicate that the highest number of fatalities and the highest number of injuries occur due to tornadoes.
The data provides two types of economic impact: property damage (PROPDMG) and crop damage (CROPDMG). The damage in U.S. dollar amounts is indicated by the ‘PROPDMGEXP’ and ‘CROPDMGEXP’ variables. According to the National Weather Service Storm Data Documentation, the index in the ‘PROPDMGEXP’ and ‘CROPDMGEXP’ can be interpreted as follows:
H, h -> hundreds = x100
K, k -> kilos = x1,000
M, m -> millions = x1,000,000
B, b -> billions = x1,000,000,000
(+) -> x1
(-) -> x0
(?) -> x0
blank -> x0
The total amount of damage is calculated with the following R code.
Create a subset of the data frame (damage subset) by selecting the ‘EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP’ columns. Create a multiplier, multiply appropiate variables, and create and append new columns with the ‘mutate’ function. Group by the storm event type and sum the total damage per event type. Display only the first 10 rows.
df.damage <- df %>% select(EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
symbol <- sort(unique(as.character(df.damage$PROPDMGEXP)))
multiplier <- c(0, 0, 0, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10^9, 10^2, 10^2, 10^3, 10^6, 10^6)
convert.multiplier <- data.frame(symbol, multiplier)
df.damage$Prop.multiplier <- convert.multiplier$multiplier[match(df.damage$PROPDMGEXP, convert.multiplier$symbol)]
df.damage$Crop.multiplier <- convert.multiplier$multiplier[match(df.damage$CROPDMGEXP, convert.multiplier$symbol)]
df.damage <- df.damage %>% mutate(PROPDMG = PROPDMG*Prop.multiplier) %>% mutate(CROPDMG = CROPDMG*Crop.multiplier) %>% mutate(TOTAL.DMG = PROPDMG + CROPDMG)
df.damage.total <- df.damage %>% group_by(EVTYPE) %>% summarise(TOTAL.DMG.EVTYPE = sum(TOTAL.DMG)) %>% arrange(-TOTAL.DMG.EVTYPE)
head(df.damage.total, 10)
## # A tibble: 10 x 2
## EVTYPE TOTAL.DMG.EVTYPE
## <fct> <dbl>
## 1 FLOOD 150319678250
## 2 HURRICANE/TYPHOON 71913712800
## 3 TORNADO 57352117607
## 4 STORM SURGE 43323541000
## 5 FLASH FLOOD 17562132111
## 6 DROUGHT 15018672000
## 7 HURRICANE 14610229010
## 8 RIVER FLOOD 10148404500
## 9 ICE STORM 8967041810
## 10 TROPICAL STORM 8382236550
The above results indicate that the storm event with the largest economic consequence is a flood.
The top 10 events with the highest number of total fatalities is shown graphically below.
First load the appropiate package and the graph the results in a bar chart with the ‘ggplot’ function.
library(ggplot2)
fatalitiesGraph <- ggplot(df.fatalities[1:10,], aes(x=reorder(EVTYPE, -total.fatalities), y=total.fatalities)) + geom_bar(stat="identity") + theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=1)) + ggtitle("Top 10 Events with Highest Total Fatalities") + labs(x="Event Type", y="Total Fatalities")
fatalitiesGraph
From the above figure, the storm event with the highest number of fatalities is a tornado.
The top 10 events with the highest number of total injuries is shown graphically below.
injuriesGraph <- ggplot(df.injuries[1:10,], aes(x=reorder(EVTYPE, -total.injuries), y=total.injuries)) + geom_bar(stat="identity") + theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=1)) + ggtitle("Top 10 Events with Highest Total Injuries") + labs(x="Event Type", y="Total Injuries")
injuriesGraph
From the above figure, the storm event with the highest number of injuries is also a tornado. Thus, across the United States, tornados are the most harmful with respect to population health.
The top 10 events with the highest total economic damage (property damage and crop damage combined) is shown graphically below.
totalDmgGraph <- ggplot(df.damage.total[1:10,], aes(x=reorder(EVTYPE, -TOTAL.DMG.EVTYPE), y=TOTAL.DMG.EVTYPE)) + geom_bar(stat="identity") + theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=1)) + ggtitle("Top 10 Events with Highest Economic Impact") + labs(x="Event Type", y="Total Economic Impact ($USD)")
totalDmgGraph
From the above figure, the storm event with the highest economic impact is a flood. Thus, across the United States, floods have the greatest economic consequence.