The U.S. National Oceanic and Atmospheric Administration (NOAA)1 tracks weather and oceanic events in the United States. This report will analyze NOAA’s storm data (as cached by Coursera’s Reproducible Research Course2) and produce a quantified ranking of event types by their human and economic impact.
The intended audience is public officials in charge of emergency preparedness, as well as other data science students and professionals.
As stipulated by the project, the analysis will be distilled into at most 3 figures.
library(dplyr)
library(ggplot2)
library(stringr)
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2" # Coursera cache of NOAA data
filename <-"StormData.csv.bz2"
download.file(url, filename)
storms_orig <- read.csv(filename)
str(storms_orig)
## 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : chr "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
## $ BGN_TIME : chr "0130" "0145" "1600" "0900" ...
## $ TIME_ZONE : chr "CST" "CST" "CST" "CST" ...
## $ COUNTY : num 97 3 57 89 43 77 9 123 125 57 ...
## $ COUNTYNAME: chr "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
## $ STATE : chr "AL" "AL" "AL" "AL" ...
## $ EVTYPE : chr "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
## $ BGN_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ BGN_AZI : chr "" "" "" "" ...
## $ BGN_LOCATI: chr "" "" "" "" ...
## $ END_DATE : chr "" "" "" "" ...
## $ END_TIME : chr "" "" "" "" ...
## $ COUNTY_END: num 0 0 0 0 0 0 0 0 0 0 ...
## $ COUNTYENDN: logi NA NA NA NA NA NA ...
## $ END_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ END_AZI : chr "" "" "" "" ...
## $ END_LOCATI: chr "" "" "" "" ...
## $ LENGTH : num 14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
## $ WIDTH : num 100 150 123 100 150 177 33 33 100 100 ...
## $ F : int 3 2 2 2 2 2 2 1 3 3 ...
## $ MAG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ FATALITIES: num 0 0 0 0 0 0 0 0 1 0 ...
## $ INJURIES : num 15 0 2 2 2 6 1 0 14 0 ...
## $ PROPDMG : num 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
## $ PROPDMGEXP: chr "K" "K" "K" "K" ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: chr "" "" "" "" ...
## $ WFO : chr "" "" "" "" ...
## $ STATEOFFIC: chr "" "" "" "" ...
## $ ZONENAMES : chr "" "" "" "" ...
## $ LATITUDE : num 3040 3042 3340 3458 3412 ...
## $ LONGITUDE : num 8812 8755 8742 8626 8642 ...
## $ LATITUDE_E: num 3051 0 0 0 0 ...
## $ LONGITUDE_: num 8806 0 0 0 0 ...
## $ REMARKS : chr "" "" "" "" ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
st <- storms_orig %>%
transmute(
date = as.Date(BGN_DATE, "%m/%d/%Y"),
year = as.integer(format(date, "%Y")),
state = STATE,
county = COUNTYNAME,
type = EVTYPE,
dth = FATALITIES,
inj = INJURIES,
PROPDMG, PROPDMGEXP,
CROPDMG, CROPDMGEXP,
REFNUM)
summary(st %>% select(date, PROPDMG, CROPDMG, dth, inj))
## date PROPDMG CROPDMG dth inj
## Min. :1950-01-03 Min. : 0.00 Min. : 0.000 Min. : 0.0000 Min. : 0.0000
## 1st Qu.:1995-04-20 1st Qu.: 0.00 1st Qu.: 0.000 1st Qu.: 0.0000 1st Qu.: 0.0000
## Median :2002-03-18 Median : 0.00 Median : 0.000 Median : 0.0000 Median : 0.0000
## Mean :1998-12-27 Mean : 12.06 Mean : 1.527 Mean : 0.0168 Mean : 0.1557
## 3rd Qu.:2007-07-28 3rd Qu.: 0.50 3rd Qu.: 0.000 3rd Qu.: 0.0000 3rd Qu.: 0.0000
## Max. :2011-11-30 Max. :5000.00 Max. :990.000 Max. :583.0000 Max. :1700.0000
st <- st %>% filter(dth+inj+PROPDMG+CROPDMG > 0)
summary(st %>% select(date, PROPDMG, CROPDMG, dth, inj))
## date PROPDMG CROPDMG dth inj
## Min. :1950-01-03 Min. : 0.00 Min. : 0.000 Min. : 0.0000 Min. : 0.0000
## 1st Qu.:1997-01-23 1st Qu.: 2.00 1st Qu.: 0.000 1st Qu.: 0.0000 1st Qu.: 0.0000
## Median :2002-08-02 Median : 5.00 Median : 0.000 Median : 0.0000 Median : 0.0000
## Mean :2000-06-13 Mean : 42.75 Mean : 5.411 Mean : 0.0595 Mean : 0.5519
## 3rd Qu.:2008-05-07 3rd Qu.: 25.00 3rd Qu.: 0.000 3rd Qu.: 0.0000 3rd Qu.: 0.0000
## Max. :2011-11-30 Max. :5000.00 Max. :990.000 Max. :583.0000 Max. :1700.0000
st %>% summarize(n(), .by = c(year, type)) %>%
ggplot(aes(x = year)) +
geom_histogram(binwidth = 1, color = "black", fill = "white") +
scale_x_continuous(breaks = seq(min(st$year), max(st$year), by = 5)) +
labs(x = "Year", y = "Event Types", title = "Figure 1. Count of Event Types Recorded Over the Years") +
theme_classic() +
theme(plot.title = element_text(hjust = .5))
To avoid wild fluctuations in the event types recorded, we will limit the data to 1998 onwards.
st <- st %>% filter(year >= 1998)
st$type %>% unique %>% sort
## [1] " HIGH SURF ADVISORY" " FLASH FLOOD" " TSTM WIND"
## [4] " TSTM WIND (G45)" "ASTRONOMICAL HIGH TIDE" "ASTRONOMICAL LOW TIDE"
## [7] "AVALANCHE" "BLIZZARD" "BLOWING DUST"
## [10] "BRUSH FIRE" "COASTAL FLOODING/EROSION" "COASTAL EROSION"
## [13] "COASTAL FLOOD" "COASTAL FLOODING" "COASTAL FLOODING/EROSION"
## [16] "COLD" "COLD WEATHER" "COLD/WIND CHILL"
## [19] "DAM BREAK" "DENSE FOG" "DENSE SMOKE"
## [22] "DROUGHT" "DROWNING" "DRY MICROBURST"
## [25] "DUST DEVIL" "DUST STORM" "EXCESSIVE HEAT"
## [28] "EXCESSIVE SNOW" "EXTREME COLD" "EXTREME COLD/WIND CHILL"
## [31] "EXTREME WINDCHILL" "FALLING SNOW/ICE" "FLASH FLOOD"
## [34] "FLASH FLOOD/FLOOD" "FLOOD" "FLOOD/FLASH/FLOOD"
## [37] "FOG" "FREEZE" "FREEZING FOG"
## [40] "FREEZING RAIN" "FROST/FREEZE" "FUNNEL CLOUD"
## [43] "GLAZE" "GUSTY WIND" "GUSTY WIND/HAIL"
## [46] "GUSTY WINDS" "HAIL" "HAZARDOUS SURF"
## [49] "HEAT" "HEAVY RAIN" "HEAVY SEAS"
## [52] "HEAVY SNOW" "HEAVY SURF" "HEAVY SURF/HIGH SURF"
## [55] "HIGH SEAS" "HIGH SURF" "HIGH WATER"
## [58] "HIGH WIND" "HIGH WIND (G40)" "HURRICANE"
## [61] "HURRICANE/TYPHOON" "HYPERTHERMIA/EXPOSURE" "ICE ON ROAD"
## [64] "ICE ROADS" "ICE STORM" "ICY ROADS"
## [67] "LAKE EFFECT SNOW" "LAKE-EFFECT SNOW" "LAKESHORE FLOOD"
## [70] "LANDSLIDE" "LANDSPOUT" "LATE SEASON SNOW"
## [73] "LIGHT FREEZING RAIN" "LIGHT SNOW" "LIGHTNING"
## [76] "MARINE HAIL" "MARINE HIGH WIND" "MARINE STRONG WIND"
## [79] "MARINE THUNDERSTORM WIND" "MARINE TSTM WIND" "MIXED PRECIPITATION"
## [82] "MUD SLIDE" "MUDSLIDE" "NON TSTM WIND"
## [85] "NON-SEVERE WIND DAMAGE" "NON-TSTM WIND" "OTHER"
## [88] "RAIN" "RECORD HEAT" "RIP CURRENT"
## [91] "RIP CURRENTS" "RIVER FLOOD" "RIVER FLOODING"
## [94] "ROCK SLIDE" "ROGUE WAVE" "ROUGH SEAS"
## [97] "SEICHE" "SMALL HAIL" "SNOW"
## [100] "SNOW SQUALL" "SNOW SQUALLS" "STORM SURGE"
## [103] "STORM SURGE/TIDE" "STRONG WIND" "STRONG WINDS"
## [106] "THUNDERSTORM" "THUNDERSTORM WIND" "THUNDERSTORM WIND (G40)"
## [109] "TIDAL FLOODING" "TORNADO" "TROPICAL DEPRESSION"
## [112] "TROPICAL STORM" "TSTM WIND" "TSTM WIND (G45)"
## [115] "TSTM WIND (G35)" "TSTM WIND (G40)" "TSTM WIND (G45)"
## [118] "TSTM WIND G45" "TSTM WIND/HAIL" "TSUNAMI"
## [121] "UNSEASONABLY COLD" "UNSEASONABLY WARM" "UNSEASONAL RAIN"
## [124] "URBAN/SML STREAM FLD" "VOLCANIC ASH" "WARM WEATHER"
## [127] "WATERSPOUT" "WET MICROBURST" "WHIRLWIND"
## [130] "WILD/FOREST FIRE" "WILDFIRE" "WIND"
## [133] "WIND AND WAVE" "WINTER STORM" "WINTER WEATHER"
## [136] "WINTER WEATHER MIX" "WINTER WEATHER/MIX" "WINTRY MIX"
st$type %>% str_squish %>% unique %>% sort
## [1] "ASTRONOMICAL HIGH TIDE" "ASTRONOMICAL LOW TIDE" "AVALANCHE" "BLIZZARD"
## [5] "BLOWING DUST" "BRUSH FIRE" "COASTAL EROSION" "COASTAL FLOOD"
## [9] "COASTAL FLOODING" "COASTAL FLOODING/EROSION" "COLD" "COLD WEATHER"
## [13] "COLD/WIND CHILL" "DAM BREAK" "DENSE FOG" "DENSE SMOKE"
## [17] "DROUGHT" "DROWNING" "DRY MICROBURST" "DUST DEVIL"
## [21] "DUST STORM" "EXCESSIVE HEAT" "EXCESSIVE SNOW" "EXTREME COLD"
## [25] "EXTREME COLD/WIND CHILL" "EXTREME WINDCHILL" "FALLING SNOW/ICE" "FLASH FLOOD"
## [29] "FLASH FLOOD/FLOOD" "FLOOD" "FLOOD/FLASH/FLOOD" "FOG"
## [33] "FREEZE" "FREEZING FOG" "FREEZING RAIN" "FROST/FREEZE"
## [37] "FUNNEL CLOUD" "GLAZE" "GUSTY WIND" "GUSTY WIND/HAIL"
## [41] "GUSTY WINDS" "HAIL" "HAZARDOUS SURF" "HEAT"
## [45] "HEAVY RAIN" "HEAVY SEAS" "HEAVY SNOW" "HEAVY SURF"
## [49] "HEAVY SURF/HIGH SURF" "HIGH SEAS" "HIGH SURF" "HIGH SURF ADVISORY"
## [53] "HIGH WATER" "HIGH WIND" "HIGH WIND (G40)" "HURRICANE"
## [57] "HURRICANE/TYPHOON" "HYPERTHERMIA/EXPOSURE" "ICE ON ROAD" "ICE ROADS"
## [61] "ICE STORM" "ICY ROADS" "LAKE EFFECT SNOW" "LAKE-EFFECT SNOW"
## [65] "LAKESHORE FLOOD" "LANDSLIDE" "LANDSPOUT" "LATE SEASON SNOW"
## [69] "LIGHT FREEZING RAIN" "LIGHT SNOW" "LIGHTNING" "MARINE HAIL"
## [73] "MARINE HIGH WIND" "MARINE STRONG WIND" "MARINE THUNDERSTORM WIND" "MARINE TSTM WIND"
## [77] "MIXED PRECIPITATION" "MUD SLIDE" "MUDSLIDE" "NON TSTM WIND"
## [81] "NON-SEVERE WIND DAMAGE" "NON-TSTM WIND" "OTHER" "RAIN"
## [85] "RECORD HEAT" "RIP CURRENT" "RIP CURRENTS" "RIVER FLOOD"
## [89] "RIVER FLOODING" "ROCK SLIDE" "ROGUE WAVE" "ROUGH SEAS"
## [93] "SEICHE" "SMALL HAIL" "SNOW" "SNOW SQUALL"
## [97] "SNOW SQUALLS" "STORM SURGE" "STORM SURGE/TIDE" "STRONG WIND"
## [101] "STRONG WINDS" "THUNDERSTORM" "THUNDERSTORM WIND" "THUNDERSTORM WIND (G40)"
## [105] "TIDAL FLOODING" "TORNADO" "TROPICAL DEPRESSION" "TROPICAL STORM"
## [109] "TSTM WIND" "TSTM WIND (G35)" "TSTM WIND (G40)" "TSTM WIND (G45)"
## [113] "TSTM WIND G45" "TSTM WIND/HAIL" "TSUNAMI" "UNSEASONABLY COLD"
## [117] "UNSEASONABLY WARM" "UNSEASONAL RAIN" "URBAN/SML STREAM FLD" "VOLCANIC ASH"
## [121] "WARM WEATHER" "WATERSPOUT" "WET MICROBURST" "WHIRLWIND"
## [125] "WILD/FOREST FIRE" "WILDFIRE" "WIND" "WIND AND WAVE"
## [129] "WINTER STORM" "WINTER WEATHER" "WINTER WEATHER MIX" "WINTER WEATHER/MIX"
## [133] "WINTRY MIX"
Let’s map the event types to the official list published by NOAA’s National Weather Service Instruction3:
event_mapping <- list(
'ASTRONOMICAL LOW TIDE' = c(
'ASTRONOMICAL LOW TIDE'),
'AVALANCHE' = c(
'AVALANCHE'),
'BLIZZARD' = c(
'BLIZZARD'),
'COASTAL FLOOD' = c(
'ASTRONOMICAL HIGH TIDE',
'COASTAL EROSION',
'COASTAL FLOOD',
'COASTAL FLOODING',
'COASTAL FLOODING/EROSION',
'TIDAL FLOODING'),
'COLD/WIND CHILL' = c(
'COLD',
'COLD WEATHER',
'COLD/WIND CHILL',
'UNSEASONABLY COLD'),
'DEBRIS FLOW' = c(
'DEBRIS FLOW',
'LANDSLIDE',
'MUD SLIDE',
'MUDSLIDE',
'ROCK SLIDE'),
'DENSE FOG' = c(
'DENSE FOG'),
'DENSE FOG' = c(
'FOG'),
'DENSE SMOKE' = c(
'DENSE SMOKE'),
'DROUGHT' = c(
'DROUGHT'),
'DUST DEVIL' = c(
'DUST DEVIL',
'OTHER'), # 2 events, from REMAKRS: "a strong dust devil", "a large dust devil"
'DUST STORM' = c(
'BLOWING DUST',
'DUST STORM'),
'EXCESSIVE HEAT' = c(
'EXCESSIVE HEAT',
'HYPERTHERMIA/EXPOSURE',
'RECORD HEAT'),
'EXTREME COLD/WIND CHILL' = c(
'EXTREME COLD',
'EXTREME COLD/WIND CHILL',
'EXTREME WINDCHILL'),
'FLASH FLOOD' = c(
'FLASH FLOOD',
'FLASH FLOOD/FLOOD',
'FLOOD/FLASH/FLOOD'),
'FLOOD' = c(
'DAM BREAK',
'DROWNING', # 1 event, from REMARKS: boy drowned in creek heavy rain caused rise of the creek
'FLOOD',
'HIGH WATER',
'URBAN/SML STREAM FLD',
'RIVER FLOOD',
'RIVER FLOODING'),
'FREEZING FOG' = c(
'FREEZING FOG'),
'FROST/FREEZE' = c(
'FREEZE',
'FROST/FREEZE'),
'FUNNEL CLOUD' = c(
'FUNNEL CLOUD'),
'HAIL' = c(
'HAIL',
'SMALL HAIL'),
'HEAT' = c(
'HEAT',
'UNSEASONABLY WARM',
'WARM WEATHER'),
'HEAVY RAIN' = c(
'HEAVY RAIN',
'RAIN',
'UNSEASONAL RAIN'),
'HEAVY SNOW' = c(
'HEAVY SNOW'),
'HIGH SURF' = c(
'HAZARDOUS SURF',
'HEAVY SURF',
'HEAVY SURF/HIGH SURF',
'HIGH SURF',
'HIGH SURF ADVISORY'),
'HIGH WIND' = c(
'HIGH WIND',
'HIGH WIND (G40)'),
'HURRICANE (TYPHOON)' = c(
'HURRICANE',
'HURRICANE (TYPHOON)',
'HURRICANE/TYPHOON'),
'LAKE-EFFECT SNOW' = c(
'LAKE EFFECT SNOW',
'LAKE-EFFECT SNOW'),
'LAKESHORE FLOOD' = c(
'LAKESHORE FLOOD'),
'LIGHTNING' = c(
'LIGHTNING'),
'MARINE HAIL' = c(
'MARINE HAIL'),
'MARINE HIGH WIND' = c(
'MARINE HIGH WIND'),
'MARINE STRONG WIND' = c(
'MARINE STRONG WIND'),
'MARINE THUNDERSTORM WIND' = c(
'MARINE THUNDERSTORM WIND',
'MARINE TSTM WIND'),
'RIP CURRENT' = c(
'RIP CURRENT',
'RIP CURRENTS'),
'SEICHE' = c(
'SEICHE'),
'SLEET' = c(
'SLEET'),
'STORM SURGE/TIDE' = c(
'STORM SURGE',
'STORM SURGE/TIDE'),
'STRONG WIND' = c(
'GUSTY WIND',
'GUSTY WIND/HAIL',
'GUSTY WINDS',
'NON TSTM WIND',
'NON-SEVERE WIND DAMAGE',
'NON-TSTM WIND',
'STRONG WIND',
'STRONG WINDS',
'WIND',
'WIND AND WAVE'),
'THUNDERSTORM WIND' = c(
'DRY MICROBURST', # as per 7.39.1 in instruction document
'THUNDERSTORM WIND',
'THUNDERSTORM WIND (G40)',
'TSTM WIND',
'TSTM WIND (G35)',
'TSTM WIND (G40)',
'TSTM WIND (G45)',
'TSTM WIND G45',
'TSTM WIND/HAIL',
'WET MICROBURST', # as per 7.39.1 in instruction document
'WHIRLWIND'),
'TORNADO' = c(
'LANDSPOUT', # as per 7.40.4 in instruction document
'TORNADO'),
'TROPICAL DEPRESSION' = c(
'TROPICAL DEPRESSION'),
'TROPICAL STORM' = c(
'TROPICAL STORM'),
'TSUNAMI' = c(
'TSUNAMI'),
'VOLCANIC ASH' = c(
'VOLCANIC ASH'),
'WATERSPOUT' = c(
'WATERSPOUT'),
'WILDFIRE' = c(
'BRUSH FIRE',
'WILD/FOREST FIRE',
'WILDFIRE'),
'WINTER STORM' = c(
'WINTER STORM'),
'WINTER WEATHER' = c(
'EXCESSIVE SNOW',
'FALLING SNOW/ICE',
'FREEZING RAIN',
'GLAZE',
'ICE ON ROAD',
'ICE ROADS',
'ICE STORM',
'ICY ROADS',
'LATE SEASON SNOW',
'LIGHT FREEZING RAIN',
'LIGHT SNOW',
'MIXED PRECIPITATION',
'SNOW',
'SNOW SQUALL',
'SNOW SQUALLS',
'THUNDERSTORM', # 1 event, not wind related, REMARKS: "snow clogged Interstate"
'WINTER WEATHER',
'WINTER WEATHER MIX',
'WINTER WEATHER/MIX',
'WINTRY MIX'),
'HIGH SEAS' = c( # no standard type found for this
'HEAVY SEAS',
'HIGH SEAS',
'ROGUE WAVE',
'ROUGH SEAS')
) %>% stack %>% with(setNames(ind, values)) # make it lookable right to left
st <- st %>% mutate(type_clean = type %>% str_squish %>% event_mapping[.]) # apply mapping
st %>% summarize(count = n(), .by = c(type_clean, type)) %>% arrange(type_clean, type) # see result
## type_clean type count
## 1 ASTRONOMICAL LOW TIDE ASTRONOMICAL LOW TIDE 2
## 2 AVALANCHE AVALANCHE 257
## 3 BLIZZARD BLIZZARD 171
## 4 COASTAL FLOOD ASTRONOMICAL HIGH TIDE 8
## 5 COASTAL FLOOD COASTAL FLOODING/EROSION 1
## 6 COASTAL FLOOD COASTAL EROSION 1
## 7 COASTAL FLOOD COASTAL FLOOD 148
## 8 COASTAL FLOOD COASTAL FLOODING 28
## 9 COASTAL FLOOD COASTAL FLOODING/EROSION 3
## 10 COASTAL FLOOD TIDAL FLOODING 2
## 11 COLD/WIND CHILL COLD 12
## 12 COLD/WIND CHILL COLD WEATHER 1
## 13 COLD/WIND CHILL COLD/WIND CHILL 90
## 14 COLD/WIND CHILL UNSEASONABLY COLD 2
## 15 DEBRIS FLOW LANDSLIDE 190
## 16 DEBRIS FLOW MUD SLIDE 1
## 17 DEBRIS FLOW MUDSLIDE 3
## 18 DEBRIS FLOW ROCK SLIDE 1
## 19 DENSE FOG DENSE FOG 58
## 20 DENSE FOG FOG 81
## 21 DENSE SMOKE DENSE SMOKE 1
## 22 DROUGHT DROUGHT 228
## 23 DUST DEVIL DUST DEVIL 76
## 24 DUST DEVIL OTHER 2
## 25 DUST STORM BLOWING DUST 1
## 26 DUST STORM DUST STORM 89
## 27 EXCESSIVE HEAT EXCESSIVE HEAT 631
## 28 EXCESSIVE HEAT HYPERTHERMIA/EXPOSURE 1
## 29 EXCESSIVE HEAT RECORD HEAT 1
## 30 EXTREME COLD/WIND CHILL EXTREME COLD 69
## 31 EXTREME COLD/WIND CHILL EXTREME COLD/WIND CHILL 111
## 32 EXTREME COLD/WIND CHILL EXTREME WINDCHILL 7
## 33 FLASH FLOOD FLASH FLOOD 1
## 34 FLASH FLOOD FLASH FLOOD 16841
## 35 FLASH FLOOD FLASH FLOOD/FLOOD 1
## 36 FLASH FLOOD FLOOD/FLASH/FLOOD 1
## 37 FLOOD DAM BREAK 1
## 38 FLOOD DROWNING 1
## 39 FLOOD FLOOD 8797
## 40 FLOOD HIGH WATER 2
## 41 FLOOD RIVER FLOOD 60
## 42 FLOOD RIVER FLOODING 1
## 43 FLOOD URBAN/SML STREAM FLD 519
## 44 FREEZING FOG FREEZING FOG 7
## 45 FROST/FREEZE FREEZE 11
## 46 FROST/FREEZE FROST/FREEZE 116
## 47 FUNNEL CLOUD FUNNEL CLOUD 8
## 48 HAIL HAIL 20480
## 49 HAIL SMALL HAIL 11
## 50 HEAT HEAT 163
## 51 HEAT UNSEASONABLY WARM 5
## 52 HEAT WARM WEATHER 1
## 53 HEAVY RAIN HEAVY RAIN 950
## 54 HEAVY RAIN RAIN 3
## 55 HEAVY RAIN UNSEASONAL RAIN 2
## 56 HEAVY SNOW HEAVY SNOW 803
## 57 HIGH SURF HIGH SURF ADVISORY 1
## 58 HIGH SURF HAZARDOUS SURF 1
## 59 HIGH SURF HEAVY SURF 26
## 60 HIGH SURF HEAVY SURF/HIGH SURF 50
## 61 HIGH SURF HIGH SURF 119
## 62 HIGH WIND HIGH WIND 4783
## 63 HIGH WIND HIGH WIND (G40) 2
## 64 HURRICANE (TYPHOON) HURRICANE 101
## 65 HURRICANE (TYPHOON) HURRICANE/TYPHOON 72
## 66 LAKE-EFFECT SNOW LAKE EFFECT SNOW 3
## 67 LAKE-EFFECT SNOW LAKE-EFFECT SNOW 194
## 68 LAKESHORE FLOOD LAKESHORE FLOOD 5
## 69 LIGHTNING LIGHTNING 9721
## 70 MARINE HAIL MARINE HAIL 2
## 71 MARINE HIGH WIND MARINE HIGH WIND 19
## 72 MARINE STRONG WIND MARINE STRONG WIND 46
## 73 MARINE THUNDERSTORM WIND MARINE THUNDERSTORM WIND 33
## 74 MARINE THUNDERSTORM WIND MARINE TSTM WIND 109
## 75 RIP CURRENT RIP CURRENT 363
## 76 RIP CURRENT RIP CURRENTS 200
## 77 SEICHE SEICHE 9
## 78 STORM SURGE/TIDE STORM SURGE 128
## 79 STORM SURGE/TIDE STORM SURGE/TIDE 47
## 80 STRONG WIND GUSTY WIND 6
## 81 STRONG WIND GUSTY WIND/HAIL 1
## 82 STRONG WIND GUSTY WINDS 18
## 83 STRONG WIND NON TSTM WIND 1
## 84 STRONG WIND NON-SEVERE WIND DAMAGE 1
## 85 STRONG WIND NON-TSTM WIND 1
## 86 STRONG WIND STRONG WIND 3349
## 87 STRONG WIND STRONG WINDS 30
## 88 STRONG WIND WIND 57
## 89 STRONG WIND WIND AND WAVE 1
## 90 THUNDERSTORM WIND TSTM WIND 2
## 91 THUNDERSTORM WIND TSTM WIND (G45) 1
## 92 THUNDERSTORM WIND DRY MICROBURST 60
## 93 THUNDERSTORM WIND THUNDERSTORM WIND 43097
## 94 THUNDERSTORM WIND THUNDERSTORM WIND (G40) 1
## 95 THUNDERSTORM WIND TSTM WIND 51516
## 96 THUNDERSTORM WIND TSTM WIND (G45) 1
## 97 THUNDERSTORM WIND TSTM WIND (G35) 1
## 98 THUNDERSTORM WIND TSTM WIND (G40) 8
## 99 THUNDERSTORM WIND TSTM WIND (G45) 23
## 100 THUNDERSTORM WIND TSTM WIND G45 1
## 101 THUNDERSTORM WIND TSTM WIND/HAIL 280
## 102 THUNDERSTORM WIND WET MICROBURST 1
## 103 THUNDERSTORM WIND WHIRLWIND 1
## 104 TORNADO LANDSPOUT 2
## 105 TORNADO TORNADO 11154
## 106 TROPICAL DEPRESSION TROPICAL DEPRESSION 35
## 107 TROPICAL STORM TROPICAL STORM 401
## 108 TSUNAMI TSUNAMI 14
## 109 VOLCANIC ASH VOLCANIC ASH 2
## 110 WATERSPOUT WATERSPOUT 23
## 111 WILDFIRE BRUSH FIRE 1
## 112 WILDFIRE WILD/FOREST FIRE 344
## 113 WILDFIRE WILDFIRE 847
## 114 WINTER STORM WINTER STORM 1263
## 115 WINTER WEATHER EXCESSIVE SNOW 25
## 116 WINTER WEATHER FALLING SNOW/ICE 2
## 117 WINTER WEATHER FREEZING RAIN 6
## 118 WINTER WEATHER GLAZE 14
## 119 WINTER WEATHER ICE ON ROAD 1
## 120 WINTER WEATHER ICE ROADS 1
## 121 WINTER WEATHER ICE STORM 534
## 122 WINTER WEATHER ICY ROADS 13
## 123 WINTER WEATHER LATE SEASON SNOW 1
## 124 WINTER WEATHER LIGHT FREEZING RAIN 22
## 125 WINTER WEATHER LIGHT SNOW 108
## 126 WINTER WEATHER MIXED PRECIPITATION 15
## 127 WINTER WEATHER SNOW 9
## 128 WINTER WEATHER SNOW SQUALL 2
## 129 WINTER WEATHER SNOW SQUALLS 3
## 130 WINTER WEATHER THUNDERSTORM 1
## 131 WINTER WEATHER WINTER WEATHER 404
## 132 WINTER WEATHER WINTER WEATHER MIX 2
## 133 WINTER WEATHER WINTER WEATHER/MIX 139
## 134 WINTER WEATHER WINTRY MIX 3
## 135 HIGH SEAS HEAVY SEAS 1
## 136 HIGH SEAS HIGH SEAS 6
## 137 HIGH SEAS ROGUE WAVE 1
## 138 HIGH SEAS ROUGH SEAS 3
st %>% select(PROPDMGEXP) %>% table
## PROPDMGEXP
## B K M
## 6876 31 167578 6471
st %>% select(CROPDMGEXP) %>% table
## CROPDMGEXP
## B K M
## 85920 2 93587 1447
multiplier <- c("K" = 1e3, "M" = 1e6, "B" = 1e9)
st <- st %>% mutate( # assume no change if exponential is empty
prop = PROPDMG * coalesce(multiplier[PROPDMGEXP], 1),
crop = CROPDMG * coalesce(multiplier[CROPDMGEXP], 1))
Since ranking is highly sensitive to maximum values, let’s verify the validity of the numeric variables’ maximum values by cross-checking them with the NOAA Storm Events Database4.
st %>% select(REFNUM,date,state,county,type,dth) %>% slice_max(order_by = dth)
## REFNUM date state county type dth
## 1 862563 2011-05-22 MO JASPER TORNADO 158
158 = 158 ✅
st %>% select(REFNUM,date,state,county,type,inj) %>% slice_max(order_by = inj)
## REFNUM date state county type inj
## 1 862563 2011-05-22 MO JASPER TORNADO 1150
1150 = 1150 ✅
st %>% select(REFNUM,date,state,county,type,prop,PROPDMG,PROPDMGEXP) %>% slice_max(order_by = prop)
## REFNUM date state county type prop PROPDMG PROPDMGEXP
## 1 605943 2006-01-01 CA NAPA FLOOD 1.15e+11 115 B
115B = 115M ❌
It seems we’ve encountered an error in the data! The B
should be an M. Let’s fix that.
st$PROPDMGEXP[st$REFNUM == 605943] <- "M"
st <- st %>% mutate(prop = PROPDMG * coalesce(multiplier[PROPDMGEXP], 1))
st %>% filter(REFNUM == 605943) %>% select(REFNUM,date,state,county,type,prop,PROPDMG,PROPDMGEXP)
## REFNUM date state county type prop PROPDMG PROPDMGEXP
## 1 605943 2006-01-01 CA NAPA FLOOD 1.15e+08 115 M
115M = 115M ✅
Now let’s check the maximum value in prop after the
correction
st %>% select(REFNUM,date,state,county,type,prop,PROPDMG,PROPDMGEXP) %>% slice_max(order_by = prop)
## REFNUM date state county type prop PROPDMG PROPDMGEXP
## 1 577616 2005-08-29 LA LAZ040 - 059 - 061>064 - 067>070 STORM SURGE 3.13e+10 31.3 B
31.3B = 31.3B ✅
st %>% select(date,state,county,type,crop,CROPDMG,CROPDMGEXP) %>% slice_max(order_by = crop)
## date state county type crop CROPDMG CROPDMGEXP
## 1 2005-08-29 MS MSZ018>019 - 025>066 - 072>074 HURRICANE/TYPHOON 1.51e+09 1.51 B
1.51B = 1.506B ✅
For clarity, let’s start over and consolidate all the data transformations performed above in one code chunk.
multiplier <- c("K" = 1e3, "M" = 1e6, "B" = 1e9)
storms_corrected <- data.frame(storms_orig)
storms_corrected$PROPDMGEXP[storms_corrected$REFNUM == 605943] <- "M" # fix data error
storms <-
storms_corrected %>%
mutate(date = as.Date(BGN_DATE, "%m/%d/%Y"), year = as.integer(format(date, "%Y"))) %>%
filter(year >= 1998) %>%
filter(FATALITIES+INJURIES+PROPDMG+CROPDMG > 0) %>% # exclude harmless events
transmute(
year,
type = EVTYPE %>% str_squish %>% event_mapping[.], # clean event types
dth = FATALITIES,
inj = INJURIES,
dmg = PROPDMG * coalesce(multiplier[PROPDMGEXP], 1) +
CROPDMG * coalesce(multiplier[CROPDMGEXP], 1))
summary(storms)
## year type dth inj dmg
## Min. :1998 THUNDERSTORM WIND:94993 Min. : 0.00000 Min. : 0.0000 Min. :0.00e+00
## 1st Qu.:2001 HAIL :20491 1st Qu.: 0.00000 1st Qu.: 0.0000 1st Qu.:2.50e+03
## Median :2006 FLASH FLOOD :16844 Median : 0.00000 Median : 0.0000 Median :1.00e+04
## Mean :2005 TORNADO :11156 Mean : 0.04194 Mean : 0.2844 Mean :1.48e+06
## 3rd Qu.:2009 LIGHTNING : 9721 3rd Qu.: 0.00000 3rd Qu.: 0.0000 3rd Qu.:3.50e+04
## Max. :2011 FLOOD : 9381 Max. :158.00000 Max. :1150.0000 Max. :3.13e+10
## (Other) :18370
We have three impact variables:
Deaths
Injuries
Damage
… to produce two rankings:
Human Impact
Economic Impact
For Economic Impact, Damage (dmg) already combines both Property Damage and Crop Damage.
For Human Impact, the ranking will combine Deaths with Injuries by valuing 10 injuries as 1 death.
Furthermore, to plot economic impact alongside human impact, $10 million will be scaled as 1 death.
# scaling factors to normalize deaths, injuries, and damage
sf = list(dth = 1, inj = 1/10, dmg = 1/10e6)
This relies on the Guidance on Treatment of the Economic Value of a Statistical Life (VSL) in U.S. Department of Transportation Analyses.5
We produce the rankings by summing across the impact variables, dividing by the number of years to get the yearly average, then sorting by the greatest average for combined Deaths and Injuries (for Human Impact), and by greatest yearly average for Damage (for Economic Impact):
# rank event types by greatest yearly impact average
get_events_ranked <- function(ranking) {
years <- diff(range(storms$year)) + 1 # number of years to divide by to get the average
summarize(storms, across(c(dth, inj, dmg), ~sum(.)/years), .by = type) %>%
arrange(desc( # sort by scaled deaths, injuries, damage and turn on/off based on ranking mode
dth * sf$dth * (ranking %in% c("human", "overall"))
+ inj * sf$inj * (ranking %in% c("human", "overall"))
+ dmg * sf$dmg * (ranking %in% c("economic", "overall"))))
}
This is used to sum the impact variables for each year, to be plotted alongside the the ranked data.
# summarizes data by event types yearly sums
get_events_yearly <- function() {
summarize(storms, across(c(dth, inj, dmg), sum), .by = c(type, year))
}
This prepares the data frame for the plotting function
prepare_events_data <- function(n, ranking) {
# Replaces values that round up to zero with NA to hide from the plot
na_low <- function(x, threshold) ifelse(x < threshold, NA, x)
events_ranked <- get_events_ranked(ranking) # rank event types by greatest yearly impact average
events_yearly <- get_events_yearly() # get event type data for each year
rbind(events_yearly, events_ranked %>% # bind the two to get the yearly data + avg
mutate(year = max(storms$year) + 2)) %>% # simulate year to align ranked events right
filter(type %in% head(unique(events_ranked$type), n)) %>% # choose the top n event types
mutate(type = factor(type, levels = rev(events_ranked$type))) %>% # factorize type to display sorted
mutate(dth = na_low(dth, .5), inj = na_low(inj, .5), dmg = na_low(dmg, 5e6))
}
Helper function to construct the text labels that will appear under each data point.
# creates plot point labels: deaths (injuries) $damage
labelize <- function(dth, inj, dmg) {
paste0(
ifelse(is.na(dth), "", round(dth)), " ",
ifelse(is.na(inj), "", paste0("(", round(inj), ")")), "\n",
# format damage as billions, with two decimal places if less than 1B, 1 otherwise
ifelse(is.na(dmg), "", paste0(round(dmg/1e9, ifelse(dmg < 1e9, 2, 1)), "B")))
}
This is the function called to plot the ranked data, based on the specified ranking strategy:
Overall - human and economic impact
Human - human impact (deaths and injuries)
Economic - economic impact (property and crop damage)
# plots the top n event types sorted by average yearly impact respecting ranking mode
plot_top_events <- function(n, ranking = c("overall", "human", "economic")[1], title, subtitle) {
shp = list(dth = 16, inj = 1, dmg = 15)
clr = list(dth = "red", inj = "black", dmg = "grey")
lbl = list(dth = "Deaths", inj = "(Injuries)", dmg = "$Damage")
events <- prepare_events_data(n, ranking)
plot <- ggplot(events, aes(x = year, y = type)) +
geom_point(aes(size = dmg*sf$dmg), shape = shp$dmg, color = clr$dmg, alpha = 0.7) + # plot damage
geom_point(aes(size = dth*sf$dth), shape = shp$dth, color = clr$dth, alpha = 0.7) + # plot deaths
geom_point(aes(size = inj*sf$inj), shape = shp$inj, color = clr$inj, alpha = 0.7) + # plot injuries
geom_text(aes(year, type, label= labelize(dth, inj, dmg)), vjust= 2, size= 2, color= "grey28") + # labels
scale_size_continuous(
range = c(1, 25), breaks = c(100,100,100), # controls how big the shapes can get
labels = unlist(lbl)) + # legend elements text
scale_x_continuous(
breaks = seq(from=min(events$year), to=max(events$year)), # control x-axis notches (1 notch / year)
labels = append(seq(from=min(events$year), to=max(events$year)-2), # add x-axis notch labels
c("", "Average")), # customize last two notches for Average column
position = "top") + # position x-axis at the top
scale_y_discrete(position = "left", labels = ~paste(rev(seq_along(.)), ".", .)) +
guides(size = guide_legend(override.aes=list(
shape = unlist(shp), color = unlist(clr)))) + # specify legend shapes
labs(x = "", y = "", size = "Legend", title = title,
subtitle = "United States (1998–2011)",
caption = paste0(
"\nScale 100 deaths : 1000 injuries : $1B damage",
"\n\nNational Oceanic and Atmospheric Administration Data,",
" as cached by Coursera (2011/11/30)")) +
theme_minimal() +
theme(
legend.position = "right",
plot.title = element_text(hjust = .5), # center title
plot.subtitle = element_text(hjust = .5), # center subtitle
plot.caption = element_text(hjust = .5, color = "grey50", size = 10), # center subtitle
axis.text.y = element_text(hjust = 0, face = "bold"), # format y-axis labels
panel.grid.major.y = element_line(color = "grey", linewidth = 0.2), # customize y-axis grid lines
panel.grid.minor.x = element_blank(), # hide x-axis grid lines
panel.grid.major.x = element_blank()) # hide x-axis grid lines
plot %>% print %>% suppressWarnings # suppress NA warnings, since we use NA to hide 0 values
}
For the results, we will plot the top 10 ranked event types for both Human Impact and Economic Impact:
plot_top_events(
n = 10, ranking = "human", title = "Figure 2. Weather Events Ranked by Greatest Human Impact")
plot_top_events(
n = 10, ranking = "economic", title = "Figure 3. Weather Events Ranked by Greatest Economic Impact")
# plot_top_events(n = 10, ranking = "overall", title = "Weather Events Ranked by Overall Impact")
In addition to the rankings in the plot, here are some further observations that can be made.
Between January 1, 1998 and November 30, 2011 in the United States:
Tornadoes of 2011 were the most destructive to human life, across all event types and years (500+ deaths, 6000+ injuries), followed by Excessive Heat of 1999 (500+ deaths, 1000+ injuries).6
Hurricanes of 2005 were the most destructive to the economy ($50+ Billion), but interestingly very few deaths and injuries were recorded (30+ deaths, 100+ injuries).7
Excessive Heat, Flash Floods, Rip Currents, have the highest ratio of Death to Injuries (i.e. are highly fatal).
Events with high Human Impact but little recorded Economic Impact: Excessive Heat, Lightning, Rip Currents, Heat.
Events with high Economic Impact but little recorded Human Impact: Hurricanes, Storm Surges, and Droughts.
National Oceanic and Atmospheric Administration. (n.d.). https://www.noaa.gov/↩︎
Reproducible research. (n.d.). Coursera. https://www.coursera.org/learn/reproducible-research↩︎
Storm Data Event Table, NATIONAL WEATHER SERVICE INSTRUCTION 10-1605 AUGUST 17, 2007, National Oceanic & Atmospheric Administration, https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf↩︎
Ncei. (n.d.). Storm Events Database | National Centers for Environmental Information. https://www.ncdc.noaa.gov/stormevents/↩︎
Valuation of a Statistical life Guidance. (n.d.). US Department of Transportation. https://www.transportation.gov/sites/dot.gov/files/docs/2016%20Revised%20Value%20of%20a%20Statistical%20Life%20Guidance.pdf#page=11↩︎
Wikipedia contributors. (2023b, December 19). 2011 Super Outbreak. Wikipedia. https://en.wikipedia.org/wiki/2011_Super_Outbreak↩︎
Bialik, C. (2015, August 26). We still don't know how many people died because of Katrina. FiveThirtyEight. https://fivethirtyeight.com/features/we-still-dont-know-how-many-people-died-because-of-katrina/↩︎