Synopsis

The goal of of this exercsise is to quantify both the physical (in the form of injuries and fatalities) and economical (in the form of Property and Crop damage) impact of the storm events. In order to best present these data in usable format I have explored the frequency of each event type and the number of occurances per event by the following 4 columns: Injuries, Fatalities, Crop Damage, and Property Damage. The former two columns apply to the physical impact each storm event took, while the latter two columns apply to the economic impact. The results listed are two plots showing the worst physical or economic offenders in terms of the number of times each occured per event type. It is in this way we can visually compare each.

Data Processing

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

As you can see from the below. I first massaged the data into injuries and fatalities by event type. Summarizing this data set allowed me to pick a point at which I was going to truncate - anything beyond a dozen or so observations would be difficult to see when plotted. Using a mean measurement of 200 fatalities and 3000 injuries But I also wanted to see which event (of the 12 left) was the worst on a ‘Per Occurance’ basis. To do so we simply appended the event frequency and did a simple mathmatical operation to create two new columns of data.

library(dplyr)
library(plyr)
library(ggplot2)
Storm_Harm<-ddply(StormData, .(EVTYPE), summarize, Injuries=sum(INJURIES), Fatalities = sum(FATALITIES))
Fatalities_Sort<-Storm_Harm[order(-Storm_Harm$Fatalities, -Storm_Harm$Injuries),]
Injury_Sort<-Storm_Harm[order(-Storm_Harm$Injuries, -Storm_Harm$Fatalities),]
Storm_Harm_Trunc<-Storm_Harm[Storm_Harm$Injuries>2000 | Storm_Harm$Fatalities>200,]
colnames(Storm_Harm_Trunc)[1]<-"Event_Type"
Event_Frequency<-data.frame(count(StormData$EVTYPE))
colnames(Event_Frequency)[1]<-"Event_Type"
Storm_Harm_Trunc<-merge(Storm_Harm_Trunc,Event_Frequency,by="Event_Type")
Storm_Harm_Trunc$Fatality_Per_Event<-Storm_Harm_Trunc$Fatalities / Storm_Harm_Trunc$freq
Storm_Harm_Trunc$Injury_Per_Event<-Storm_Harm_Trunc$Injuries / Storm_Harm_Trunc$freq
Storm_Harm_Trunc<-Storm_Harm_Trunc[order(-Storm_Harm_Trunc$Fatality_Per_Event),]

In order to process the effect of the Economical damage we will need to calculate and merge the Exponent columns for both Property and Crop damage. First I subset the original data set into just the columns desired, then converted the myriad exponent values into numbers, and finally performed the product operation to get the total crop or property damage.

myvars<-c("EVTYPE","PROPDMG","PROPDMGEXP","CROPDMG","CROPDMGEXP")
Storm_Damage<-StormData[,myvars]

Storm_Damage$PROPDMGEXP<- gsub ("^$",1,Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMGEXP<- gsub ("h|H|2",1e2,Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMGEXP<- gsub ("k|K|3",1e3,Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMGEXP<- gsub ("4",1e4,Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMGEXP<- gsub ("5",1e5,Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMGEXP<- gsub ("m|M|6",1e6,Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMGEXP<- gsub ("b|B|9",1e9,Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMGEXP<- gsub ("-|+|?|0",1e3,Storm_Damage$PROPDMGEXP)

Storm_Damage$PROPDMGEXP<-as.numeric(Storm_Damage$PROPDMGEXP)
Storm_Damage$PROPDMG <-Storm_Damage$PROPDMGEXP * Storm_Damage$PROPDMG

Storm_Damage$CROPDMGEXP<- gsub ("^$",1,Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMGEXP<- gsub ("h|H|2",1e2,Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMGEXP<- gsub ("k|K|3",1e3,Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMGEXP<- gsub ("4",1e4,Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMGEXP<- gsub ("5",1e5,Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMGEXP<- gsub ("m|M|6",1e6,Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMGEXP<- gsub ("b|B|9",1e9,Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMGEXP<- gsub ("-|+|?|0",1e3,Storm_Damage$CROPDMGEXP)

Storm_Damage$CROPDMGEXP<-as.numeric(Storm_Damage$CROPDMGEXP)
Storm_Damage$CROPDMG <-Storm_Damage$CROPDMGEXP * Storm_Damage$CROPDMG

Storm_Damage<-ddply(Storm_Damage, .(EVTYPE), summarize, Property_Damage=sum(PROPDMG), Crop_Damage = sum(CROPDMG))

Property_Damage_Sort<-Storm_Damage[order(-Storm_Damage$Property_Damage, -Storm_Damage$Crop_Damage),]
Crop_Damage_Sort<-Storm_Damage[order(-Storm_Damage$Crop_Damage, -Storm_Damage$Property_Damage),]
Storm_Damage_Trunc<-Storm_Damage[Storm_Damage$Property_Damage>1e19 | Storm_Damage$Crop_Damage>5e18,]
Storm_Damage_Trunc<-na.omit(Storm_Damage_Trunc)
colnames(Storm_Damage_Trunc)[1]<-"Event_Type"

Results

What events have caused the most personal damage?

library(reshape2)
SHT_Melt_Sum<-melt(Storm_Harm_Trunc[,c('Event_Type', 'Injuries','Fatalities')],id.vars=1)
ggplot(SHT_Melt_Sum, aes(x = Event_Type, y = value)) + geom_bar(aes(fill=variable),position = "dodge", stat="identity")+ theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + ggtitle("Worst Fatalities & Injuries in Totality") + labs(x="Event Type", y="Total Fatalities or Injury by Event Occurance")+ facet_wrap(~variable, ncol=1, scales="free_y")

What events caused the most personal damage per occcurance?

library(reshape2)
SHT_Melt_Freq<-melt(Storm_Harm_Trunc[,c('Event_Type', 'Injury_Per_Event','Fatality_Per_Event')],id.vars=1)
ggplot(SHT_Melt_Freq, aes(x = Event_Type, y = value)) + geom_bar(aes(fill=variable),position = "dodge", stat="identity")+ theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + ggtitle("Worst Fatalities & Injuries Per Event Occurance") + labs(x="Event Type", y="Fatalities or Injury Per Event Occurance")+ facet_wrap(~variable, ncol=1, scales="free_y")

What events have caused the most property damage?

library(reshape2)
SDT_Melt_Sum<-melt(Storm_Damage_Trunc[,c('Event_Type', 'Property_Damage','Crop_Damage')],id.vars=1)
ggplot(SDT_Melt_Sum, aes(x = Event_Type, y = value)) + geom_bar(aes(fill=variable),position = "dodge", stat="identity")+ theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)) + ggtitle("Worst Property and Crop Damage in Totality") + labs(x="Event Type", y="Total Worst Property or Crop Damage by Event Occurance")+ facet_wrap(~variable, ncol=1, scales="free_y")