In this report, we look at the national storm data produced by the National Weather Service. The data covered period from 1950 to 2011. In particular, the data are used to identify the events that are most harmful to population health and the events that have the greatest economic consequences. Based on the analysis, tornado is the most harmful event both to population health and property/crop. The analysis will be further explained in the Results section.
We first download the data and read into R. Then we’ll look at the data to get an initial understanding of what’s included.
# Load necessary packages
library(dplyr)
# Downloading and reading in the data
setwd("C:/Users/George/WorkingDir")
addr <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(addr, destfile = "./ReproducibleResearch2/stormdata.bz2",
method = "internal", setInternet2(use = TRUE))
storm <- read.csv("./ReproducibleResearch2/stormdata.bz2")
# Get a sense of what's in the data
dim(storm)
## [1] 902297 37
head(storm)
## 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
str(storm)
## 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
## $ BGN_TIME : Factor w/ 3608 levels "00:00:00 AM",..: 272 287 2705 1683 2584 3186 242 1683 3186 3186 ...
## $ TIME_ZONE : Factor w/ 22 levels "ADT","AKS","AST",..: 7 7 7 7 7 7 7 7 7 7 ...
## $ COUNTY : num 97 3 57 89 43 77 9 123 125 57 ...
## $ COUNTYNAME: Factor w/ 29601 levels "","5NM E OF MACKINAC BRIDGE TO PRESQUE ISLE LT MI",..: 13513 1873 4598 10592 4372 10094 1973 23873 24418 4598 ...
## $ STATE : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
## $ EVTYPE : Factor w/ 985 levels " HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
## $ BGN_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ BGN_AZI : Factor w/ 35 levels ""," N"," NW",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_LOCATI: Factor w/ 54429 levels "","- 1 N Albion",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_DATE : Factor w/ 6663 levels "","1/1/1993 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_TIME : Factor w/ 3647 levels ""," 0900CST",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ 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 : Factor w/ 24 levels "","E","ENE","ESE",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_LOCATI: Factor w/ 34506 levels "","- .5 NNW",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ 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: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ WFO : Factor w/ 542 levels ""," CI","$AC",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ STATEOFFIC: Factor w/ 250 levels "","ALABAMA, Central",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ ZONENAMES : Factor w/ 25112 levels ""," "| __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
## $ 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 : Factor w/ 436781 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
# Extract the data we need
dat <- select(storm, EVTYPE, FATALITIES, INJURIES, PROPDMG, CROPDMG)
head(dat)
## EVTYPE FATALITIES INJURIES PROPDMG CROPDMG
## 1 TORNADO 0 15 25.0 0
## 2 TORNADO 0 0 2.5 0
## 3 TORNADO 0 2 25.0 0
## 4 TORNADO 0 2 2.5 0
## 5 TORNADO 0 2 2.5 0
## 6 TORNADO 0 6 2.5 0
# Group the data by type for further analysis
dat.by.type <- group_by(dat, EVTYPE)
# Summarize by calculating the average for the variables
sum.dat <- summarise(dat.by.type, total.fatality = sum(FATALITIES, na.rm = T), total.injury = sum(INJURIES, na.rm = T), total.property.damage = sum(PROPDMG, na.rm = T), total.crop.damage = sum(CROPDMG, na.rm = T))
sum.dat
## Source: local data frame [985 x 5]
##
## EVTYPE total.fatality total.injury total.property.damage
## 1 HIGH SURF ADVISORY 0 0 200
## 2 COASTAL FLOOD 0 0 0
## 3 FLASH FLOOD 0 0 50
## 4 LIGHTNING 0 0 0
## 5 TSTM WIND 0 0 108
## 6 TSTM WIND (G45) 0 0 8
## 7 WATERSPOUT 0 0 0
## 8 WIND 0 0 0
## 9 ? 0 0 5
## 10 ABNORMAL WARMTH 0 0 0
## .. ... ... ... ...
## Variables not shown: total.crop.damage (dbl)
# Add a new column to combine damages and replace the EVTYPE column with a new column named "event.type" with the character class
sum.dat.new <- mutate(sum.dat, total.damages = total.property.damage + total.crop.damage, event.type = EVTYPE)
sum.dat.new <- select(sum.dat.new, event.type, total.fatality, total.injury, total.property.damage, total.crop.damage, total.damages)
# Convert the data into a data frame and change the event.type class to character for easier later manipulations
sum.dat.new <- as.data.frame(sum.dat.new)
sum.dat.new$event.type = as.character(sum.dat.new$event.type)
class(sum.dat.new)
## [1] "data.frame"
class(sum.dat.new$event.type)
## [1] "character"
# Sort data based on damages
sum.dat.damage <- arrange(sum.dat.new, desc(total.damages), desc(total.property.damage), desc(total.crop.damage))
# Filter out the top 10 events in terms of total damages
sum.dat.damage <- slice(sum.dat.damage, 1:10)
top.damage.events <- sum.dat.damage$event.type
# Sort data based on fatalities and filter out top 10 events
sum.dat.fatality <- arrange(sum.dat.new, desc(total.fatality))
sum.dat.fatality <- slice(sum.dat.fatality, 1:10)
top.fatality.events <- sum.dat.fatality$event.type
# Sort data based on injuries and filter out top 10 events
sum.dat.injury <- arrange(sum.dat.new, desc(total.injury))
sum.dat.injury <- slice(sum.dat.injury, 1:10)
top.injury.events <- sum.dat.injury$event.type
# List and plot the top fatality events
top.fatality.events
## [1] "TORNADO" "EXCESSIVE HEAT" "FLASH FLOOD" "HEAT"
## [5] "LIGHTNING" "TSTM WIND" "FLOOD" "RIP CURRENT"
## [9] "HIGH WIND" "AVALANCHE"
barplot(sum.dat.fatality$total.fatality, names.arg = sum.dat.fatality$event.type, main = "Top Fatality Events")
# List and plot the top injury events
top.injury.events
## [1] "TORNADO" "TSTM WIND" "FLOOD"
## [4] "EXCESSIVE HEAT" "LIGHTNING" "HEAT"
## [7] "ICE STORM" "FLASH FLOOD" "THUNDERSTORM WIND"
## [10] "HAIL"
barplot(sum.dat.injury$total.injury, names.arg = sum.dat.injury$event.type, main = "Top Injury Events")
So, based on the data, we can conclude that the event types that are most harmful to population health is tornado since it’s the top event in terms of both fatality and injury across the United States. And the common events in both categories, i.e. the top most harmful events are found below:
# Find the common top events between fatality and injury
intersect(top.fatality.events, top.injury.events)
## [1] "TORNADO" "EXCESSIVE HEAT" "FLASH FLOOD" "HEAT"
## [5] "LIGHTNING" "TSTM WIND" "FLOOD"
When it comes to damages, the top events in terms of combined damages is also Tornado. Here, we also find the top 10 events as below.
# List the top damage events
top.damage.events
## [1] "TORNADO" "FLASH FLOOD" "TSTM WIND"
## [4] "HAIL" "FLOOD" "THUNDERSTORM WIND"
## [7] "LIGHTNING" "THUNDERSTORM WINDS" "HIGH WIND"
## [10] "WINTER STORM"
# Plot the top damage events
barplot(sum.dat.damage$total.damage, names.arg=sum.dat.damage$event.type, main = "Top Damage Events")