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.
Setting the Work Directory and Downloading NOAA File From the Internet
setwd ("C:/Users/fkmho/Documents/Data_Science/Reproducible_Research")
getwd()
## [1] "C:/Users/fkmho/Documents/Data_Science/Reproducible_Research"
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", destfile = "stormData.csv")
# create vector stormdata from download stormData.csv file
stormdata <- read.csv("stormData.csv")
# view dimension rows and columns
dim(stormdata)
## [1] 902297 37
# explore head data
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
newstormdata <- stormdata[ , c(8, 23:28)]
rm(stormdata)
head(newstormdata)
## EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1 TORNADO 0 15 25.0 K 0
## 2 TORNADO 0 0 2.5 K 0
## 3 TORNADO 0 2 25.0 K 0
## 4 TORNADO 0 2 2.5 K 0
## 5 TORNADO 0 2 2.5 K 0
## 6 TORNADO 0 6 2.5 K 0
Data Acronyms Clarification
CROPDMG - Crop Damage CROPDAMAGE - Crop Damage Expense EVTYPE - Event Type Fatalities - Fatalities Injuries - Injuries PROPDMG - Property Damage PROPDAMAGE - Property Damage Expense
Fatalities and Injuries Summary
summary(newstormdata$FATALITIES)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.0168 0.0000 583.0000
summary(newstormdata$INJURIES)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.1557 0.0000 1700.0000
# Call Packages dplyr & bindrcpp
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.3.3
##
## 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(bindrcpp)
## Warning: package 'bindrcpp' was built under R version 3.3.3
Fatalities and Injuries Aggregation by Types of Events on Descending Order With First 20 Subset
fatalities <- aggregate(FATALITIES~EVTYPE, data = newstormdata, sum)
fatalities <- fatalities[order(-fatalities$FATALITIES), ][1:20, ]
fatalities
## EVTYPE FATALITIES
## 834 TORNADO 5633
## 130 EXCESSIVE HEAT 1903
## 153 FLASH FLOOD 978
## 275 HEAT 937
## 464 LIGHTNING 816
## 856 TSTM WIND 504
## 170 FLOOD 470
## 585 RIP CURRENT 368
## 359 HIGH WIND 248
## 19 AVALANCHE 224
## 972 WINTER STORM 206
## 586 RIP CURRENTS 204
## 278 HEAT WAVE 172
## 140 EXTREME COLD 160
## 760 THUNDERSTORM WIND 133
## 310 HEAVY SNOW 127
## 141 EXTREME COLD/WIND CHILL 125
## 676 STRONG WIND 103
## 30 BLIZZARD 101
## 350 HIGH SURF 101
injuries <- aggregate(INJURIES ~ EVTYPE, data = newstormdata, sum)
injuries <- injuries[order(-injuries$INJURIES), ][1:20, ]
injuries
## EVTYPE INJURIES
## 834 TORNADO 91346
## 856 TSTM WIND 6957
## 170 FLOOD 6789
## 130 EXCESSIVE HEAT 6525
## 464 LIGHTNING 5230
## 275 HEAT 2100
## 427 ICE STORM 1975
## 153 FLASH FLOOD 1777
## 760 THUNDERSTORM WIND 1488
## 244 HAIL 1361
## 972 WINTER STORM 1321
## 411 HURRICANE/TYPHOON 1275
## 359 HIGH WIND 1137
## 310 HEAVY SNOW 1021
## 957 WILDFIRE 911
## 786 THUNDERSTORM WINDS 908
## 30 BLIZZARD 805
## 188 FOG 734
## 955 WILD/FOREST FIRE 545
## 117 DUST STORM 440
Top Fatalities and Injuries Graphs
par(mfrow=c(1,1), mar=c(12,7,3,2))
barplot(fatalities$FATALITIES,names.arg=fatalities$EVTYPE,las=2,col="green", ylab="fatalities", main="Top Fatalities")
par(mfrow=c(1,1), mar=c(12,7,3,2))
barplot(injuries$INJURIES,names.arg=injuries$EVTYPE,las=2,col="green", ylab="injuries",main="Top Injuries")
Tornados have the hghtest number of injuries and fatalities according as illustrated above.
Across the United States, which types of events have the greatest economic consequences?
Conversion of Property and Crop Damage to Numbers. H=10^2, K=10^3, M =10^6, B=10^9, and create variables PROPDAMAGE, CROPDAMAGE
newstormdata$PROPDAMAGE = 0
newstormdata[newstormdata$PROPDMGEXP == "H", ]$PROPDAMAGE = newstormdata[newstormdata$PROPDMGEXP == "H", ]$PROPDMG * 10^2
newstormdata[newstormdata$PROPDMGEXP == "K", ]$PROPDAMAGE = newstormdata[newstormdata$PROPDMGEXP == "K", ]$PROPDMG * 10^3
newstormdata[newstormdata$PROPDMGEXP == "M", ]$PROPDAMAGE = newstormdata[newstormdata$PROPDMGEXP == "M", ]$PROPDMG * 10^6
newstormdata[newstormdata$PROPDMGEXP == "B", ]$PROPDAMAGE = newstormdata[newstormdata$PROPDMGEXP == "B", ]$PROPDMG * 10^9
newstormdata$CROPDAMAGE = 0
newstormdata[newstormdata$CROPDMGEXP == "H", ]$CROPDAMAGE = newstormdata[newstormdata$CROPDMGEXP == "H", ]$CROPDMG * 10^2
newstormdata[newstormdata$CROPDMGEXP == "K", ]$CROPDAMAGE = newstormdata[newstormdata$CROPDMGEXP == "K", ]$CROPDMG * 10^3
newstormdata[newstormdata$CROPDMGEXP == "M", ]$CROPDAMAGE = newstormdata[newstormdata$CROPDMGEXP == "M", ]$CROPDMG * 10^6
newstormdata[newstormdata$CROPDMGEXP == "B", ]$CROPDAMAGE = newstormdata[newstormdata$CROPDMGEXP == "B", ]$CROPDMG * 10^9
Crop and Property Damage Variable Aggregation Top 20 Arranged in Descending Order
economicdamage <- aggregate(PROPDAMAGE + CROPDAMAGE ~ EVTYPE, newstormdata, sum)
names(economicdamage) = c("EVENTTYPE", "TOTALDAMAGE")
economicdamage <- arrange(economicdamage, desc(TOTALDAMAGE))
economicdamage <- economicdamage[1:20, ]
economicdamage$TOTALDAMAGE <- economicdamage$TOTALDAMAGE/10^9
economicdamage$EVENTTYPE <- factor(economicdamage$EVENTTYPE, levels = economicdamage$EVENTTYPE)
head(economicdamage)
## EVENTTYPE TOTALDAMAGE
## 1 FLOOD 150.31968
## 2 HURRICANE/TYPHOON 71.91371
## 3 TORNADO 57.34061
## 4 STORM SURGE 43.32354
## 5 HAIL 18.75290
## 6 FLASH FLOOD 17.56213
with(economicdamage, barplot(TOTALDAMAGE, names.arg = EVENTTYPE, beside = T, cex.names = 0.8, las=2, col = "blue", main = "Crop and Property Damage Top 20 Event Types", ylab = "Damages Dollar Value"))
The worst economic damage is caused by flood and least is heavy rain/severe weather