Shreyash Mishra
19 May, 2020

ANALYSIS ON THE IMPACT OF WEATHER EVENTS IN US

Introduction

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
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

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.

Data Processing

Load the packages that will be needed for aggregating the data, and visualizing the results.

library(ggplot2)
library(gridExtra)

Download the data using the link above, and start your analysis.

url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
zipFile <- "Data.csv.zip"
if (!file.exists(zipFile)) {download.file(url, zipFile, mode = "wb")}
b <- read.table("Data.csv.zip",header=TRUE,sep=",")

Quickly inspect your dataset.

str(b)
## 'data.frame':    902297 obs. of  37 variables:
##  $ STATE__   : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
##  $ BGN_TIME  : Factor w/ 3608 levels "00:00:00 AM",..: 272 287 2705 1683 2584 3186 242 1683 3186 3186 ...
##  $ TIME_ZONE : Factor w/ 22 levels "ADT","AKS","AST",..: 7 7 7 7 7 7 7 7 7 7 ...
##  $ COUNTY    : num  97 3 57 89 43 77 9 123 125 57 ...
##  $ COUNTYNAME: Factor w/ 29601 levels "","5NM E OF MACKINAC BRIDGE TO PRESQUE ISLE LT MI",..: 13513 1873 4598 10592 4372 10094 1973 23873 24418 4598 ...
##  $ STATE     : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ EVTYPE    : Factor w/ 985 levels "   HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : Factor w/ 35 levels "","  N"," NW",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_LOCATI: Factor w/ 54429 levels ""," Christiansburg",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_DATE  : Factor w/ 6663 levels "","1/1/1993 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_TIME  : Factor w/ 3647 levels ""," 0900CST",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ 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   : Factor w/ 24 levels "","E","ENE","ESE",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_LOCATI: Factor w/ 34506 levels ""," CANTON"," TULIA",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ 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: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ WFO       : Factor w/ 542 levels ""," CI","%SD",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ STATEOFFIC: Factor w/ 250 levels "","ALABAMA, Central",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ ZONENAMES : Factor w/ 25112 levels "","                                                                                                               "| __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ 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   : Factor w/ 436781 levels "","\t","\t\t",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...
head(b$EVTYPE,5)
## [1] TORNADO TORNADO TORNADO TORNADO TORNADO
## 985 Levels:    HIGH SURF ADVISORY  COASTAL FLOOD  FLASH FLOOD ... WND
head(b$FATALITIES,5)
## [1] 0 0 0 0 0
head(b$INJURIES,5)
## [1] 15  0  2  2  2
head(b$PROPDMG,5)
## [1] 25.0  2.5 25.0  2.5  2.5
head(b$PROPDMGEXP,5)
## [1] K K K K K
## Levels:  - ? + 0 1 2 3 4 5 6 7 8 B h H K m M
head(b$CROPDMG,5)
## [1] 0 0 0 0 0
head(b$CROPDMGEXP,5)
## [1]     
## Levels:  ? 0 2 B k K m M

Select the required observations and create a new, smaller dataframe.

events <- data.frame(b$STATE,b$EVTYPE,b$FATALITIES,b$INJURIES,b$PROPDMG,b$PROPDMGEXP,b$CROPDMG,b$CROPDMGEXP)
names(events) <- c("STATE","EVTYPE","FATALITIES","INJURIES","PROPDMG","PROPDMGEXP","CROPDMG","CROPDMGEXP")

Inspect your newly formed dataframe.

str(events)
## 'data.frame':    902297 obs. of  8 variables:
##  $ STATE     : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ EVTYPE    : Factor w/ 985 levels "   HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
##  $ 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: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
head(events)
##   STATE  EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1    AL TORNADO          0       15    25.0          K       0           
## 2    AL TORNADO          0        0     2.5          K       0           
## 3    AL TORNADO          0        2    25.0          K       0           
## 4    AL TORNADO          0        2     2.5          K       0           
## 5    AL TORNADO          0        2     2.5          K       0           
## 6    AL TORNADO          0        6     2.5          K       0

We will need to recode the numbers for property and crop damages using PROPDMG-PROPDMGEXP and CROPDMG-CROPDMGEXP respectively.

