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 basic goal of this project is to explore the (NOAA)Storm Database collected between 1950 - 2011 to address the following questions:
Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
There is also some documentation of the database available. Here you will find how some of the variables are constructed/defined at the National Weather Service Storm Data Documentation
We start by requiring needed packages and uploading the original Storm Data [47Mb] file provided by Coursera.
library(readr) # allows us to more efficiently load large files
library(dplyr) # allows for effective data manipulation
library(ggplot2) # to create needed graphics
library(lubridate)# to work with data variables
library(gridExtra)# to assist with plots
StormData <- read_csv("StormData.csv.bz2")
# dim(StormData)
# names(StormData)
Since this is such a large dataset, we will limit it to only variables that we are interested in. The ‘CROPDMGEXP’ is the exponent values for ‘CROPDMG’ (crop damage). In the same way, ‘PROPDMGEXP’ is the exponent values for ‘PROPDMG’ (property damage). We use both to get the total values for crops and property damage. (B or b = Billion, M or m = Million, K or k = Thousand, H or h = Hundred). The number from one to ten represent the power of ten (10^The number). The symbols “-”, “+” and “?” refers to less than, greater than and low certainty. You have the option to ignore these three symbols altogether. According to NOAA the data recording start from Jan. 1950. At that time they recorded one event type, tornado. They add more events gradually and only from Jan. 1996 they start recording all events type. Since our objective is comparing the effects of different weather events, we could also only look at data from 1996 or later.
We also create a new variable EVYear which identifies the year in with the event began.
StormData1 <- select(StormData, BGN_DATE, EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG,CROPDMGEXP)
#Keep only rows of data with actual harm or damage is recorded
StormData1 <- filter(StormData1, FATALITIES > 0 | INJURIES > 0 | PROPDMG > 0 | CROPDMG > 0)
# To restrict data to 1996 or later
StormData1 <- mutate(StormData1, EVYear = year(as.POSIXct(BGN_DATE, format = "%m/%d/%Y")))
StormData1 <- filter(StormData1, EVYear > 1995)
HarmDataEv <- group_by(StormData1, EVTYPE)
HarmDataEv <- summarize(HarmDataEv, TotFatalities=sum(FATALITIES), TotInjuries = sum(INJURIES), TotHarm = TotFatalities + TotInjuries)
HarmDataEv <- arrange(HarmDataEv, desc(TotFatalities))
HarmDataEv <- filter(HarmDataEv, TotFatalities > 200)
# Taking the exponents of properly and crop damage into account
dataexp <- function(exp) {
if(exp=="h" | exp=="H" | exp== "2") {
return(100)
} else if(exp=="k" | exp=="K" | exp =="3") {
return(1000)
} else if(exp == "4") {
return(1e+04)
} else if(exp == "5") {
return(1e+05)
} else if(exp == "m" | exp == "M" | exp =="6") {
return(1e+06)
} else if(exp == "7") {
return(1e+07)
} else if(exp == "b" | exp == "B") {
return(1e+09)
} else {
return(1)
}
}
StormData2 = subset(StormData1, !is.na(PROPDMGEXP))
PropExp <- sapply(StormData2$PROPDMGEXP, function(x) {dataexp(x)})
StormData2$PropAMT <- StormData2$PROPDMG * PropExp
StormData3 = subset(StormData1, !is.na(CROPDMGEXP))
CropExp <- sapply(StormData3$CROPDMGEXP, function(x) {dataexp(x)})
StormData3$CropAMT <- StormData3$CROPDMG * CropExp
PropData <- group_by(StormData2, EVTYPE)
PropData <- summarize(PropData, TotProp=sum(PropAMT))
PropData <- arrange(PropData, desc(TotProp))
PropData <- filter(PropData, TotProp > 5000000000)
CropData <- group_by(StormData3, EVTYPE)
CropData <- summarize(CropData, TotCrop=sum(CropAMT))
CropData <- arrange(CropData, desc(TotCrop))
CropData <- filter(CropData, TotCrop > 700000000)
Creating bar charts based of the event types that are most harmful with respect to population health. The following graphs identify the weather events with the most amount of harm (fatalities or injuries).
#ggplot(HarmDataEv) + geom_bar(aes(x=EVTYPE, y=TotFatalities))
q <- ggplot(HarmDataEv, aes(x=EVTYPE, y=TotFatalities)) +geom_bar(stat = "identity")
q <- q + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + geom_bar(stat="identity") + ggtitle("Total Deaths by Top Weather Event Types") + xlab("Weather Event") + ylab("Deaths") + theme(plot.title = element_text(size = rel(.9)))
HarmDataEv2 <- filter(HarmDataEv, TotInjuries > 250)
p <- ggplot(HarmDataEv2, aes(x=EVTYPE, y=TotInjuries)) +geom_bar(stat = "identity")
p <- p + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + geom_bar(stat="identity") + ggtitle("Total Injuries by Top Weather Event Types") + xlab("Weather Event") + ylab("Injuries") + theme(plot.title = element_text(size = rel(.9)))
grid.arrange(q, p, ncol=2)
To address which types of events have the greatest economic consequences, the following bar charts are based upon the event types with the largest amount of crop and property damage.
q <- ggplot(PropData, aes(x=EVTYPE, y=TotProp)) +geom_bar (stat = "identity")
q <- q + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + geom_bar(stat="identity") + ggtitle("Top Events for Property Damage") + xlab("Weather Event") + ylab("Deaths") + theme(plot.title = element_text(size = rel(.9)))
p <- ggplot(CropData, aes(x=EVTYPE, y=TotCrop)) +geom_bar(stat = "identity")
p <- p + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + geom_bar(stat="identity") + ggtitle("Top Events for Crop Damage") + xlab("Weather Event") + ylab("Injuries") + theme(plot.title = element_text(size = rel(.9)))
grid.arrange(q, p, ncol=2)