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.

The basic goal of this analysis is to explore the NOAA Storm Database and answer some basic questions about severe weather events.

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?

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]

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

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.

Data Processing

[describe in words and code how the data was loaded into R and processed for analysis. ]

This R library is required to manipulate data:

library(dplyr)

Data file is downloaded as bz2 compression. But read.csv takes care of decompressing it as it’s uploading the file into R.

url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
filename <- "stormdata.csv.bz2"
download.file(url, destfile = filename, method = "curl")
wx_data <- read.csv(filename, header = TRUE)

The wx_data dataframe has the following dimensions:

dim(wx_data)
## [1] 902297     37

… and structure:

str(wx_data)
## 'data.frame':    902297 obs. of  37 variables:
##  $ STATE__   : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : chr  "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
##  $ BGN_TIME  : chr  "0130" "0145" "1600" "0900" ...
##  $ TIME_ZONE : chr  "CST" "CST" "CST" "CST" ...
##  $ COUNTY    : num  97 3 57 89 43 77 9 123 125 57 ...
##  $ COUNTYNAME: chr  "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
##  $ STATE     : chr  "AL" "AL" "AL" "AL" ...
##  $ EVTYPE    : chr  "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : chr  "" "" "" "" ...
##  $ BGN_LOCATI: chr  "" "" "" "" ...
##  $ END_DATE  : chr  "" "" "" "" ...
##  $ END_TIME  : chr  "" "" "" "" ...
##  $ COUNTY_END: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ COUNTYENDN: logi  NA NA NA NA NA NA ...
##  $ END_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_AZI   : chr  "" "" "" "" ...
##  $ END_LOCATI: chr  "" "" "" "" ...
##  $ LENGTH    : num  14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
##  $ WIDTH     : num  100 150 123 100 150 177 33 33 100 100 ...
##  $ F         : int  3 2 2 2 2 2 2 1 3 3 ...
##  $ MAG       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ FATALITIES: num  0 0 0 0 0 0 0 0 1 0 ...
##  $ INJURIES  : num  15 0 2 2 2 6 1 0 14 0 ...
##  $ PROPDMG   : num  25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
##  $ PROPDMGEXP: chr  "K" "K" "K" "K" ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: chr  "" "" "" "" ...
##  $ WFO       : chr  "" "" "" "" ...
##  $ STATEOFFIC: chr  "" "" "" "" ...
##  $ ZONENAMES : chr  "" "" "" "" ...
##  $ LATITUDE  : num  3040 3042 3340 3458 3412 ...
##  $ LONGITUDE : num  8812 8755 8742 8626 8642 ...
##  $ LATITUDE_E: num  3051 0 0 0 0 ...
##  $ LONGITUDE_: num  8806 0 0 0 0 ...
##  $ REMARKS   : chr  "" "" "" "" ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...

What types of events are most harmful with respect to population health?

The total fatalities by event was calculated and sorted in decreasing order.

FT <- aggregate(FATALITIES ~ EVTYPE, data = wx_data, FUN = sum)
FT.top <- FT[order(-FT$FATALITIES), ][1:15, ]

Likewise the total was calculated for injuries by event:

IN <- aggregate(INJURIES ~ EVTYPE, data = wx_data, FUN = sum)
IN.top <- IN[order(-IN$INJURIES), ][1:15, ]

Here is the code and plot that shows the events with most fatalities and injuries.

par(mfrow = c(1, 2), mar = c(12, 4, 3, 2), mgp = c(3, 1, 0), cex = 0.8)

barplot(FT.top$FATALITIES, 
        las = 3, 
        names.arg = FT.top$EVTYPE, 
        main = "Top 15 Events with Fatalities", 
        ylab = "number of fatalities", 
        col = "red")

barplot(IN.top$INJURIES, 
        las = 3, 
        names.arg = IN.top$EVTYPE, 
        main = "Top 15 Events with Injuries", 
        ylab = "number of injuries", 
        col = "red")

What types of events have the greatest economic consequences?

Property Damage

What does the property damage exponent contain?

unique(wx_data$PROPDMGEXP)
##  [1] "K" "M" ""  "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"

To get a true measure of property damage, the values in property damage column need to be multiplied by the values in the property damage exponent, i.e. PROPDMG * PROPEXP. Therefore the codes in property damage exponent column need to be converted to a numeric value.