#property
# Recode the PROPDMGEXP into appropriate 'multipliers'
events$PROPDMGEXP <- as.character(events$PROPDMGEXP)
events$PROPEXP <- events$PROPDMGEXP
events$PROPEXP[events$PROPDMGEXP == "H"] <- 100        
events$PROPEXP[events$PROPDMGEXP == "h"] <- 100
events$PROPEXP[events$PROPDMGEXP == "K"] <- 1000        
events$PROPEXP[events$PROPDMGEXP == "M"] <- 1e+06        
events$PROPEXP[events$PROPDMGEXP == "m"] <- 1e+06
events$PROPEXP[events$PROPDMGEXP == "B"] <- 1e+09        
events$PROPEXP[events$PROPDMGEXP == ""] <- 1
events$PROPEXP[events$PROPDMGEXP == "0"] <- 1
events$PROPEXP[events$PROPDMGEXP == "1"] <- 10
events$PROPEXP[events$PROPDMGEXP == "2"] <- 100
events$PROPEXP[events$PROPDMGEXP == "3"] <- 1000
events$PROPEXP[events$PROPDMGEXP == "4"] <- 10000
events$PROPEXP[events$PROPDMGEXP == "5"] <- 1e+05
events$PROPEXP[events$PROPDMGEXP == "6"] <- 1e+06
events$PROPEXP[events$PROPDMGEXP == "7"] <- 1e+07
events$PROPEXP[events$PROPDMGEXP == "8"] <- 1e+08
events$PROPEXP[events$PROPDMGEXP == "+"] <- 0
events$PROPEXP[events$PROPDMGEXP == "-"] <- 0
events$PROPEXP[events$PROPDMGEXP == "?"] <- 0
events$PROPEXP <- as.numeric(events$PROPEXP)
events$propvalue <- events$PROPEXP
#Calculate for the PROP DAMAGEVALUE: Whole number x Multiplier
events$propvalue <- events$PROPDMG * events$PROPEXP/10^9

#crops
# Recode the CROPDMGEXP into appropriate 'multipliers'
events$CROPDMGEXP <- as.character(events$CROPDMGEXP)
events$CROPEXP <- events$CROPDMGEXP
events$CROPEXP[events$CROPDMGEXP == "K"] <- 1000
events$CROPEXP[events$CROPDMGEXP == "k"] <- 1000
events$CROPEXP[events$CROPDMGEXP == "M"] <- 1e+06
events$CROPEXP[events$CROPDMGEXP == "m"] <- 1e+06
events$CROPEXP[events$CROPDMGEXP == "B"] <- 1e+09
events$CROPEXP[events$CROPDMGEXP == "0"] <- 1
events$CROPEXP[events$CROPDMGEXP == "2"] <- 100
events$CROPEXP[events$CROPDMGEXP == ""] <- 1
events$CROPEXP[events$CROPDMGEXP == "?"] <- 0
events$CROPEXP <- as.numeric(events$CROPEXP)
events$cropvalue <- events$CROPEXP
#Calculate for the CROP DAMAGEVALUE: Whole number x Multiplier
events$cropvalue <- events$CROPDMG * events$CROPEXP/10^9

Collect the data in appropriate fashion.

#Get the total number (SUM) of injuries/fatalities/damages by event type.
dfatal<-aggregate(FATALITIES ~ EVTYPE, data=events, sum)
dinjury <- aggregate(INJURIES ~ EVTYPE, data=events, sum)
dprop <- aggregate(propvalue ~ EVTYPE, data=events, sum)
dcrop <- aggregate(cropvalue ~ EVTYPE, data=events, sum)
#sort the data in descending order
dfatal <- dfatal[order(dfatal$FATALITIES,decreasing=TRUE),]
dinjury <- dinjury[order(dinjury$INJURIES,decreasing=TRUE),]
dprop <- dprop[order(dprop$propvalue,decreasing=TRUE),]
dcrop <- dcrop[order(dcrop$cropvalue,decreasing=TRUE),]
#select the top 10 most harmful factors
sfatal <- dfatal[1:10,]
sinjury <- dinjury[1:10,]
sprop <- dprop[1:10,]
scrop <- dcrop[1:10,]

Impact to population health

Show the top 10 events in terms of number of fatalities, and injuries.

g1 <- ggplot(data=sfatal, aes(x=reorder(EVTYPE, FATALITIES), y=FATALITIES)) +
        geom_bar(fill="red",stat="identity")  + coord_flip() +
        labs(title="Top 10 Fatality - causing Events in US",x="Weather Event", y="Total Number of Fatalities")
g2 <- ggplot(data=sinjury, aes(x=reorder(EVTYPE, INJURIES), y=INJURIES)) +
        geom_bar(fill="red",stat="identity")  + coord_flip() + 
        labs(title="Top 10 Injury-causing Events in US",xlab="Weather Event", ylab="Total Number of Injuries")
g1

g2

Greatest economic consequences

Show the top 10 events in terms of damage to properties and crops.

g3 <- ggplot(data=sprop, aes(x=reorder(EVTYPE, propvalue), y=propvalue)) +
        geom_bar(fill="red",stat="identity")  + coord_flip() + 
        labs(title="Top 10 Property Damaging Events in US",x="Weather Event", y="Total Property Damage (in Billions)")
g4 <- ggplot(data=scrop, aes(x=reorder(EVTYPE, cropvalue), y=cropvalue)) +
        geom_bar(fill="red",stat="identity")  + coord_flip() + 
        labs(title="Top 10 Crop Damaging Events in US",x="Weather Event", y="Total Crop Damage (in Billions)")
g3

g4

Results

In terms of number of injuries and fatalities, TORNADO has the highest damage to people’s health.
On the other hand, FLOOD has the highest property damage cost, and DROUGHT has the highest crop damage cost.