In this project we aim to explore the effects of severe weather events on public health and economy by exploring U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database.
Severe weather events can result in fatalities, injuries and property damage. In this report we investigate the events causing most damage to public health and property.
In our investigation we conclude that Tornados cause the most harm to public health while Floods cause the most property damage.
Original Data is available at: https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2
Documentation for the data is available at: https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf
First, we load the necesssary libraries.
library(dplyr)
library(stringr)
library(tidyr)
library(ggplot2)
We load the data that is in the file called repdata_data_StormData.csv.
stormdt <- read.csv("repdata_data_StormData.csv", na.strings = "" )
There are 902297 rows in the file. We check the first few rows.
dim(stormdt)
## [1] 902297 37
head(stormdt, 3)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL TORNADO
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL TORNADO
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL TORNADO
## BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1 0 <NA> <NA> <NA> <NA> 0 NA
## 2 0 <NA> <NA> <NA> <NA> 0 NA
## 3 0 <NA> <NA> <NA> <NA> 0 NA
## END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1 0 <NA> <NA> 14.0 100 3 0 0 15 25.0
## 2 0 <NA> <NA> 2.0 150 2 0 0 0 2.5
## 3 0 <NA> <NA> 0.1 123 2 0 0 2 25.0
## PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1 K 0 <NA> <NA> <NA> <NA> 3040 8812
## 2 K 0 <NA> <NA> <NA> <NA> 3042 8755
## 3 K 0 <NA> <NA> <NA> <NA> 3340 8742
## LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1 3051 8806 <NA> 1
## 2 0 0 <NA> 2
## 3 0 0 <NA> 3
Next, we check the data for summary information on fatalities, injuries and property damage. We also check for NA values and conclude that there are none for these columns.
ft <- stormdt$FATALITIES
summary(ft)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.0168 0.0000 583.0000
mean(is.na(ft))
## [1] 0
inj <- stormdt$INJURIES
summary(inj)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.1557 0.0000 1700.0000
mean(is.na(inj))
## [1] 0
prp <- stormdt$PROPDMG
summary(prp)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 0.00 0.00 12.06 0.50 5000.00
mean(is.na(prp))
## [1] 0
There is only a subset of information that we are going to use for this report. We will only use the EVTYPE, FATALITIES, INJURIES, PROPDMG and PROPDMGEXP columns, so we subset those. Also, we skip the rows which have the value 0 in these columns.
stormdt <- stormdt[ , c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP")]
# removing events with no data
nonZero <- apply(stormdt[, 2:4], 1, sum)
stormdt <- stormdt[which(nonZero > 0),]
As per documentation, PROPDMGEXP values can be K for thousand, M for million and B for billion. Here we replace the letters with actual values and add a new column named PDEXP.
stormdt <- stormdt %>% mutate(PDEXP = ifelse(PROPDMGEXP == "K", 1000,
ifelse(PROPDMGEXP == "M", 1000000, ifelse(PROPDMGEXP == "B", 1000000000, 1))))
stormdt$PDEXP <- replace_na(stormdt$PDEXP, 1)
There are a lot of typos and mislabeling of Event Types in the original data set. We clean up the data by grouping them by valid events specified in the documentation and fixing the typos as much as possible.
tstm <- grepl("*TSTM *", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[tstm] <- "THUNDERSTORM WIND"
thunder <- grepl("*Thun*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[thunder] <- "THUNDERSTORM WIND"
tornado <- grepl("*Tornado*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[tornado] <- "TORNADO"
blizz <- grepl("*Blizz*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[blizz] <- "BLIZZARD"
blsn <- grepl("*Blowing Snow*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[blsn] <- "BLIZZARD"
coastfl <- grepl("*Coastal*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[coastfl] <- "COASTAL FLOOD"
erosion <- grepl("*erosion*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[erosion] <- "COASTAL FLOOD"
cold <- grepl("^Cold*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[cold] <- "COLD/WIND CHILL"
aval <- grepl("*Aval*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[aval] <- "AVALANCHE"
dusts <- grepl("*Blowing Dust*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[dusts] <- "DUST STORM"
dusty <- grepl("*Dust Storm*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[dusty] <- "DUST STORM"
dustdev <- grepl("*Dust Devil*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[dustdev] <- "DUST DEVIL"
heat <- grepl("^Heat*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[heat] <- "HEAT"
eheat <- grepl("^Record*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[eheat] <- "EXCESSIVE HEAT"
snow <- grepl("*Snow*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[snow] <- "HEAVY SNOW"
xtrm <- grepl("*Extreme*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[xtrm] <- "EXTREME COLD/WIND CHILL"
flash <- grepl("*Flash*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[flash] <- "FLASH FLOOD"
flood <- grepl("Flood*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[flood] <- "FLOOD"
fld <- grepl("*Flood* !flash", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[fld] <- "FLOOD"
freeze <- grepl("*Freeze *", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[freeze] = "FROST/FREEZE"
frost <- grepl("*Frost*)", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[frost] = "FROST/FREEZE"
frdr <- grepl("*Freezing Driz*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[frdr] <- "SLEET"
frrn <- grepl("*Freezing Rain*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[frrn] <- "SLEET"
frsp <- grepl("*Freezing Sp*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[frsp] <- "SLEET"
hail <- grepl("*Hail*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[hail] <- "HAIL"
fire <- grepl("*Fire*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[fire] <- "WILDFIRE"
lightn <- grepl("*Light*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[lightn] <- "LIGHTNING"
rain <- grepl("*Rain*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[rain] <- "HEAVY RAIN"
trop <- grepl("*Tropical Storm*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[trop] <- "TROPICAL STORM"
hwind <- grepl("*High wi*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[hwind] <- "HIGH WIND"
swind <- grepl("*Strong Wi*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[swind] <- "STRONG WIND"
hurr <- grepl("*Hurri*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[hurr] <- "HURRICANE (TYPHOON)"
rip <- grepl("^RIP*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[rip] <- "RIP CURRENT"
winters <- grepl("Winter St*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[winters] <- "WINTER STORM"
winterw <- grepl("Winter We*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[winterw] <- "WINTER WEATHER"
surge <- grepl("*Storm Su*", stormdt[, "EVTYPE"], ignore.case = TRUE)
stormdt$EVTYPE[surge] <- "STORM SURGE/TIDE"
We sum up the fatalities, injuries and damages grouped by event type. Property damages are calculated by multiplying PROPDMG by PDEXP.
sumstorm <- stormdt %>% group_by(EVTYPE) %>% summarize(sum_ft =
sum(FATALITIES), sum_inj = sum(INJURIES), sum_dmg = sum(PROPDMG * PDEXP)) %>% as.data.frame()
We sort the data by number of fatalites in decreasing order. We keep the top ten.
topfatal <- sumstorm[order(sumstorm$sum_ft, sumstorm$sum_inj, sumstorm$sum_dmg, decreasing = TRUE), ]
topfatal <- topfatal[1:10, ]
topfatal$EVTYPE <- factor(topfatal$EVTYPE, levels = topfatal$EVTYPE[order(topfatal$sum_ft, decreasing = TRUE)])
Next, data is sorted by number of injuries in decreasing order and top ten is kept.
topinjur <- sumstorm[order(sumstorm$sum_inj, sumstorm$sum_ft, sumstorm$sum_dmg, decreasing = TRUE), ]
topinjur <- topinjur[1:10, ]
topinjur$EVTYPE <- factor(topinjur$EVTYPE, levels = topinjur$EVTYPE[order(topinjur$sum_inj, decreasing = TRUE)])
Damages are sorted in decreasing order and top 10 is kept.
topdmg <- sumstorm[order(sumstorm$sum_dmg, sumstorm$sum_ft, sumstorm$sum_inj, decreasing = TRUE), ]
topdmg <- topdmg[1:10, ]
topdmg$EVTYPE <- factor(topdmg$EVTYPE, levels = topdmg$EVTYPE[order(topdmg$sum_dmg, decreasing = TRUE)])
As per our analysis Tornados cause most fatalities and injuries in the USA. Excessive Heat is the second leading cause of fatalities, Floods take the third place in fatalities. The plot below shows the top ten Severe Weather Events causing most fatalities.
ggplot(topfatal, aes(x = EVTYPE, y = sum_ft)) +
geom_col() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
xlab("Event Type") + ylab("Number of Fatalities") +
ggtitle("Severe Weather Events Causing Most Fatalities")
Tornados, Thunderstorn Winds, Floods take the top 3 spots as most injury causing Severe Weather Events.
ggplot(topinjur, aes(x = EVTYPE, y = sum_inj)) +
geom_col() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
xlab("Event Type") + ylab("Number of Injuries") +
ggtitle("Severe Weather Events Causing Most Injuries")
Severe Weather Events that cause most property damage are Floods, Hurricane(Typhoon) and Tornados
ggplot(topdmg, aes(x = EVTYPE, y = sum_dmg/1000000000)) +
geom_col() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
xlab("Event Type") + ylab("Damages in Billions (USD)") +
ggtitle("Severe Weather Events Causing Most Damages")
While best effort was made to cleap up the data, there is still much room for improvement. It would be of best interest of public if U.S. National Oceanic and Atmospheric Administration’s (NOAA) would use a software that prevented typos (such as selecting from valid events instead of manually entering) for entering data in the storm database.