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.
First, we load the data into R and check to see what we’re dealing with.
storm <- read.csv("repdata_data_StormData.csv")
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/ 436774 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 ...
Now that we know what our dataset looks like, we load the packages to be used to analyze the dataset.
library(dplyr)
library(ggplot2)
We are tasked to answer two questions for this activity:
Which types of events are most harmful to population health?
Which types of events have the greatest economic consequences?
Let’s tackle the first one.
In the dataset, the indicators for harm are number of fatalities and number of injuries, coded as FATALITIES AND INJURIES. We’ll be making bar graphs to easily see which kind of calamity or event did the most harm. To do this, we get each of the total fatalities and injuries per event. After, we get the event with the top fatalities and injuries.
harmful <- storm %>% group_by(EVTYPE) %>%
summarize(fatalities.sum= sum(FATALITIES), injuries.sum = sum(INJURIES))
fatalities <- arrange(harmful, -fatalities.sum)
top.fatalities <- head(fatalities, n=7)
injuries <- arrange(harmful, -injuries.sum)
top.injuries <- head(injuries, n=7)
We can now plot the events with the most number of fatalities and injuries. We set scipen to 5 to remove the scientific notation for the axis labels.
options(scipen=5)
barplot(top.fatalities$fatalities.sum, names.arg=top.fatalities$EVTYPE, ylim=range(0,6000),
las=2, cex.names=0.5, main="Most Fatal Events")
barplot(top.injuries$injuries.sum, names.arg=top.injuries$EVTYPE, ylim=range(0,100000),
las=2, cex.names=0.5, main="Events with Most Injuries")
In the dataset, the indicators for economic consequence are property damage and crop damage coded as PROPDMG and CROPDMG. They both have corresponding exponents that help translate whether the values are in hundreds (H), thousands(K), millions (M) or billions (B).
We take a look at the exponents columns.
unique(storm$CROPDMGEXP)
## [1] M K m B ? 0 k 2
## Levels: ? 0 2 B k K m M
unique(storm$PROPDMGEXP)
## [1] K M B m + 0 5 6 ? 4 2 3 h 7 H - 1 8
## Levels: - ? + 0 1 2 3 4 5 6 7 8 B h H K m M
As we can see, the data for the columns are untidy. We only take the ones with H, K, M or B values.
storm.dmg <- storm[which(storm$PROPDMGEXP == "H" | storm$PROPDMGEXP == "K" |
storm$PROPDMGEXP == "M" | storm$PROPDMGEXP == "m" |
storm$PROPDMGEXP == "B" | storm$CROPDMGEXP == "H" |
storm$CROPDMGEXP == "K" | storm$CROPDMGEXP == "M" |
storm$CROPDMGEXP == "m" | storm$CROPDMGEXP == "B") , ]
storm.dmg <- select(storm.dmg,EVTYPE,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP)
We then convert the codes to its numerical values so we can multiply it to the corresponding PROPDMG and CROPDMG value to get the real cost of damage. We set NAs since we need every value to be numerical to perform arithmetic on it.
storm.dmg$PROPDMGEXP <- gsub("H", 100, storm.dmg$PROPDMGEXP)
storm.dmg$PROPDMGEXP <- gsub("K", 1000, storm.dmg$PROPDMGEXP)
storm.dmg$PROPDMGEXP <- gsub("[Mm]", 10^6, storm.dmg$PROPDMGEXP)
storm.dmg$PROPDMGEXP <- gsub("B", 10^9, storm.dmg$PROPDMGEXP)
storm.dmg$PROPDMGEXP<- as.numeric(storm.dmg$PROPDMGEXP)
storm.dmg$PROPDMGEXP<- ifelse(is.na(storm.dmg$PROPDMGEXP), 0, storm.dmg$PROPDMGEXP)
storm.dmg$CROPDMGEXP <- gsub("H", 100, storm.dmg$CROPDMGEXP)
storm.dmg$CROPDMGEXP <- gsub("K", 1000, storm.dmg$CROPDMGEXP)
storm.dmg$CROPDMGEXP <- gsub("[Mm]", 10^6, storm.dmg$CROPDMGEXP)
storm.dmg$CROPDMGEXP <- gsub("B", 10^9, storm.dmg$CROPDMGEXP)
storm.dmg$CROPDMGEXP<- as.numeric(storm.dmg$CROPDMGEXP)
storm.dmg$CROPDMGEXP<- ifelse(is.na(storm.dmg$CROPDMGEXP), 0, storm.dmg$CROPDMGEXP)
We get the total damage by first, multiplying PROPDMG and CROPDMG to its corresponding exponents and then adding them with each other.
storm.dmg$total.dmg <- (storm.dmg$PROPDMG*storm.dmg$PROPDMGEXP)+(storm.dmg$CROPDMG*storm.dmg$CROPDMGEXP)
We then get the total damage per event and we only take the top 7 events.
costly <- storm.dmg %>% group_by(EVTYPE) %>%
summarize(total.dmg= sum(total.dmg)/10^9)
costly <- arrange(costly, -total.dmg)
top.costly <- head(costly, n=7)
We can now plot events vs damage cost.
barplot(top.costly$total.dmg, names.arg=top.costly$EVTYPE, ylim=range(0,160),
las=2, cex.names=0.5, ylab = "Damage Cost (in billions)",
main="Events with the Greatest Economic Consequences")
As seen below, tornadoes are the most harmful event by a very great margin. They are both the most fatal most injury-causing. However, despite the marginally lower fatality count, excessive heat and flash floods aren’t to be dismissed with about a 1000-2000 death count. They both also have a high injury count together with TSTM wind.
Floods costs the most in terms of damage at around $150 billion, followed by typhoon and tornado.