Reproducible Research, Assignment: Course Project 2

Introduction

Storms 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. Storm Data is an official publication of the National Oceanic and Atmospheric Administration #Synopsis This Report involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. The objective of this report is to answer two 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 Processing

Loading Data

if (!file.exists("repdata_data_StormData.csv.bz2")) {
  file<-('https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2') 
download.file(file, destfile="repdata_data_StormData.csv.bz2")
}
  Storm.Data <- read.csv("repdata_data_StormData.csv.bz2")

As mentioned before, the objectives of this report is to analyze the event types which cause the worst health and economic consequences. Therefoer, we eliminate the irrelvant data such as the geographical location and timings. The new dataset is saved as “New.Storm”.

New.Storm <- Storm.Data[,c(8,23:28)]
str(New.Storm)
## '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 ...

Data Cleaning

As the output of “str” function show that the New.Storm table contains 7 variables 4 numeric (FATALITIES,INJURIES,PROPDMG and CROPDMG) and three Factor variables (EVTYPE,PROPDMGEXP,CROPDMGEXP). The NATIONAL WEATHER SERVICE INSTRUCTION 10-1605 documantation mentioned that both PROPDMGEXP (Property Damage) and CROPDMGEXP (Crop Damage) have only for 3 levels “K” for thousands, “M” for millions, and “B” for billions. Therefore, we will create new two variables to re-code the PROPDMGEXP and PROPDMGEXP as follows into PROPD and CROPD:

New.Storm$PROPD<- 0
New.Storm[which(New.Storm$PROPDMGEXP == "H"),]$PROPD <- 100
New.Storm[which(New.Storm$PROPDMGEXP == "h"),]$PROPD <- 100
New.Storm[which(New.Storm$PROPDMGEXP == "K"),]$PROPD <- 1000
New.Storm[which(New.Storm$PROPDMGEXP == "m"),]$PROPD <- 1000000
New.Storm[which(New.Storm$PROPDMGEXP == "M"),]$PROPD <- 1000000
New.Storm[which(New.Storm$PROPDMGEXP == "B"),]$PROPD <- 1000000000
table(New.Storm$PROPD)
## 
##      0    100   1000  1e+06  1e+09 
## 466248      7 424665  11337     40
New.Storm$CROPD<- 0
New.Storm[which(New.Storm$CROPDMGEXP == "K"),]$CROPD <- 1000
New.Storm[which(New.Storm$CROPDMGEXP == "k"),]$CROPD <- 1000
New.Storm[which(New.Storm$CROPDMGEXP == "m"),]$CROPD <- 1000000
New.Storm[which(New.Storm$CROPDMGEXP == "M"),]$CROPD <- 1000000
New.Storm[which(New.Storm$CROPDMGEXP == "B"),]$CROPD <- 1000000000
table(New.Storm$CROPD)
## 
##      0   1000  1e+06  1e+09 
## 618440 281853   1995      9

Results

Q1) Which types of events are most harmful with respect to population health, in US?

A) The Effect of Storm Event on Fatalities

To find this effect, We use barplot chart to show the top 15 storm event types that are causing most Fatalities:

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
Event.Group <- group_by(New.Storm, EVTYPE)

Q1.Fatalities <- summarise(Event.Group, Fatalities= sum(FATALITIES))
Storm.Health.Fatalities <- arrange(Q1.Fatalities, desc(Fatalities)) 
Top15.Fatalities <- head(Storm.Health.Fatalities,15)

New=barplot(Top15.Fatalities$Fatalities,names=Top15.Fatalities$EVTYPE, main="Top 15 Storm Events Most Harmful to Population Health, Fatalities", ylab="Fatalities" ,  xlab="Event Type" ,  col = "red",ylim=c(0,6000))
text(x=New, y=Top15.Fatalities$Fatalities, labels=round(Top15.Fatalities$Fatalities,0), pos=3, xpd=NA)
box()

B) The Effect of Storm Event on INJURIES

To find this effect, We use barplot chart to show the top 15 storm event types that are causing most Injuries:

library(dplyr)
 
Event.Group <- group_by(New.Storm, EVTYPE)
Q1.INJURIES <- summarise(Event.Group, Injuries= sum(INJURIES))
Storm.Health.INJURIES <- arrange(Q1.INJURIES, desc(Injuries)) 
Top15.Injuries <- head(Storm.Health.INJURIES,15)

New=barplot(Top15.Injuries$Injuries,names=Top15.Injuries$EVTYPE, main="Top 15 Storm Events Most Harmful to Population Health, Injuries", ylab="Injuries" ,  xlab="Event Type" ,  col = "green",ylim=c(0,100000))
text(x=New, y=Top15.Injuries$Injuries, labels=round(Top15.Injuries$Injuries,0), pos=3, xpd=NA)
box()

As the above two figures show the TORNADOs storm event have the most harmful on population health

Q2)Which types of events have the greatest economic consequences, in us?

To find this effect, We use barplot chart to show the top 15 storm event types that are causing the worst economic consequence:

library(dplyr)
Event.Group2 <- group_by(New.Storm, EVTYPE)

New.Storm$Eco <- (New.Storm$PROPDMG * New.Storm$PROPD) + (New.Storm$CROPDMG * New.Storm$CROPD)

Q2.Economy <- summarise(Event.Group2, Economic= sum(New.Storm$Eco))

Storm.Economy <- arrange(Q2.Economy, desc(Economic)) 

Top15.Economy<- head(Storm.Economy,15)


New=barplot( Top15.Economy$Economic/10^9,names=Top15.Economy$EVTYPE, main="Top 15 Storm Events have the Greatest Economic Consequences",  ylab="Economic Consequences" ,  xlab="Event Type" ,  col = "red",ylim=c(0,500))
text(x=New, Top15.Economy$Economic/10^9, labels=round(Top15.Economy$Economic/10^9,0), pos=3, xpd=NA)
box()

As the above figure shows the FLOOD storm event have the worst economic consequence.