Project Title : Estimating harmful weather impacts of NOAA data

Synopsis:

This project explores the US National Oceanic and Atmospheric Administration’s storm data base and estimates the fatalities, injuries and property damage of severe weather.

Data Downloading and Data Processing:

if(!file.exists("StormData.csv.bz2"))
{
fileUrl<-"https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
 
download.file(fileUrl, destfile="StormData.csv.bz2", method="curl")

}

stormData<-read.csv("StormData.csv.bz2")

Loading the required libraries

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
library(ggplot2)

Harmful events that has an impact on population health

  ## Select and group the required fields to estimate fatalities 

stormFatalities<-stormData %>% select(EVTYPE, FATALITIES) %>% group_by(EVTYPE)

stormFatalities<- stormFatalities %>% summarise(totalFatalities=sum(FATALITIES)) %>% arrange(-totalFatalities)
## `summarise()` ungrouping output (override with `.groups` argument)
 ## Select and group the required fields to estimate Injuries

stormInjuries<-stormData %>% select(EVTYPE, INJURIES) %>% group_by(EVTYPE)

stormInjuries<- stormInjuries %>% summarise(totalInjuries=sum(INJURIES)) %>% arrange(-totalInjuries)
## `summarise()` ungrouping output (override with `.groups` argument)

Events that have the greatest economic consequences

Sorting out property data

propertyData<- sort(unique(as.character(stormData$PROPDMGEXP)))

print(propertyData)
##  [1] ""  "-" "?" "+" "0" "1" "2" "3" "4" "5" "6" "7" "8" "B" "h" "H" "K" "m" "M"

Sorting out crop data

cropData<-sort(unique(as.character(stormData$CROPDMGEXP)))

print(cropData)
## [1] ""  "?" "0" "2" "B" "k" "K" "m" "M"

Data Transformation

Data in PROPDMGEXP and CROPDMGEXP is represented as exponents to interpret the numeric values for the damage.

According to data, ‘H’ is for hundred dollars, ‘K’ is for thousand dollars, ‘M’ is for million dollars, ‘B’ is for billion dollars;

Assume that the special symbols ’‘,’+‘,’?’ represents zero dollars.

Extract the required variables to estimate the economic impact

requiredFields<- stormData %>% select(EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)


propertyValues<-c(0, 0, 0, 10^0, 10^1, 10^1, 10^1, 10^1, 10^1, 10^1, 10^1, 10^1, 10^1, 10^9, 10^2, 10^2, 10^3, 10^6, 10^6)

propertyExp<-data.frame(propertyData, propertyValues)

cropValues<-c(0, 0, 0, 10^2, 10^9, 10^3, 10^3, 10^6, 10^6)

cropExp<-data.frame(cropData, cropValues)

Match the expenses data to numeric values

propertyDamage<-propertyExp$propertyValues[ match (requiredFields$PROPDMGEXP, propertyExp$propertyData)]

cropDamage<-cropExp$cropValues[ match(requiredFields$CROPDMGEXP, cropExp$cropData)]

calculate the total damage expenses

requiredFields<- requiredFields %>% mutate(PROPDMG=PROPDMG*propertyDamage)
requiredFields<- requiredFields %>% mutate(CROPDMG=CROPDMG*cropDamage)
requiredFields<-requiredFields %>% mutate(TotalDamage=PROPDMG+CROPDMG)


economicDamage<- requiredFields %>% group_by(EVTYPE) 

economicDamage<-economicDamage %>% summarise(TotalDamage=sum(TotalDamage)) %>% arrange(-TotalDamage)
## `summarise()` ungrouping output (override with `.groups` argument)

RESULTS

Showing the impact of Public Health by graphical representation

Creating graph for the Fatalities

g1 <- ggplot(stormFatalities[1:15,],
 aes(x=totalFatalities, y=reorder(EVTYPE, -totalFatalities)))

##Setting shape and colors for the plot

 g1<-g1+geom_bar(stat="identity", color="black", fill="magenta") +
 theme(axis.text.x = element_text(angle=90, vjust=0.5, hjust=1))
 
##Setting titles for the plot

 g1<-g1+ggtitle("Frequent Weather Events result in Fatalities") +
 labs(y="Weather Events", x="Fatalities")

 print(g1)

Creating graph for the Injuries

g2<-ggplot(stormInjuries[1:15,],
  aes(x=totalInjuries, y=reorder(EVTYPE, -totalInjuries)))

## Setting shape and colors for the plot

g2<-g2+geom_bar(stat="identity", color="black", fill="green") +
    theme(axis.text.x=element_text(angle=90, vjust=0.5, hjust=1))

## Setting titles for the plot

g2<-g2+ggtitle("Frequent Weather events result in Injuries")+
    labs(y="Weather Events", x="Injuries")

print(g2)

Conclusion:

According to the above graph, weather event “Tornado” impacts extremely on public health, results in huge number of fatalities and injuries.

Creating graph for the economic impact

g3<-ggplot(economicDamage[1:15,],
 aes(x=TotalDamage, y=reorder(EVTYPE, -TotalDamage)))

##Setting shape and colors for the plot

g3<-g3+geom_bar(stat="identity", color="black", fill="blue")+
    theme(axis.text.x=element_text(angle=90, vjust=0.5, hjust=1))

##Setting titles for the plot

g3<-g3+ggtitle("Frequent weather events result in economic impact")+
     labs(x= "Economic impact in Dollars", y="Weather events")
    
print(g3)

Conclusion:

According to the above graph, weather event “Flood” impacts on property and results in greatest economic consequences