Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. Many severe events can result in fatalities, injuries, and property damage, and preventing such outcomes to the extent possible is a key concern.
This project involves exploring 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 data for this assignment come in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size. You can download the file from the course web site.
More documentation can be found here and here
The events in the database start in the year 1950 and end in November 2011. In the earlier years of the database there are generally fewer events recorded, most likely due to a lack of good records. More recent years should be considered more complete.
We shall download and read the file from the site repository.
if (!"StormData.csv.bz2" %in% dir("./")) {
print("Downloading file, please wait....")
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2","datafile.csv.bz2")
}
if(!'StormData' %in% ls()){
StormData <- read.csv("StormData.csv.bz2", header = TRUE, sep = ",")
}
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"
The data contains 902297 observations and 37 variables. The questions regarding this assignment regards the economic and human and economic consequences. We shall therefore only require the following variables to answer these question. They reduce the dimensions of the data for us:
# New dataframe for manipulation:
conseReal <- StormData[, c(8,23:28)]
We can now do some data processing on the new dataframe
# Transform the exponentials that read "-", "+" and "?" to read "0" exponential.
rm <- c("B", "h", "H", "K", "m", "M")
conseReal$PROPDMGEXP <- ifelse(conseReal$PROPDMGEXP %in% rm, as.character(conseReal$PROPDMGEXP), "NONE")
conseReal$CROPDMGEXP <- ifelse(conseReal$CROPDMGEXP %in% rm, as.character(conseReal$CROPDMGEXP), "NONE")
# We shall multiply the exponential colum with the damage column
conseReal$PROPDMG <- conseReal$PROPDMG * (10^9 * (conseReal$PROPDMGEXP == "B") +
10^6 *(conseReal$PROPDMGEXP %in% c("m", "M")) +
10^3 * (conseReal$PROPDMGEXP %in% c("k", "K")) +
100 * (conseReal$PROPDMGEXP %in% c("h", "H")))
conseReal$CROPDMG <- conseReal$CROPDMG * (10^9 * (conseReal$CROPDMGEXP == "B") + 10^6 *(conseReal$CROPDMGEXP %in% c("m", "M")) + 10^3 * (conseReal$CROPDMGEXP %in% c("k", "K")) + 100 * (conseReal$CROPDMGEXP %in% c("h", "H")))
# we then combine the tow columns with total damage costs
conseReal$PROPandCROP <- conseReal$PROPDMG + conseReal$CROPDMG
# Combine the fatalities and the injuries columns
conseReal$FandI <- conseReal$FATALITIES + conseReal$INJURIES
DeathAndInjuries <- aggregate(FandI ~ EVTYPE, data = conseReal, FUN = sum)
DeathAndInjuries <- DeathAndInjuries[order(DeathAndInjuries$FandI, decreasing = TRUE),]
# TOP 15 causes of Fatality and Injuries
MaxHumanHarm <- DeathAndInjuries[1:15, ]
print(MaxHumanHarm)
## EVTYPE FandI
## 830 TORNADO 96979
## 123 EXCESSIVE HEAT 8428
## 854 TSTM WIND 7461
## 164 FLOOD 7259
## 452 LIGHTNING 6046
## 269 HEAT 3037
## 147 FLASH FLOOD 2755
## 424 ICE STORM 2064
## 759 THUNDERSTORM WIND 1621
## 972 WINTER STORM 1527
## 354 HIGH WIND 1385
## 238 HAIL 1376
## 406 HURRICANE/TYPHOON 1339
## 304 HEAVY SNOW 1148
## 953 WILDFIRE 986
barplot(sort(by(MaxHumanHarm$FandI, MaxHumanHarm$EVTYPE, sum), decreasing=T)[15:1], horiz=T, las=1, cex.names=0.7, xlab="Total Fatalities and Injuries Per Event Type")
mtext("Total Fatalities and Injuries By Event Type (top 15)", side=3, line=1, cex=1, at=30000, font=2)
Destruction <- aggregate(PROPandCROP/10e9 ~ EVTYPE, data = conseReal, FUN = sum)
Destruction <- Destruction[order(Destruction$PROPandCROP, decreasing = TRUE),]
# TOP 15 Total Cost of Damage by Event Type (Billion of Dollars)
MaxDestruction <- Destruction[1:15, ]
print(MaxDestruction)
## EVTYPE PROPandCROP/1e+10
## 164 FLOOD 15.0319678
## 406 HURRICANE/TYPHOON 7.1913713
## 830 TORNADO 5.7352114
## 666 STORM SURGE 4.3323541
## 238 HAIL 1.8757805
## 147 FLASH FLOOD 1.7562129
## 88 DROUGHT 1.5018672
## 397 HURRICANE 1.4610229
## 586 RIVER FLOOD 1.0148404
## 424 ICE STORM 0.8967041
## 844 TROPICAL STORM 0.8382237
## 972 WINTER STORM 0.6715441
## 354 HIGH WIND 0.5908618
## 953 WILDFIRE 0.5060587
## 854 TSTM WIND 0.5038936
barplot(sort(by(MaxDestruction$PROPandCROP, MaxDestruction$EVTYPE, sum), decreasing=T)[15:1], horiz=T, las=1, cex.names=0.7, xlab="Total Cost of Destruction Per Event Type")
mtext("Total Cost of Destruction By Event Type (Billions of $)", side=3, line=1, cex=1, at=30000, font=2)
tornado Injured and Killed most people in the USA than any other weather event under the period between 1950 and end in November 2011. However floods caused the most destruction to property and crops within the same period.