Title

Effect of different weather conditions with respect to population health and economic consequences.

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.The goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events. - Which types of events are most harmful with respect to population health across United States. - Which types of events have the greatest economic consequences across United States.

Data Processing

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
setwd("~/Downloads/RepData_PeerAssessment2")
if(!file.exists('StormData.csv.bz2')){
        url <- "http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
        fileName <- file.path(getwd(),'StormData.csv.bz2')
        download.file(url,destfile=fileName)
}

stormData <- read.csv(bzfile('StormData.csv.bz2'), header = TRUE)
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 ""," 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 ...

we are interested in 7 variables for our analysis to answer the two questions.

We are going to subset our data to make the process faster

stormData <- select(stormData, EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
str(stormData)
## 'data.frame':    902297 obs. of  7 variables:
##  $ 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 ...

which Severe Weather Events caused the most fatalities?

The following shows the top 7 severe weather events that caused the most fatalities.

fatality.data <- group_by(stormData, EVTYPE)
fatality.data7 <- summarise(fatality.data, total = sum(FATALITIES)) %>% arrange(desc(total)) %>% top_n(7)
## Selecting by total
fatality.data7 
## Source: local data frame [7 x 2]
## 
##           EVTYPE total
##           (fctr) (dbl)
## 1        TORNADO  5633
## 2 EXCESSIVE HEAT  1903
## 3    FLASH FLOOD   978
## 4           HEAT   937
## 5      LIGHTNING   816
## 6      TSTM WIND   504
## 7          FLOOD   470
barplot(fatality.data7$total, 
        names = fatality.data7$EVTYPE,
        xlab = "Event Type",las=2,cex.names=0.5,
        ylab = "Total Deaths",
        main = "Top 7  Weather Events showing Fatality",col = "red"
        )

Tornado caused the most fatalities.

Which Severe Weather Events caused the most injuries?

The following shows the top 7 severe weather events that caused the most injuries.

injury.data <- group_by(stormData, EVTYPE)
injury.data7 <- summarise(injury.data, total = sum(INJURIES)) %>% arrange(desc(total)) %>% top_n(7)
## Selecting by total
injury.data7   
## Source: local data frame [7 x 2]
## 
##           EVTYPE total
##           (fctr) (dbl)
## 1        TORNADO 91346
## 2      TSTM WIND  6957
## 3          FLOOD  6789
## 4 EXCESSIVE HEAT  6525
## 5      LIGHTNING  5230
## 6           HEAT  2100
## 7      ICE STORM  1975
barplot(injury.data7$total, 
        names = injury.data7$EVTYPE,
        xlab = "Event Type",las=2,cex.names=0.5,
        ylab = "Total Injury",
        main = "Top 7  Weather Events showing Injury",col = "blue"
        )

Tornado caused the most Injuries.

Which types of events have the greatest economic consequences?

Economic impact is measured by total of property damages and crop damages. The factor variablies PROPDMGEXP and CROPDMGEXP have the following levels.

unique(stormData$PROPDMGEXP)
##  [1] K M   B m + 0 5 6 ? 4 2 3 h 7 H - 1 8
## Levels:  - ? + 0 1 2 3 4 5 6 7 8 B h H K m M
unique(stormData$CROPDMGEXP)
## [1]   M K m B ? 0 k 2
## Levels:  ? 0 2 B k K m M

We are going to convert the property damage and crop damage data into comparable numerical forms according to the meaning of units described in the code book, Storm Events. Both PROPDMGEXP and CROPDMGEXP columns record a multiplier for each observation where we have Hundred (H), Thousand (K), *** Million (M)*** and Billion (B).

stormData$PROPDMGEXP <- as.character(stormData$PROPDMGEXP)
stormData$PROPDMGEXP = gsub("\\-|\\+|\\?","0",stormData$PROPDMGEXP)
stormData$PROPDMGEXP = gsub("B|b", "9", stormData$PROPDMGEXP)
stormData$PROPDMGEXP = gsub("M|m", "6", stormData$PROPDMGEXP)
stormData$PROPDMGEXP = gsub("K|k", "3", stormData$PROPDMGEXP)
stormData$PROPDMGEXP = gsub("H|h", "2", stormData$PROPDMGEXP)
stormData$PROPDMGEXP <- as.numeric(stormData$PROPDMGEXP)
stormData$PROPDMGEXP[is.na(stormData$PROPDMGEXP)] = 0
stormData$property.damage.data<- stormData$PROPDMG * 10^stormData$PROPDMGEXP
property.damage <- aggregate(property.damage.data~EVTYPE, data=stormData, sum)
property.damage<- property.damage[order(-property.damage$property.damage.data),]
property.damage7<-property.damage[1:7,]
property.damage7
##                EVTYPE property.damage.data
## 170             FLOOD         144657709807
## 411 HURRICANE/TYPHOON          69305840000
## 834           TORNADO          56947380676
## 670       STORM SURGE          43323536000
## 153       FLASH FLOOD          16822673978
## 244              HAIL          15735267513
## 402         HURRICANE          11868319010
stormData$CROPDMGEXP <- as.character(stormData$CROPDMGEXP)
stormData$CROPDMGEXP = gsub("\\-|\\+|\\?","0",stormData$CROPDMGEXP)
stormData$CROPDMGEXP = gsub("B|b", "9", stormData$CROPDMGEXP)
stormData$CROPDMGEXP = gsub("M|m", "6", stormData$CROPDMGEXP)
stormData$CROPDMGEXP = gsub("K|k", "3", stormData$CROPDMGEXP)
stormData$CROPDMGEXP = gsub("H|h", "2", stormData$CROPDMGEXP)
stormData$CROPDMGEXP <- as.numeric(stormData$CROPDMGEXP)
stormData$CROPDMGEXP[is.na(stormData$CROPDMGEXP)] = 0
stormData$crop.damage.data<- stormData$CROPDMG * 10^stormData$CROPDMGEXP
crop.damage <- aggregate(crop.damage.data~EVTYPE, data=stormData, sum)
crop.damage<- crop.damage[order(-crop.damage$crop.damage.data),]
crop.damage7<-crop.damage[1:7,]
crop.damage7
##                EVTYPE crop.damage.data
## 95            DROUGHT      13972566000
## 170             FLOOD       5661968450
## 590       RIVER FLOOD       5029459000
## 427         ICE STORM       5022113500
## 244              HAIL       3025954473
## 402         HURRICANE       2741910000
## 411 HURRICANE/TYPHOON       2607872800
total.damage <- aggregate(property.damage.data+ crop.damage.data~EVTYPE, data=stormData, sum)
names(total.damage)[2] <- "total"
total.damage7 <- arrange(total.damage, desc(total)) %>% top_n(7)
## Selecting by total
total.damage7
##              EVTYPE        total
## 1             FLOOD 150319678257
## 2 HURRICANE/TYPHOON  71913712800
## 3           TORNADO  57362333946
## 4       STORM SURGE  43323541000
## 5              HAIL  18761221986
## 6       FLASH FLOOD  18243991078
## 7           DROUGHT  15018672000
barplot(total.damage7$total, 
        names = total.damage7$EVTYPE,
        xlab = "Event Type",las=2,cex.names=0.5,
        ylab = "Total Loss of Economy",
        main = "Top 7  Weather Events showing Economy Effect",col = "darkgreen"
        )

- This analysis shows FLOOD caused the most property damage. DROUGHT caused the most crop damange. - FLOOD caused the most total damage.

Result

After analyzing the data we conclude following results: - TORNADO caused the most fatalities. - TORNADO caused the most Injuries. - FLOOD caused the most property damage. - DROUGHT caused the most crop damange. - FLOOD caused the most economic impact.