wx_data$PROPEXP[wx_data$PROPDMGEXP == "K"] <- 1000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "M"] <- 1000000
wx_data$PROPEXP[wx_data$PROPDMGEXP == ""] <- 1
wx_data$PROPEXP[wx_data$PROPDMGEXP == "B"] <- 1000000000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "m"] <- 1000000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "0"] <- 1
wx_data$PROPEXP[wx_data$PROPDMGEXP == "5"] <- 100000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "6"] <- 1000000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "4"] <- 10000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "2"] <- 100
wx_data$PROPEXP[wx_data$PROPDMGEXP == "3"] <- 1000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "h"] <- 100
wx_data$PROPEXP[wx_data$PROPDMGEXP == "7"] <- 10000000
wx_data$PROPEXP[wx_data$PROPDMGEXP == "H"] <- 100
wx_data$PROPEXP[wx_data$PROPDMGEXP == "1"] <- 10
wx_data$PROPEXP[wx_data$PROPDMGEXP == "8"] <- 100000000
# give 0 to invalid exponent data, so they not count in
wx_data$PROPEXP[wx_data$PROPDMGEXP == "+"] <- 0
wx_data$PROPEXP[wx_data$PROPDMGEXP == "-"] <- 0
wx_data$PROPEXP[wx_data$PROPDMGEXP == "?"] <- 0

Now the property damage value can be calculated.

wx_data$PROPDMGVAL <- wx_data$PROPDMG * wx_data$PROPEXP

And total of each event type is calculated.

propdmg <- aggregate(PROPDMGVAL ~ EVTYPE, data = wx_data, FUN = sum)

Crop Damage

What does the crop damage exponent variable contain?

unique(wx_data$CROPDMGEXP)
## [1] ""  "M" "K" "m" "B" "?" "0" "k" "2"

Similar to the property damage exponent above, this variable also contains codes instead of numerical values. Therefore it needs to be converted.

wx_data$CROPEXP[wx_data$CROPDMGEXP == "M"] <- 1000000
wx_data$CROPEXP[wx_data$CROPDMGEXP == "K"] <- 1000
wx_data$CROPEXP[wx_data$CROPDMGEXP == "m"] <- 1000000
wx_data$CROPEXP[wx_data$CROPDMGEXP == "B"] <- 1000000000
wx_data$CROPEXP[wx_data$CROPDMGEXP == "0"] <- 1
wx_data$CROPEXP[wx_data$CROPDMGEXP == "k"] <- 1000
wx_data$CROPEXP[wx_data$CROPDMGEXP == "2"] <- 100
wx_data$CROPEXP[wx_data$CROPDMGEXP == ""] <- 1
# give 0 to invalid exponent data, so they not count in
wx_data$CROPEXP[wx_data$CROPDMGEXP == "?"] <- 0

Now the crop damage value can be calculated

wx_data$CROPDMGVAL <- wx_data$CROPDMG * wx_data$CROPEXP

And total of each event type is calculated.

cropdmg <- aggregate(CROPDMGVAL ~ EVTYPE, data = wx_data, FUN = sum)

To avoid overcrowding the plots with too much data, only the 15 most damaging events were selected.

propdmg.top <- propdmg[order(-propdmg$PROPDMGVAL), ][1:15, ]
cropdmg.top <- cropdmg[order(-cropdmg$CROPDMGVAL), ][1:15, ]

The following code generate the plots below, which show the events with greatest economical consequences.

par(mfrow = c(1, 2), mar = c(12, 4, 3, 2), mgp = c(3, 1, 0), cex = 0.8)
barplot(propdmg.top$PROPDMGVAL/(10^9), las = 3, names.arg = propdmg.top$EVTYPE, 
        main = "Top Events - Property Damages", ylab = "Cost of damage ($ billions)", 
        col = "red")
barplot(cropdmg.top$CROPDMGVAL/(10^9), las = 3, names.arg = cropdmg.top$EVTYPE, 
        main = "Top Events - Crop Damages", ylab = "Cost of damage ($ billions)", 
        col = "red")

Results

The results from the analysis show that tornado is the number one event that causes fatalities and injuries. As far as property damage, the number one event is flood, while drought is responsible the greatest number of crop damages.