Synopsis

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.

Data Processing

Download packages

library(R.utils)
library(ggplot2)
library(plyr)

Download data:

The data for this assignment come in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size. You can download the file from the course web site:

Storm Data [47Mb]

file_name <- "StormData.csv.bz2"

if (!file.exists(file_name)){
  fileURL <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
  download.file(fileURL, file_name)
}  

if (!exists('stormdata')) {
  stormdata <- read.csv("StormData.csv.bz2", stringsAsFactors = FALSE)
}

There is also some documentation of the database available. Here you will find how some of the variables are constructed/defined.

National Weather Service Storm Data Documentation
National Climatic Data Center Storm Events FAQ

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.

Clean data:

First we want to subset the data by selecting only the columns we are interested in and only the rows where the event type is not blank and fatalities, injuries, property damage, or crop damage is greater than zero:

storm_data <- subset(stormdata, EVTYPE != "?" & (FATALITIES > 0 | INJURIES > 0 | PROPDMG > 0 | CROPDMG > 0),
select = c("EVTYPE", 
           "FATALITIES", 
           "INJURIES", 
           "PROPDMG", 
           "PROPDMGEXP", 
           "CROPDMG", 
           "CROPDMGEXP"))

According to page 12 of the documentation, the PROPDMG and CROPDMG variables must be accompanied by the PROPDMGEXP and CROPDMGEXP variables, which contains information on the magnitude of the values. The magnitude variables represent the following values:

  • H for hundreds
  • K for thousands
  • M for millions
  • B for billions
  • X where X is between 1 and 9 for 10^X

In order to be able to use PROPDMG and CROPDMG, we need to multiply them by the value indicated by their magnitude varaible:

storm_data$PROPMULT <- 1
storm_data$PROPMULT [(storm_data$PROPDMGEXP =="H") | (storm_data$PROPDMGEXP =='h')] <- 100
storm_data$PROPMULT [(storm_data$PROPDMGEXP =="K") | (storm_data$PROPDMGEXP =="k")] <- 1000
storm_data$PROPMULT [(storm_data$PROPDMGEXP =="M") | (storm_data$PROPDMGEXP =="m")] <- 1000000
storm_data$PROPMULT [(storm_data$PROPDMGEXP =="B") | (storm_data$PROPDMGEXP =="b")] <- 1000000000
storm_data$PROPMULT [storm_data$PROPDMGEXP =="1"] <- 10
storm_data$PROPMULT [storm_data$PROPDMGEXP =="2"] <- 100
storm_data$PROPMULT [storm_data$PROPDMGEXP =="3"] <- 1000
storm_data$PROPMULT [storm_data$PROPDMGEXP =="4"] <- 10000
storm_data$PROPMULT [storm_data$PROPDMGEXP =="5"] <- 100000
storm_data$PROPMULT [storm_data$PROPDMGEXP =="6"] <- 1000000
storm_data$PROPMULT [storm_data$PROPDMGEXP =="7"] <- 10000000
storm_data$PROPMULT [storm_data$PROPDMGEXP =="8"] <- 100000000
storm_data$PROPMULT [storm_data$PROPDMGEXP =="9"] <- 1000000000
storm_data$PROPERTY_DAMAGE <- storm_data$PROPDMG*storm_data$PROPMULT 

