This report analyzes storm events in the NOAA STORM database starting in the year 1950 and end in November 2011. Reported are the impacts on economic damage (property and crop damage) and health (fatalities and injuries). Impact is measured by counts for fatalities and injuries, and totals for economic damage. Per storm impacts are also reported. Given are graphs for the top 10 health impact storms (total fatalities and injuries) verse ecomonic impact. These show that high impact in one area is often not realated or inversely realted to the other area.
The data was downloaded from https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2 into the working directory and unpacked into a data frame variable ‘’’NOAA’’’ using the following code. If the data was previously downloaded and unpacked this is skipped. The primary working directory may be set in the first line.
setwd("~/Coursera/Course5/Project 2")
library(data.table)
library(dplyr)
##
## Attaching package: 'dplyr'
##
## The following objects are masked from 'package:data.table':
##
## between, last
##
## The following objects are masked from 'package:stats':
##
## filter, lag
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
loadData <- function(URL,DIR,FILE){
destfile <- paste0(DIR,'/',FILE)
if (!dir.exists(DIR)) dir.create(DIR)
downloadData(URL,destfile)
if (!exists(DIR)) {
assign(x = DIR,
value = read.csv(destfile,
header = TRUE,
sep = ",",
quote = "\"",
stringsAsFactors=FALSE)
)
}
NOAA
}
downloadData <- function(url,destfile){
method <- 'wget'
if (!file.exists(destfile)) download.file(url, destfile, method)
}
The event description within the data contained variations for the same event. For example TSTM WIND THUNDERTORM WINDS or THUNDERTORM WINDSS or ICE ON ROAD,ICE ROADS, ICY ROADS Variations were identified and aggregated. The list below shows the applied combinations. While there may in fact be technical differences between some of the combined events, the combination give a better representation of the damage resulting from the type of event. The last argument of the clnVar(list, replacement) function is the description used for the aggregation.
#Cleaning up some variations
clnVar <- function(TMP,entype,newtype){
for (x in entype){
TMP[TMP==x[1]] <- newtype
}
TMP
}
cleanUp <- function (DF){
DF$EVTYPE <- trimws(toupper(DF$EVTYPE))
DF$EVTYPE = clnVar(DF$EVTYPE,c('DRY MIRCOBURST WINDS'),'DRY MICROBURST')
DF$EVTYPE = clnVar(DF$EVTYPE,c('FLASH FLOOD/FLOOD','FLASH FLOODING','FLASH FLOODING/FLOOD','FLASH FLOODS',
'FLOOD/FLASH FLOOD'),'FLASH FLOODS')
DF$EVTYPE = clnVar(DF$EVTYPE,c('AVALANCE'),'AVALANCHE')
DF$EVTYPE = clnVar(DF$EVTYPE,c('COASTALSTORM'),'COASTAL STORM')
DF$EVTYPE = clnVar(DF$EVTYPE,c('GUSTY WIND'),'GUSTY WINDS')
DF$EVTYPE = clnVar(DF$EVTYPE,c('HEAT WAVES'),'HEAT WAVE')
DF$EVTYPE = clnVar(DF$EVTYPE,c('HEAVY RAINS'),'HEAVY RAIN')
DF$EVTYPE = clnVar(DF$EVTYPE,c('HIGH WINDS'),'HIGH WIND')
DF$EVTYPE = clnVar(DF$EVTYPE,c('HURRICANE OPAL/HIGH WINDS'),'HURRICANE OPAL')
DF$EVTYPE = clnVar(DF$EVTYPE,c('HYPERTHERMIA/EXPOSURE','HYPOTHERMIA/EXPOSURE'),'HIGH WIND')
DF$EVTYPE = clnVar(DF$EVTYPE,c('ICE ON ROAD','ICE ROADS'),'ICY ROADS')
DF$EVTYPE = clnVar(DF$EVTYPE,c('LANDSLIDES'),'LANDSLIDE')
DF$EVTYPE = clnVar(DF$EVTYPE,c('LIGHTNING.'),'LIGHTNING')
DF$EVTYPE = clnVar(DF$EVTYPE,c('LIGHTNING AND THUNDERSTORM WIN','LIGHTNING INJURY'),'LIGHTNING')
DF$EVTYPE = clnVar(DF$EVTYPE,c('MUDSLIDES'),'MUDSLIDE')
DF$EVTYPE = clnVar(DF$EVTYPE,c('RECORD HEAT'),'RECORD/EXCESSIVE HEAT')
DF$EVTYPE = clnVar(DF$EVTYPE,c('RIP CURRENTS'),'RIP CURRENT')
DF$EVTYPE = clnVar(DF$EVTYPE,c('RIVER FLOODING'),'RIVER FLOOD')
DF$EVTYPE = clnVar(DF$EVTYPE,c('SNOW SQUALLS'),'SNOW SQUALL')
DF$EVTYPE = clnVar(DF$EVTYPE,c('STORM SURGE/TIDE'),'STORM SURGE')
DF$EVTYPE = clnVar(DF$EVTYPE,c('STRONG WINDS'),'STRONG WIND')
DF$EVTYPE = clnVar(DF$EVTYPE,c('TSTM WIND (G45)','THUNDERSTORM WINDS 13','THUNDERSTORM WIND G52',
'THUNDERSTORM WIND (G40)','TSTM WIND (G35)','TSTM WIND (G40)',
'TSTM WIND/HAIL','TSTM WIND','THUNDERSTORMS WINDS','THUNDERSTORMW',
'THUNDERSTORM WIND','THUNDERSTORM WIND','THUNDERSTORM WIND',
'THUNDERSTORM WINDS','THUNDERSTORM WINDS','THUNDERSTORM WINDS',
'THUNDERSTORM WINDS/HAIL','THUNDERSTORM WINDSS',
'THUNDERTORM WINDS','THUNDERSTORM'),'THUNDER STM')
DF$EVTYPE = clnVar(DF$EVTYPE,c('TORNADOES, TSTM WIND, HAIL','TORNADO F2','TORNADO F3'),'TORNADO')
DF$EVTYPE = clnVar(DF$EVTYPE,c('WATERSPOUT TORNADO','WATERSPOUT/TORNADO'),'WATERSPOUT')
DF$EVTYPE = clnVar(DF$EVTYPE,c('WILDF$EVTYPEIRE','WILD/FOREST FIRE'),'WILD FIRES')
DF$EVTYPE = clnVar(DF$EVTYPE,c('WINDS'),'WIND')
DF$EVTYPE = clnVar(DF$EVTYPE,c('WINTER WEATHER MIX','WINTER WEATHER/MIX','WINTRY MIX'),'WINTER WEATHER')
DF$EVTYPE = clnVar(DF$EVTYPE,c('TYPHOON','HURRICANE/TYPHOON','HURRICANE OPAL','HURRICANE-GENERATED SWELLS',
'HURRICANE FELIX','HURRICANE ERIN','HURRICANE ERIN','HURRICANE EMILY',
'HURRICANE EDOUARD'),'HURRICANE')
DF$EVTYPE = clnVar(DF$EVTYPE,c('EXTREME HEAT','EXCESSIVE HEAT','HEAT WAVE'),'HEAT')
DF$EVTYPE = clnVar(DF$EVTYPE,c('WINTER STORMS'),'WINTER STORM')
DF$EVTYPE = clnVar(DF$EVTYPE,c('BLACK ICE'),'ICY ROADS')
DF
}
Code for loading and cleaning the data
NOAA <- loadData(URL ='https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2',
DIR ='NOAA',
FILE= 'repdata-data-StormData.csv.bz2')
NOAA <- cleanUp(NOAA)
NOAA$EVTYPE = factor(NOAA$EVTYPE)
NOAA$COUNT = 1 #Added to count events
The data reports the number of fatalities and injuries, both direct and indirect. This can be used as a measure of the effect of the storms on Health.
Code for isolating fatality and injury data from the big table.
NOAA_FI = select(NOAA,EVTYPE,FATALITIES,INJURIES,COUNT)
names(NOAA_FI) = c('EVTYPE','FATALITIES','INJURIES','COUNT')
Below are tables ordered by fatalities, injuries and the total of Fatalities and injuries.
# Data grouping
tmp.tb <- data.table(NOAA_FI)
setkey(tmp.tb, EVTYPE)
A <- tmp.tb[, lapply(.SD, sum), by = list(EVTYPE)]
rm(tmp.tb)
A$TOTAL_F_and_I = A$FATALITIES + A$INJURIES
#Sort by ...
A_fatalities_ordered <- arrange(A,desc(A$FATALITIES))
A_injuries_ordered <- arrange(A,desc(A$INJURIES))
A_total_ordered <- arrange(A,desc(A$TOTAL_F_and_I))
The top 15 when sorted in various orders are shown below.
Table 1
head(A_fatalities_ordered,n=10)
## EVTYPE FATALITIES INJURIES COUNT TOTAL_F_and_I
## 1: TORNADO 5658 91364 60658 97022
## 2: HEAT 3113 9159 2544 12272
## 3: FLASH FLOOD 978 1777 54278 2755
## 4: LIGHTNING 817 5232 15758 6049
## 5: THUNDER S 711 9508 324581 10219
## 6: RIP CURRENT 572 529 774 1101
## 7: FLOOD 470 6789 25327 7259
## 8: HIGH WIND 291 1439 21754 1730
## 9: AVALANCHE 225 170 387 395
## 10: WINTER STORM 216 1338 11436 1554
Table 2
head(A_injuries_ordered,n=10)
## EVTYPE FATALITIES INJURIES COUNT TOTAL_F_and_I
## 1: TORNADO 5658 91364 60658 97022
## 2: THUNDER S 711 9508 324581 10219
## 3: HEAT 3113 9159 2544 12272
## 4: FLOOD 470 6789 25327 7259
## 5: LIGHTNING 817 5232 15758 6049
## 6: ICE STORM 89 1975 2006 2064
## 7: FLASH FLOOD 978 1777 54278 2755
## 8: HIGH WIND 291 1439 21754 1730
## 9: HAIL 15 1361 288661 1376
## 10: WINTER STORM 216 1338 11436 1554
Table 3
head(A_total_ordered,n=10)
## EVTYPE FATALITIES INJURIES COUNT TOTAL_F_and_I
## 1: TORNADO 5658 91364 60658 97022
## 2: HEAT 3113 9159 2544 12272
## 3: THUNDER S 711 9508 324581 10219
## 4: FLOOD 470 6789 25327 7259
## 5: LIGHTNING 817 5232 15758 6049
## 6: FLASH FLOOD 978 1777 54278 2755
## 7: ICE STORM 89 1975 2006 2064
## 8: HIGH WIND 291 1439 21754 1730
## 9: WINTER STORM 216 1338 11436 1554
## 10: HURRICANE 135 1333 298 1468
Tornadoes and thunderstorms are at or near the top in the lists above. This is a result of the sheer number of tornadoes. When considering the relative health impact (fatalities and injuries) per event for events that occurred more than 10 times, Tornadoes drop much lower and Thunderstorms falls out of the top 15.
A$RELATIVE <- A$TOTAL_F_and_I/A$COUNT
A_Relative_ordered <- select(filter(A,COUNT>10),EVTYPE,COUNT,TOTAL_F_and_I,RELATIVE)
A_Relative_ordered <- arrange(A_Relative_ordered,desc(RELATIVE))
print(head(A_Relative_ordered,n=15))
## EVTYPE COUNT TOTAL_F_and_I RELATIVE
## 1: TSUNAMI 20 162 8.1000000
## 2: GLAZE 43 223 5.1860465
## 3: HURRICANE 298 1468 4.9261745
## 4: HEAT 2544 12272 4.8238994
## 5: ICE 61 143 2.3442623
## 6: UNSEASONABLY WARM AND DRY 13 29 2.2307692
## 7: TORNADO 60658 97022 1.5994922
## 8: FOG 538 796 1.4795539
## 9: RIP CURRENT 774 1101 1.4224806
## 10: ICY ROADS 51 63 1.2352941
## 11: DUST STORM 427 462 1.0819672
## 12: COLD 82 86 1.0487805
## 13: ICE STORM 2006 2064 1.0289133
## 14: AVALANCHE 387 395 1.0206718
## 15: BLOWING SNOW 17 16 0.9411765
Economic impact is another way to measure the damage cause by storms. A similar analysis to above is preformed on storms where economic damage was recorded. Only events where injuries or fatalities are recorded included in this sections analysis thus the count of events will differ from above.
Code for isolating property damage (PROPDMG) and crop damage (CROPDMG) data from the big table.
NOAA_DMG = select(NOAA,EVTYPE,PROPDMG,CROPDMG,COUNT)
names(NOAA_DMG) = c('EVTYPE','PROPDMG','CROPDMG','COUNT')
Data grouping by event Type (EVTYPE)
tmp.tb <- data.table(NOAA_DMG)
setkey(tmp.tb, EVTYPE)
B <- tmp.tb[, lapply(.SD, sum), by = list(EVTYPE)]
rm(tmp.tb)
B$TOTALDMG = B$PROPDMG + B$CROPDMG
Ordering data
B_total_ordered <- arrange(B,desc(B$TOTALDMG))
Table 4
print(head(B_total_ordered,n=10))
## EVTYPE PROPDMG CROPDMG COUNT TOTALDMG
## 1: TORNADO 3213585.76 100021.02 60658 3313606.78
## 2: THUNDER S 2672407.16 199127.18 324581 2871534.34
## 3: FLASH FLOOD 1420174.59 179200.46 54278 1599375.05
## 4: HAIL 688693.38 579596.28 288661 1268289.66
## 5: FLOOD 899938.48 168037.88 25327 1067976.36
## 6: LIGHTNING 603351.78 3580.61 15758 606932.39
## 7: HIGH WIND 380356.56 19042.81 21754 399399.37
## 8: WINTER STORM 133220.59 2478.99 11436 135699.58
## 9: HEAVY SNOW 122251.99 2165.72 15708 124417.71
## 10: WILDFIRE 84459.34 4364.20 2761 88823.54
Below is the ranking when considering damage on a per event basis for events that resulted in damage at least ten times.
B$RELATIVE = B$TOTALDMG/B$COUNT
B_Relative_ordered <- select(filter(B,COUNT>10),EVTYPE,COUNT,TOTALDMG,RELATIVE)
B_Relative_ordered <- arrange(B_Relative_ordered,desc(RELATIVE))
Table 5
print(head(B_Relative_ordered,n=15))
## EVTYPE COUNT TOTALDMG RELATIVE
## 1: ICE 61 7660.00 125.57377
## 2: HURRICANE 298 36324.44 121.89409
## 3: RIVER FLOOD 202 18977.53 93.94817
## 4: TROPICAL STORM 690 54322.80 78.72870
## 5: EXCESSIVE SNOW 25 1935.00 77.40000
## 6: FLOODING 120 8824.90 73.54083
## 7: STORM SURGE 409 27025.54 66.07711
## 8: RAIN 16 1055.05 65.94062
## 9: URBAN FLOODING 99 5972.10 60.32424
## 10: URBAN FLOOD 251 14216.50 56.63944
## 11: TORNADO 60658 3313606.78 54.62770
## 12: SEICHE 21 980.00 46.66667
## 13: TSUNAMI 20 925.30 46.26500
## 14: FLASH FLOODS 1369 60146.65 43.93473
## 15: FLOOD 25327 1067976.36 42.16750
The plots below show the relationship of between the economic and health impacts of the top 10 events for health impacts listed in table 3. These show that high impact in one econmic damage is often not realated or inversely realted to impact in health.
Code for generating plots is below.
C <- head(A_total_ordered,n=10)
W = filter(NOAA,NOAA$EVTYPE %in% C$EVTYPE[1:5] )
W$TOTAL_F_and_I <- W$FATALITIES + W$INJURIES
W$TOTAL_E <- W$PROPDMG + W$CROPDMG
g1 = W$EVTYPE
x1 = W$TOTAL_F_and_I
y1 = W$TOTAL_E
PLOT1 = qplot(x1,y1,facets = .~g1,
xlab='Fatalities and Injuries',
ylab='Ecomonic Damage',
ylim=c(0,2000),
xlim=c(0,100))
W = filter(NOAA,NOAA$EVTYPE %in% C$EVTYPE[6:10])
W$TOTAL_F_and_I <- W$FATALITIES + W$INJURIES
W$TOTAL_E <- W$PROPDMG + W$CROPDMG
g2 = W$EVTYPE
x2 = W$TOTAL_F_and_I
y2 = W$TOTAL_E
PLOT2 = qplot(x2,y2,facets = .~g2,
xlab='Fatalities and Injuries',
ylab='Ecomonic Damage',
ylim=c(0,2000),
xlim=c(0,100))
The points plotted are for events where the economic impact is in the range (0,2000) and the fatalities and injuries are in the range (0,100). This limitation removes outliers from the graphs and helps visualize the relationship between the variables for the majority of the Storms. Warnings that are triggered by points out side the plot ranges are suppressed.
suppressWarnings(print(PLOT1))
See above for figure captions.
suppressWarnings(print(PLOT2))
See above for figure captions.