| Title: “StormData Analysis using NOAA Data to analyse about severe weather Events |
| Author: “Suganthi M” |
| Date: “January 15, 2017” |
This project involves analysis of the stormdata from 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.The events in the database start in the year 1950 and end in November 2011.
The analysis involves fetching the data from NOAA, processing it ,cleaning it and computing the Events that cause the most harm impacts to the population with respect to their health and also the Events that causes the most economic consequences.From the Analysis we determine that Tornado causes the most fatalties and Injuries while Flood and Drought causes the most ecnomic damages.
The Data is downloaded from here and placed in the working directory.
library(ggplot2)
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(knitr)
library(reshape2)
library(gridExtra)
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
stormdata<-read.csv("repdataFdataStormData.csv.bz2")
Once the data is loaded in R, lets look at the data set
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/ 436781 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 ...
The analysis requires us to find answers for the following two questions:
Across the United States, which types of events (as indicated in the EVTYPE variable) are
most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
Fatalities and Injuries are the columns that provides the data pertaining to the population health.
First summarize the data Fatalities based on Event type
stormFatalities<-aggregate(FATALITIES~EVTYPE,stormdata, sum)
Arrange the dataset in descending order to find the most impact
stormFatalities<-arrange(stormFatalities,desc(FATALITIES))
The total observations are
dim(stormFatalities)
## [1] 985 2
Fetch the top 10 events
stormtopFatalities<-stormFatalities[1:10,]
Lets take a look at the top 10 events to health
stormtopFatalities
## EVTYPE 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
We need to do the same steps to calculate the Injuries. Summarize Injuries by event type
stormInjuries<-aggregate(INJURIES~EVTYPE,stormdata, sum)
Sort the Injuries data in Descending order
stormInjuries<-arrange(stormInjuries,desc(INJURIES))
Pick the Top 10
stormtopInjuries<-stormInjuries[1:10,]
Lets look at the data
stormtopInjuries
## EVTYPE 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
The second part of the assignment is to see which events causes the greatest economic consequnces. To Analyse this, we need to look at the Property Damages and crop damages.
names(stormdata)
## [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"
From the above, we notice that there are four columns related to Damages in the data set–> PROPDMG,PROPDMGEXP,CROPDMG and CROPDMGEXP
In order to calculate the damages,we need to convert PROPDMG and CROPDMG based on the exponent values represented in columns PROPDMGEXP and CROPDMGEXP respectively,
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
Values B means Billion(100000000), M - Million(1000000) , K- Thousands(1000), numbers 1 to 8 denotes the number of zeroes to be added after 1 .
The transformation for property damages based on the exponent would be as below:
stormdata[stormdata$PROPDMGEXP == "K"|stormdata$PROPDMGEXP == "3", ]$PROPDMG<- stormdata[stormdata$PROPDMGEXP == "K"|stormdata$PROPDMGEXP == "3", ]$PROPDMG*1000
stormdata[stormdata$PROPDMGEXP == "M"|stormdata$PROPDMGEXP == "m" |stormdata$PROPDMGEXP == "6", ]$PROPDMG<- stormdata[stormdata$PROPDMGEXP == "M"|stormdata$PROPDMGEXP == "m"|stormdata$PROPDMGEXP == "6", ]$PROPDMG*1000000
stormdata[stormdata$PROPDMGEXP == "B", ]$PROPDMG<-stormdata[stormdata$PROPDMGEXP == "B",]$PROPDMG*1000000000
stormdata[stormdata$PROPDMGEXP == "8", ]$PROPDMG<-stormdata[stormdata$PROPDMGEXP == "8",]$PROPDMG*100000000
stormdata[stormdata$PROPDMGEXP == "7", ]$PROPDMG<-stormdata[stormdata$PROPDMGEXP == "7",]$PROPDMG*10000000
stormdata[stormdata$PROPDMGEXP == "5", ]$PROPDMG<- stormdata[stormdata$PROPDMGEXP == "5",]$PROPDMG*100000
stormdata[stormdata$PROPDMGEXP == "4", ]$PROPDMG<- stormdata[stormdata$PROPDMGEXP == "4",]$PROPDMG*10000
stormdata[stormdata$PROPDMGEXP == "2", ]$PROPDMG<- stormdata[stormdata$PROPDMGEXP == "2",]$PROPDMG*100
stormdata[stormdata$PROPDMGEXP == "1", ]$PROPDMG<- stormdata[stormdata$PROPDMGEXP == "1",]$PROPDMG*10
Lets take a look at Crop damages exponent
unique(stormdata$CROPDMGEXP)
## [1] M K m B ? 0 k 2
## Levels: ? 0 2 B k K m M
Apply the exponent convertion on crop damages, the transformation would be as below
stormdata[stormdata$CROPDMGEXP == "B",]$CROPDMG<- stormdata[stormdata$CROPDMGEXP == "B",]$CROPDMG*1000000000
stormdata[stormdata$CROPDMGEXP == "K"|stormdata$CROPDMGEXP == "k",]$CROPDMG<- stormdata[stormdata$CROPDMGEXP == "K"|stormdata$CROPDMGEXP == "k",]$CROPDMG*1000
stormdata[stormdata$CROPDMGEXP == "M"|stormdata$CROPDMGEXP == "m",]$CROPDMG<- stormdata[stormdata$CROPDMGEXP == "M"|stormdata$CROPDMGEXP == "m",]$CROPDMG*1000000
stormdata[stormdata$PROPDMGEXP == "2", ]$PROPDMG<- stormdata[stormdata$PROPDMGEXP =="2",]$PROPDMG*100
Lets Summarize the Property Damages by Event types
propdamages<-aggregate(PROPDMG~EVTYPE,stormdata, sum)
Sort it by the most damaged
propdamages<-arrange(propdamages, desc(PROPDMG))
Pick the top 10 events that cause the most damages
propdamagestop <- propdamages[1:10,]
propdamagestop
## EVTYPE PROPDMG
## 1 FLOOD 144657709807
## 2 HURRICANE/TYPHOON 69305840000
## 3 TORNADO 56947380677
## 4 STORM SURGE 43323536000
## 5 FLASH FLOOD 16822673979
## 6 HAIL 15735267018
## 7 HURRICANE 11868319010
## 8 TROPICAL STORM 7703890550
## 9 WINTER STORM 6688497251
## 10 HIGH WIND 5270046295
Lets Summarize the Crop damages by Event types
cropdamages<-aggregate(CROPDMG~EVTYPE,stormdata, sum)
Sort it by the most damaged
cropdamages<-arrange(cropdamages, desc(CROPDMG))
Pick the top 10 events that cause the most damages
cropdamagestop<-cropdamages[1:10,]
cropdamagestop
## EVTYPE 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
Fatalitiesplot<-ggplot(stormtopFatalities, aes(x=reorder(EVTYPE,-FATALITIES), y=FATALITIES/1000,fill=FATALITIES,label = round(FATALITIES/1000,2 )))+
geom_bar(stat='identity')+
xlab("Event Type") +
ylab("Fatalities in Thousands") +
theme(axis.text.x = element_text(size=7,angle=45, vjust=1, hjust=1))+
guides(fill=FALSE)+
geom_label (aes(fill = FATALITIES), size=3,colour = "white", fontface = "bold")
Injuriesplot<-ggplot(stormtopInjuries,aes(reorder(EVTYPE,-INJURIES),INJURIES/1000, fill=INJURIES,label = round(INJURIES/1000,2 )))+
geom_bar(stat='identity')+ xlab("Event Type") +
ylab("Injuries In Thousands") +
theme(axis.text.x = element_text(size=7,angle=45, vjust=1, hjust=1))+
guides(fill=FALSE)+
geom_label (aes(fill = INJURIES), size=3,colour = "white", fontface = "bold")
Arrange the plots
grid.arrange(Fatalitiesplot,Injuriesplot,ncol=2, top="Top Harmful Events with respect to population health in Thousands")
From the Graph it shows that Tornado is the most harmful event that causes the most impacts with respect to the population Health
propdamageplot<-ggplot(propdamagestop, aes(x=reorder(EVTYPE,-PROPDMG), y=PROPDMG/1000000000,fill=PROPDMG ,label = round(PROPDMG/1000000000,2 )))+
geom_bar(stat='identity')+
xlab("Event Type") +
ylab("Property Damages in Billions") +
theme(axis.text.x = element_text(size=7,angle=45, vjust=1, hjust=1))+
guides(fill=FALSE)+
geom_label (aes(fill = PROPDMG), size=3,colour = "white", fontface = "bold")
cropdamageplot<-ggplot(cropdamagestop,aes(reorder(EVTYPE,-CROPDMG),CROPDMG/1000000000, fill=CROPDMG,label = round(CROPDMG/1000000000,2 )))+
geom_bar(stat='identity')+ xlab("Event Type") +
ylab("Crop Damages in Billions") +
theme(axis.text.x = element_text(size=7,angle=45, vjust=1, hjust=1))+
guides(fill=FALSE)+
geom_label (aes(fill = CROPDMG), size=3,colour = "white", fontface = "bold")
Arrange the plots
grid.arrange(propdamageplot,cropdamageplot,ncol=2, top=" Top Economic Consequences by Event Types in Billions")
From the graph it is understood that Flood causes the most Property Damages while Drought causes the most Crop Damages.