storm_data$CROPMULT <- 1
storm_data$CROPMULT [(storm_data$CROPDMGEXP =="H") | (storm_data$CROPDMGEXP =='h')] <- 100
storm_data$CROPMULT [(storm_data$CROPDMGEXP =="K") | (storm_data$CROPDMGEXP =="k")] <- 1000
storm_data$CROPMULT [(storm_data$CROPDMGEXP =="M") | (storm_data$CROPDMGEXP =="m")] <- 1000000
storm_data$CROPMULT [(storm_data$CROPDMGEXP =="B") | (storm_data$CROPDMGEXP =="b")] <- 1000000000
storm_data$CROPMULT [storm_data$CROPDMGEXP =="1"] <- 10
storm_data$CROPMULT [storm_data$CROPDMGEXP =="2"] <- 100
storm_data$CROPMULT [storm_data$CROPDMGEXP =="3"] <- 1000
storm_data$CROPMULT [storm_data$CROPDMGEXP =="4"] <- 10000
storm_data$CROPMULT [storm_data$CROPDMGEXP =="5"] <- 100000
storm_data$CROPMULT [storm_data$CROPDMGEXP =="6"] <- 1000000
storm_data$CROPMULT [storm_data$CROPDMGEXP =="7"] <- 10000000
storm_data$CROPMULT [storm_data$CROPDMGEXP =="8"] <- 100000000
storm_data$CROPMULT [storm_data$CROPDMGEXP =="9"] <- 1000000000
storm_data$CROP_DAMAGE <- storm_data$CROPDMG*storm_data$CROPMULT 

In order to be able to measure economic consequences, we need to add the columns PROPERTY_DAMAGE and CROP_DAMAGE to get the total ECON_DAMAGE:

storm_data$ECON_DAMAGE <- storm_data$PROPERTY_DAMAGE+storm_data$CROP_DAMAGE

Finally, we need to aggregate storm_data by event type and divide total economic damage by 1,000,000 to make the number more manageable:

fatalities <- aggregate(storm_data$FATALITIES, by = list(storm_data$EVTYPE), FUN = sum)
colnames(fatalities) <- c("EVTYPE", "FATALITIES")
fatalities <- arrange(fatalities, desc(FATALITIES))[1:10, 1:2]

injuries <- aggregate(storm_data$INJURIES, by = list(storm_data$EVTYPE), FUN = sum)
colnames(injuries) <- c("EVTYPE", "INJURIES")
injuries <- arrange(injuries, desc(INJURIES))[1:10, 1:2]

econ_damage <- aggregate(storm_data$ECON_DAMAGE, by = list(storm_data$EVTYPE), FUN = sum)
colnames(econ_damage) <- c("EVTYPE", "ECON_DAMAGE")
econ_damage <- arrange(econ_damage, desc(ECON_DAMAGE))[1:10, 1:2]
econ_damage$ECON_DAMAGE <- econ_damage$ECON_DAMAGE/1000000

Results

Question 1:

  • Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?

What are the 10 event types with the most fatalities:

g <- ggplot(fatalities, aes(x=reorder(EVTYPE, -FATALITIES), y=FATALITIES))
g <- g + geom_bar(stat="identity") 
g <- g + theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=1))
g <- g + ggtitle("Top 10 Event Types with Highest Total Fatalities in U.S.") 
g <- g + xlab("Event Type")
g <- g + ylab("Total Fatalities")
g

What are the 10 event types with the most injuries:

g2 <- ggplot(injuries, aes(x=reorder(EVTYPE, -INJURIES), y=INJURIES))
g2 <- g2 + geom_bar(stat="identity") 
g2 <- g2 + theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=1))
g2 <- g2 + ggtitle("Top 10 Event Types with Highest Total Injuries in U.S.") 
g2 <- g2 + xlab("Event Type")
g2 <- g2 + ylab("Total Injuries")
g2

We can see from these plots that tornados are the most harmful events with respect to population health.

Question 2:

  • Across the United States, which types of events have the greatest economic consequences?

What are the 10 event types with the highest cost in propery damage and crop damage:

g3 <- ggplot(econ_damage, aes(x=reorder(EVTYPE, -ECON_DAMAGE), y=ECON_DAMAGE))
g3 <- g3 + geom_bar(stat="identity") 
g3 <- g3 + theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=1))
g3 <- g3 + ggtitle("Top 10 Event Types with Highest Total Cost in U.S.") 
g3 <- g3 + xlab("Event Type")
g3 <- g3 + ylab("Total Cost ($Millions)")
g3

According to the plot above, hurricanes have had the highest cost in terms of both property and crop damage.