This is a report that determine the storm events that are most harmful to population health and the greatest economic consequences. It is based on the NOAA Storm Database repdata_data_StormData.csv.bz2 with data from 1950 to 2011.
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
home<-"C:/users/samlt/Documents"
setwd(home)
storm<-read.csv("repdata_data_StormData.csv.bz2")
Definition of Function dmgEXP to convert the exponents PROPDMGEXP and CROPDMGEXP to the numeric multipliers for the corresponding numbers in PROPDMG and CROPDMG for Property and Crop Damages calculations. Sum of the two will be used as the total economical cost of damage. Conversions of PROPDMGEXP, CROPDMGEXP used are: b = 1e9,B=1e9,m=1e6,M =1e6,k=1e3,K=1e3,h=100,H=100,“+”=1,all other=0.
dmgEXP<- function(exp) {
L<-length(exp)
z<-rep(0,L)
for (i in 1:L)
{ z[i]<-switch((exp)[i],
b = 1000000000,
B=1000000000,
m = 1000000,
M = 1000000,
k=1000,
K=1000,
h=100,
H=100,
"+"=1,
0)
}
z
}
Select only the revelant variables for computation from storm and store them in Data File storm2. Calculate the cost for p (Prorperty Damages), c (Crop Damages) and t (Total Cost of Damages, ie p+c), these are named PROP,CROP,ECONDMG respectively and included in storm2 and saved in data file storm3
storm2<-select(storm,EVTYPE,BGN_DATE,END_DATE,FATALITIES,INJURIES,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP,REFNUM)
p<-as.numeric(dmgEXP(as.character(storm2$PROPDMGEXP)))*storm2$PROPDMG
c<-as.numeric(dmgEXP(as.character(storm2$CROPDMGEXP)))*storm2$CROPDMG
t<-p+c
storm3<-cbind(storm2,p,c,t)
names(storm3)<-c(names(storm2),"PROP","CROP","ECONDMG")
The maximum total cost of damage (ECONDMG) is summarised under different weather events EVTYPE. Top 12 weather events with maximum total cost (ECONDMG) are plotted as bar plot ## Top Casuality Events Plot Compute Casualties by summing up Fatalities and Injuries in data file storm3, sort them in descending order and plot the top 12 weather events that gives max casualties.
g<-group_by(storm3,EVTYPE)
pd<-summarize(g,maxpd=max(ECONDMG))
pd2<-arrange(pd,desc(maxpd))
pd2<-pd2[1:12,]
par(mfrow=c(1,1),mar=c(15,5,2,1))
barplot((pd2$maxpd/1200000000),names.arg=pd2$EVTYPE,ylim=c(1,120),font.main=1,main="Fig 1. Total Economic Cost (Property + Crop Damaged)\n NOAA storm database 1950-2011",ylab="Billions USD",log="y")
storm3$CASUALTIES<-storm3$FATALITIES+storm3$INJURIES
g<-group_by(storm3,EVTYPE)
cs<-summarize(g,maxpd=max(CASUALTIES))
cs2<-arrange(cs,desc(maxpd))
cs2<-cs2[1:12,]
par(mfrow=c(1,1),mar=c(11,5,2,1))
barplot(cs2$maxpd,names.arg=cs2$EVTYPE,main="Fig 2. Casualties (Death + Injured)\n NOAA storm database 1950-2011",font.main=4,ylim=c(1,5000),ylab="Number of Casualties",log="y")
The list of Property Damage and Casualties for the top 12 Weather Events are calculated below. Their plots are as shown in Fig 1 and Fig 2.
dev.off
## function (which = dev.cur())
## {
## if (which == 1)
## stop("cannot shut down device 1 (the null device)")
## .External(C_devoff, as.integer(which))
## dev.cur()
## }
## <bytecode: 0x0eea9f04>
## <environment: namespace:grDevices>
names(pd2)<-c("Weather Events","Property Damage (USD)")
print(head(pd2,12))
## # A tibble: 12 x 2
## `Weather Events` `Property Damage (USD)`
## <fct> <dbl>
## 1 FLOOD 115032500000.
## 2 STORM SURGE 31300000000.
## 3 HURRICANE/TYPHOON 16930000000.
## 4 RIVER FLOOD 10000000000.
## 5 TROPICAL STORM 5150000000.
## 6 ICE STORM 5000500000.
## 7 WINTER STORM 5000000000.
## 8 STORM SURGE/TIDE 4000000000.
## 9 HURRICANE 3500000000.
## 10 TORNADO 2800000000.
## 11 HEAVY RAIN/SEVERE WEATHER 2500000000.
## 12 HURRICANE OPAL 2105000000.
names(cs2)<-c("Weather Events","Casualties")
print(head(cs2,12))
## # A tibble: 12 x 2
## `Weather Events` Casualties
## <fct> <dbl>
## 1 TORNADO 1742.
## 2 ICE STORM 1569.
## 3 FLOOD 802.
## 4 HURRICANE/TYPHOON 787.
## 5 HEAT 583.
## 6 EXCESSIVE HEAT 521.
## 7 BLIZZARD 390.
## 8 HEAT WAVE 202.
## 9 TROPICAL STORM 201.
## 10 HEAVY SNOW 185.
## 11 WINTER STORM 170.
## 12 TSUNAMI 161.