Synopsis

This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database, which 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.

Historically, extreme weather and climate events have been attributed to human health risks and economic challenges for communitites and municipalities. Therefore, discovering events and patterns that result in significant casualties and property damage can help identify future vulnerabilities.This knowledge will become increasingly important in the management of susceptibility, implementation of appropriate preventative measures and impact reduction on the overall economy.

Please reference the link below for the full dataset:

https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2

Install and load the required packages required for the completion of this assignment

library(dplyr)
library(ggplot2)
library(reshape2)

Data Processing-Population Health

This section of the analysis will focus on reading in the raw data and subsetting it on the columns of interest, specifically population health statistics. Fatalities and injuries are then summed together and rolled up into each event type.

Loading and pre-processing the raw data

storm_data<-read.csv("C:/Users/aao1009/Desktop/StormData.csv")
names(storm_data)
##  [1] "STATE__"    "BGN_DATE"   "BGN_TIME"   "TIME_ZONE"  "COUNTY"    
##  [6] "COUNTYNAME" "STATE"      "EVTYPE"     "BGN_RANGE"  "BGN_AZI"   
## [11] "BGN_LOCATI" "END_DATE"   "END_TIME"   "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE"  "END_AZI"    "END_LOCATI" "LENGTH"     "WIDTH"     
## [21] "F"          "MAG"        "FATALITIES" "INJURIES"   "PROPDMG"   
## [26] "PROPDMGEXP" "CROPDMG"    "CROPDMGEXP" "WFO"        "STATEOFFIC"
## [31] "ZONENAMES"  "LATITUDE"   "LONGITUDE"  "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS"    "REFNUM"

Subsetting the variables of interest and saving the data in a separate data frame object

p_health<-select(storm_data, c(EVTYPE, FATALITIES, INJURIES))
p_health<-mutate(p_health,TOTAL_CASUALTIES = FATALITIES + INJURIES)
p_agg<-aggregate(TOTAL_CASUALTIES ~ EVTYPE, data = p_health, sum)
p_health_sorted <-p_agg[order(p_agg$TOTAL_CASUALTIES, decreasing=TRUE), ]

Plotting top 10 event types as a sum of fatalities and injuries

top_events<-p_health_sorted[1:10,]
top_events
##                EVTYPE TOTAL_CASUALTIES
## 834           TORNADO            96979
## 130    EXCESSIVE HEAT             8428
## 856         TSTM WIND             7461
## 170             FLOOD             7259
## 464         LIGHTNING             6046
## 275              HEAT             3037
## 153       FLASH FLOOD             2755
## 427         ICE STORM             2064
## 760 THUNDERSTORM WIND             1621
## 972      WINTER STORM             1527
ggplot(top_events, aes(x=EVTYPE, y=TOTAL_CASUALTIES)) + 
      geom_bar(stat="identity", width=.9, fill="purple") + 
      labs(title="TOP 10-HIGHEST CASUALTIES") + 
      theme(axis.text.x = element_text(angle=65, vjust=0.6))

Data Processing-Property Damage

Creating a function that converts the financial damage from a string value, where h=100, k=1000, m=1000000, and b=billion to a usable numeric format

convert_string <- function(e) {
    if (e %in% c("h", "H"))
        return(2)
    else if (e %in% c("k", "K"))
        return(3)
    else if (e %in% c("m", "M"))
        return(6)
    else if (e %in% c("b", "B"))
        return(9)
    else if (!is.na(as.numeric(e))) 
        return(as.numeric(e))
    else if (e %in% c("", "-", "?", "+"))
        return(0)
    else {
        stop("Invalid value.")
    }
}

Implementing the coversion function on the property and crop damage values

economic <- subset(storm_data, PROPDMG > 0 & CROPDMG > 0, select=c(EVTYPE, PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP))
p <- sapply(economic$PROPDMGEXP, FUN=convert_string)
economic$PropertyDamage <- economic$PROPDMG * (10 ** p)
c <- sapply(economic$CROPDMGEXP, FUN=convert_string)
economic$CropDamage <- economic$CROPDMG * (10 ** c)
head(economic)
##                           EVTYPE PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 187566 HURRICANE OPAL/HIGH WINDS     0.1          B      10          M
## 187571        THUNDERSTORM WINDS     5.0          M     500          K
## 187581            HURRICANE ERIN    25.0          M       1          M
## 187583            HURRICANE OPAL    48.0          M       4          M
## 187584            HURRICANE OPAL    20.0          m      10          m
## 187653        THUNDERSTORM WINDS    50.0          K      50          K
##        PropertyDamage CropDamage
## 187566        1.0e+08      1e+07
## 187571        5.0e+06      5e+05
## 187581        2.5e+07      1e+06
## 187583        4.8e+07      4e+06
## 187584        2.0e+07      1e+07
## 187653        5.0e+04      5e+04

Property Damage Rollup for each event type

pdamage_agg<-aggregate(PropertyDamage ~ EVTYPE, data = economic, sum)
pdamage_sorted <-pdamage_agg[order(pdamage_agg$PropertyDamage, decreasing=TRUE), ]
head(pdamage_sorted)
##               EVTYPE PropertyDamage
## 25              HAIL   301960393470
## 14             FLOOD   121971090050
## 10       FLASH FLOOD    66931681760
## 47 HURRICANE/TYPHOON    26740295000
## 42         HURRICANE     7809278000
## 52       RIVER FLOOD     5079635000

Crop Damage Rollup for each event type

cdamage_agg<-aggregate(CropDamage ~ EVTYPE, data = economic, sum)
cdamage_sorted <-cdamage_agg[order(cdamage_agg$CropDamage, decreasing=TRUE), ]
head(cdamage_sorted) 
##               EVTYPE CropDamage
## 52       RIVER FLOOD 5028734000
## 49         ICE STORM 5022113500
## 14             FLOOD 4073443450
## 42         HURRICANE 2688910000
## 47 HURRICANE/TYPHOON 2607822800
## 25              HAIL 1878569130

Plotting top 10 property damaging events

ggplot(data=head(pdamage_sorted, 10), aes(x=reorder(EVTYPE, PropertyDamage), y=log10(PropertyDamage), fill=PropertyDamage )) +
    geom_bar(fill="grey", stat="identity") + coord_flip() +
    xlab("Event type") + ylab("Property Damage in Dollars (log10)") +
    ggtitle("Top 10-Property Damaging Weather Events") +
    theme(plot.title = element_text(hjust = 0))

Plotting top 10 crop damaging events

ggplot(data=head(cdamage_sorted, 10), aes(x=reorder(EVTYPE, CropDamage), y=log10(CropDamage), fill=CropDamage )) +
    geom_bar(fill="orange", stat="identity") + coord_flip() +
    xlab("Event type") + ylab("Crop Damage in Dollars (log10)") +
    ggtitle("Top 10-Crop Damaging Weather Events") +
    theme(plot.title = element_text(hjust = 0))

Results

From the population health perspective, Tornadoes seem to be the most davastating in nature, resulting in the highest number of casualties, followed by excessive heat, tstm winds and floods. In contrast, weather events causing the most financial damage include hail, flood and flash flood, with river flood and ice storm being the highest contributor to crop damage.