The purpose of this report is to find out which types of weather events caused the greatest economical damage across the United States and which types were most phycally harmful to people across the nation. Storm Data, an official publication of the National Oceanic and Atmospheric Administration, documents “the occurrence of storms and other significant weather phenomena having sufficient intensity to cause loss of life, injuries, significant property damage, and/or disruption to commerce”. We obtained Storm Data from 1950 though November 2011 and created three different groups. The first group includes the top 10 events that caused most economical damage. The second group contains the top 10 events that caused most injuries and the third group causing most fatalities. Based on our analysis, we found the following; 1) the most harmful weather event based on both fatalities and injuries was, by far, the tornado, 2) the event that caused the greatest economical damage was the flood, 3) three events that were included in the top 5 lists on both injury and fatality groups were the tornado, excessive heat and lightning, and 4) the only event that showed up in the top 5 lists for all the categories was the tornado.
We read in a csv file containing Storm Data collected between January 1950 and November 2011. We then check to see how many rows there are in the dataset and see what the data look like in the first six rows.
stormData <- read.csv("repdata-data-StormData.csv.bz2")
dim(stormData)
## [1] 902297 37
head(stormData)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL
## 4 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL
## 5 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL
## 6 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL
## EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1 TORNADO 0 0
## 2 TORNADO 0 0
## 3 TORNADO 0 0
## 4 TORNADO 0 0
## 5 TORNADO 0 0
## 6 TORNADO 0 0
## COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1 NA 0 14.0 100 3 0 0
## 2 NA 0 2.0 150 2 0 0
## 3 NA 0 0.1 123 2 0 0
## 4 NA 0 0.0 100 2 0 0
## 5 NA 0 0.0 150 2 0 0
## 6 NA 0 1.5 177 2 0 0
## INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1 15 25.0 K 0
## 2 0 2.5 K 0
## 3 2 25.0 K 0
## 4 2 2.5 K 0
## 5 2 2.5 K 0
## 6 6 2.5 K 0
## LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1 3040 8812 3051 8806 1
## 2 3042 8755 0 0 2
## 3 3340 8742 0 0 3
## 4 3458 8626 0 0 4
## 5 3412 8642 0 0 5
## 6 3450 8748 0 0 6
Columns we are interested for this study are as follows: “EVTYPE”, “FATALITIES”, “INJURIES”, “PROPDMG”, “PROPDMGEXP”, “CROPDMG”, “CROPDMGEXP”. To see how many missing values are there in numeric fields, “FATALITIES”, “INJURIES”, “PROPDMG”, and “CROPDMG”, do the following.
stormDamageNumeric <- stormData[,23:25]
CROPDMG = stormData$CROPDMG
stormDamageNumeric <- cbind(stormDamageNumeric, CROPDMG)
summary(is.na(stormDamageNumeric))
## FATALITIES INJURIES PROPDMG CROPDMG
## Mode :logical Mode :logical Mode :logical Mode :logical
## FALSE:902297 FALSE:902297 FALSE:902297 FALSE:902297
## NA's :0 NA's :0 NA's :0 NA's :0
Based on the above analysis, we conclude that missing value is not a problem in this dataset.
The columns, “PROPDMGEXP” and “CROPDMGEXP” contain letters, “K”, “M” and “B” to represent 1000, 1000,000 and 1000,000,000. We have to convert these letters and calculate the actual damage in each observation.
library(dplyr)
stormDamage <- select(stormData, EVTYPE, FATALITIES:CROPDMGEXP) ##create a subset
PDE <- vector(mode = "numeric", length = 902297)
for (i in 1:902297) {
if (stormDamage$PROPDMGEXP[i] == "K") {PDE[i] = stormDamage$PROPDMG[i] * 1000}
else if (stormDamage$PROPDMGEXP[i] == "M") {PDE[i] = stormDamage$PROPDMG[i] * 1000000}
else if (stormDamage$PROPDMGEXP[i] == "B") {PDE[i] = stormDamage$PROPDMG[i] * 1000000000}
else {PDE[i] = stormDamage$PROPDMG[i]}
}
CDE <- vector(mode = "numeric", length = 902297)
total <- vector(mode = "numeric", length = 902297)
for (i in 1:902297) {
if (stormDamage$CROPDMGEXP[i] == "K") {CDE[i] = stormDamage$CROPDMG[i] * 1000}
else if (stormDamage$CROPDMGEXP[i] == "k") {CDE[i] = stormDamage$CROPDMG[i] * 1000}
else if (stormDamage$CROPDMGEXP[i] == "M") {CDE[i] = stormDamage$CROPDMG[i] * 1000000}
else if (stormDamage$CROPDMGEXP[i] == "B") {CDE[i] = stormDamage$CROPDMG[i] * 1000000000}
else {CDE[i] = stormDamage$CROPDMG[i]}
total[i] = PDE[i] + CDE[i]
}
stormDamage = cbind(stormDamage, PDE, CDE, total)
In order to find out which weather types are causing most economical damage, most injuries, and most fatalities separately, we create three groups as follows and look at only top 10 event types.
EVTYPES <- group_by(stormDamage, EVTYPE)
sumDamage <- summarise(EVTYPES, total=sum(total))
sumInjury <- summarise(EVTYPES, INJURIES=sum(INJURIES))
sumFatal <- summarise(EVTYPES, FATALITIES=sum(FATALITIES))
sumDamDesc <- sumDamage[rev(order(sumDamage$total)),]
sumInjDesc <- sumInjury[rev(order(sumInjury$INJURIES)),]
sumFatalDesc <- sumFatal[rev(order(sumFatal$FATALITIES)),]
sumDamDesc = sumDamDesc[1:10,]
sumDamDesc
## Source: local data frame [10 x 2]
##
## EVTYPE total
## <fctr> <dbl>
## 1 FLOOD 150319678257
## 2 HURRICANE/TYPHOON 71913712800
## 3 TORNADO 57340614060
## 4 STORM SURGE 43323541000
## 5 HAIL 18753321526
## 6 FLASH FLOOD 17562129167
## 7 DROUGHT 15018672000
## 8 HURRICANE 14610229010
## 9 RIVER FLOOD 10148404500
## 10 ICE STORM 8967041360
sumInjDesc = sumInjDesc[1:10,]
sumInjDesc
## Source: local data frame [10 x 2]
##
## EVTYPE INJURIES
## <fctr> <dbl>
## 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
sumFatalDesc = sumFatalDesc[1:10,]
sumFatalDesc
## Source: local data frame [10 x 2]
##
## EVTYPE FATALITIES
## <fctr> <dbl>
## 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
sumDamDesc$EVTYPE <- ordered(sumDamDesc$EVTYPE, levels=levels(sumDamDesc$EVTYPE)[unclass(sumDamDesc$EVTYPE)])
sumInjDesc$EVTYPE <- ordered(sumInjDesc$EVTYPE, levels=levels(sumInjDesc$EVTYPE)[unclass(sumInjDesc$EVTYPE)])
sumFatalDesc$EVTYPE <- ordered(sumFatalDesc$EVTYPE, levels=levels(sumFatalDesc$EVTYPE)[unclass(sumFatalDesc$EVTYPE)])
We plot top 10 weather events to visually understand the effects of each event in each category.
library(ggplot2)
EVTYPES <- group_by(stormDamage, EVTYPE)
sumDamage <- summarise(EVTYPES, total=sum(total))
sumInjury <- summarise(EVTYPES, INJURIES=sum(INJURIES))
sumFatal <- summarise(EVTYPES, FATALITIES=sum(FATALITIES))
sumDamDesc <- sumDamage[rev(order(sumDamage$total)),]
sumInjDesc <- sumInjury[rev(order(sumInjury$INJURIES)),]
sumFatalDesc <- sumFatal[rev(order(sumFatal$FATALITIES)),]
sumDamDesc = sumDamDesc[1:10,]
sumInjDesc = sumInjDesc[1:10,]
sumFatalDesc = sumFatalDesc[1:10,]
sumDamDesc$EVTYPE <- ordered(sumDamDesc$EVTYPE, levels=levels(sumDamDesc$EVTYPE)[unclass(sumDamDesc$EVTYPE)])
sumInjDesc$EVTYPE <- ordered(sumInjDesc$EVTYPE, levels=levels(sumInjDesc$EVTYPE)[unclass(sumInjDesc$EVTYPE)])
sumFatalDesc$EVTYPE <- ordered(sumFatalDesc$EVTYPE, levels=levels(sumFatalDesc$EVTYPE)[unclass(sumFatalDesc$EVTYPE)])
ggplot(data=sumDamDesc, aes(x=EVTYPE, y=total)) + geom_bar(fill = "steelblue", stat="identity") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title = "Economic Damage Caused by Various Weather Events", x = "Weather Event Type", y = "total damage in $")
ggplot(data=sumInjDesc, aes(x=EVTYPE, y=INJURIES)) + geom_bar(fill = "khaki1", stat="identity") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title = "Number of Injuries Caused by Various Weather Events", x = "Weather Event Type", y = "Number of Injuries")
ggplot(data=sumFatalDesc, aes(x=EVTYPE, y=FATALITIES)) + geom_bar(fill = "plum3", stat="identity") + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title = "Number of Fatalities Caused by Various Weather Events", x = "Weather Event Type", y = "Number of Fatalities")