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.

SYNOPSIS

  1. This is an exploration of the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database.
  2. The FATALITIES and INJURIES variables are selected to evaluate which event is the most harmful with respect to public health.
  3. The PROPDMG, PRODMGEXP, CROPDMG and CROPDMGEXP variables are selected to evaluate which event is the most harmful with respect to economic consequences.
  4. The PROPDMG and PRODMGEXP variables are processed into one variable showing the final property damage.
  5. The CORPDMG and CROPDMGEXP variables are processed into one variable showing the final crop damage.
  6. Across the United States, Tornados are the most harmful events with respect to population health, creating the largest number of fatalities and injuries.
  7. Across the United States, Floods have the greatest economic consequences with repect to property damage; Droughts have the greatest economic consequences with repect to crop damage.

DATA PROCESSING

Install Packages

library(rmarkdown)
library(R.utils)
library(knitr)
library(tidyr)
library(dplyr)
library(ggplot2)

Download and read the data

if(!file.exists("C:/Users/pmeng2/Documents/R.Studio/Reproducible_research/RepData_PeerAssessment2/stormData.csv.bz2"))
        {
        download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", destfile="C:/Users/pmeng2/Documents/R.Studio/Reproducible_research/RepData_PeerAssessment2/stormData.csv.bz2")
        }
if(!file.exists("C:/Users/pmeng2/Documents/R.Studio/Reproducible_research/RepData_PeerAssessment2/stormdata.csv"))
        {
        bunzip2("stormData.csv.bz2","stormdata.csv",remove=F)
        }
stormdata <- read.csv("stormdata.csv", header = T)
str(stormdata)
## '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 "","- 1 N Albion",..: 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 "","- .5 NNW",..: 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","$AC",..: 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/ 436774 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...

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

1.1 First, select the variables that are needed to answer this question.

healthdata <-  select(stormdata, EVTYPE, FATALITIES, INJURIES)

1.2 Get the sum fatalities and injuries for each events

sumfatal <- as.vector(tapply(healthdata$FATALITIES, healthdata$EVTYPE, sum))
suminjur <- as.vector(tapply(healthdata$INJURIES, healthdata$EVTYPE, sum))
events <- levels(healthdata$EVTYPE)
sumhealth <- data.frame(events, sumfatal, suminjur)
colnames(sumhealth) <- c("event", "fatalities","injuries")

1.3 arrange the dataframe in the desc order, get the top 10 events

fatality10 <- arrange(sumhealth, desc(fatalities))[1:10, 1:2]
injury10 <- arrange(sumhealth, desc(injuries))[1:10, c(1,3)]
topfatality <- fatality10 [1,1]
topinjury <- injury10 [1,1]

Question 2. Across the United States, which types of events have the greatest economic consequences?

2.1 First, select the variables that are needed to answer this question.

dmgdata <-  select(stormdata, EVTYPE, PROPDMG:CROPDMGEXP)

2.2 combine the PRODMG and PRODMGEXP, CROPDMG and CROPDMGEXP columns

levels(dmgdata$PROPDMGEXP)
##  [1] ""  "-" "?" "+" "0" "1" "2" "3" "4" "5" "6" "7" "8" "B" "h" "H" "K" "m" "M"
levels(dmgdata$CROPDMGEXP)
## [1] ""  "?" "0" "2" "B" "k" "K" "m" "M"
dmgdata <- mutate(dmgdata,PROPDMGEXP = as.character(PROPDMGEXP), CROPDMGEXP = as.character(CROPDMGEXP))
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == ""] <- 1
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "0"] <- 1
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "1"] <- 10
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "2"] <- 100
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "3"] <- 1000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "4"] <- 10000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "5"] <- 100000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "6"] <- 1000000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "7"] <- 10000000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "8"] <- 100000000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "B"] <- 1000000000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "h"] <- 100
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "H"] <- 100
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "K"] <- 1000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "m"] <- 1000000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "M"] <- 1000000
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "-"] <- 0
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "+"] <- 0
dmgdata$PROPDMGEXP[dmgdata$PROPDMGEXP == "?"] <- 0

dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == ""] <- 1
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "0"] <- 1
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "2"] <- 100
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "k"] <- 1000
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "K"] <- 1000
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "m"] <- 1000000
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "M"] <- 1000000
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "B"] <- 1000000000
dmgdata$CROPDMGEXP[dmgdata$CROPDMGEXP == "?"] <- 0

dmgdata1 <- mutate(dmgdata,PROPDMGEXP = as.numeric(PROPDMGEXP), CROPDMGEXP = as.numeric(CROPDMGEXP))
dmgdata2 <- mutate(dmgdata1, PROPDMG = PROPDMG*PROPDMGEXP)
dmgdata3 <- mutate(dmgdata2, CROPDMG = CROPDMG*CROPDMGEXP)

DMGDATA <- select(dmgdata3, EVTYPE, PROPDMG, CROPDMG)

2.3 Get the sum damage for each events

sumpropdmg <- as.vector(tapply(DMGDATA$PROPDMG, DMGDATA$EVTYPE, sum))
sumcropdmg <- as.vector(tapply(DMGDATA$CROPDMG, DMGDATA$EVTYPE, sum))
events <- levels(DMGDATA$EVTYPE)
DMGSUM <- data.frame(events, sumpropdmg, sumcropdmg)
colnames(DMGSUM) <- c("event", "propdmg","cropdmg")

2.4 arrange the dataframe in the desc order, get the top 10 events

propdmg10 <- arrange(DMGSUM, desc(propdmg))[1:10, 1:2]
cropdmg10 <- arrange(DMGSUM, desc(cropdmg))[1:10, c(1,3)]
toppropdmg <- propdmg10 [1,1]
topcropdmg <- cropdmg10 [1,1]

RESULTS

Harm to Public Health

  1. The top10 and top 1 harmful events with repect to fatalities is :
fatality10
##             event fatalities
## 1         TORNADO       5633
## 2  EXCESSIVE HEAT       1903
## 3     FLASH FLOOD        978
## 4            HEAT        937
## 5       LIGHTNING        816
## 6       TSTM WIND        504
## 7           FLOOD        470
## 8     RIP CURRENT        368
## 9       HIGH WIND        248
## 10      AVALANCHE        224
topfatality
## [1] TORNADO
## 985 Levels:    HIGH SURF ADVISORY  COASTAL FLOOD  FLASH FLOOD ... WND
  1. The top10 and top 1 harmful events with repect to injuries is :
injury10
##                event injuries
## 1            TORNADO    91346
## 2          TSTM WIND     6957
## 3              FLOOD     6789
## 4     EXCESSIVE HEAT     6525
## 5          LIGHTNING     5230
## 6               HEAT     2100
## 7          ICE STORM     1975
## 8        FLASH FLOOD     1777
## 9  THUNDERSTORM WIND     1488
## 10              HAIL     1361
topinjury
## [1] TORNADO
## 985 Levels:    HIGH SURF ADVISORY  COASTAL FLOOD  FLASH FLOOD ... WND
  1. Making the plots of the top 10 fatalities and top 10 injuries
par(mfrow=c(1,2),mar=c(10,3,3,2))
barplot(fatality10$fatalities, names.arg = fatality10$event, las = 2, ylab = "Fatalities", main = "Top 10 Fatalities Events")
barplot(injury10$injuries, names.arg = injury10$event, las = 2, ylab = "Injuries", main = "Top 10 Injuries Events")

Harm to Economics

  1. The top10 and top1 harmful events with repect to the property damage.
propdmg10
##                event      propdmg
## 1              FLOOD 144657709870
## 2  HURRICANE/TYPHOON  69305840000
## 3            TORNADO  56947381845
## 4        STORM SURGE  43323536000
## 5        FLASH FLOOD  16822678195
## 6               HAIL  15735270147
## 7          HURRICANE  11868319010
## 8     TROPICAL STORM   7703890550
## 9       WINTER STORM   6688497260
## 10         HIGH WIND   5270046260
toppropdmg
## [1] FLOOD
## 985 Levels:    HIGH SURF ADVISORY  COASTAL FLOOD  FLASH FLOOD ... WND
  1. The top10 and top1 harmful events with repect to the crop damage.
cropdmg10
##                event     cropdmg
## 1            DROUGHT 13972566000
## 2              FLOOD  5661968450
## 3        RIVER FLOOD  5029459000
## 4          ICE STORM  5022113500
## 5               HAIL  3025954473
## 6          HURRICANE  2741910000
## 7  HURRICANE/TYPHOON  2607872800
## 8        FLASH FLOOD  1421317100
## 9       EXTREME COLD  1292973000
## 10      FROST/FREEZE  1094086000
topcropdmg
## [1] DROUGHT
## 985 Levels:    HIGH SURF ADVISORY  COASTAL FLOOD  FLASH FLOOD ... WND
  1. Making the plots of the top 10 property damage and top 10 crop damage events
par(mfrow=c(1,2),mar=c(10,3,3,2))
barplot(propdmg10$propdmg, names.arg = propdmg10$event, las = 2, ylab = "Property Damage", main = "Top 10 Property Damege Events")
barplot(cropdmg10$cropdmg, names.arg = cropdmg10$event, las = 2, ylab = "Crop Damage", main = "Top 10 Crop Damage Evenets")

SUMMARY

  1. Across the United States, Tornados are the most harmful events with respect to population health, creating the largest number of fatalities and injuries.
  2. Across the United States, Floods have the greatest economic consequences with repect to property damage; Droughts have the greatest economic consequences with repect to crop damage.