In this report the aim is to describe which severe weather types that are most harmful on population health and has greatest ecomic cosequences in US. To investigate this data from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database is used including data from 1950 and end in November 2011. From this data it is found that tornados is the weather event that causes the majority of fatalities and injuries. For economic damage, flood is the weather event causing most damage, followed by hurricanes/typhons and tornados.
The data analysis aims at answering following questions:
Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
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.
The data for this assignment come in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size. The file is downloaded from the course web site.
There is also some documentation of the storm database. Information on how variables are constructed/defined can be found here:
National Weather Service Storm Data Documentation
National Climatic Data Center Storm Events FAQ
The events in the database start in the year 1950 and end in November 2011. In the earlier years of the database there are generally fewer events recorded, most likely due to a lack of good records. More recent years should be considered more complete.
library(dplyr)
library(ggplot2)
Load the data to the stormdata data frame and have a look on it.
fileUrl <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(fileUrl, destfile = "StormData.csv.bz2")
stormdata <- read.csv("StormData.csv.bz2")
str(stormdata)
## '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 ...
There are two variables in the data that are related to health, FATALITIES and INJURIES. Both variables indicate number of people affected.
The variables PROPDMG and CROPDMG are used to indicate the damage on property and crops. Both variables are entered as dollars and used together with the variables PROPDMGEXP and CROPDMGEXP, which include alphabetical characters used to signify magnitude, “K” for thousands, “M” for millions, and “B” for billions.
Check if theere are any missing values in variables.
sum(is.na(stormdata$EVTYPE))
## [1] 0
sum(is.na(stormdata$FATALITIES))
## [1] 0
sum(is.na(stormdata$INJURIES))
## [1] 0
sum(is.na(stormdata$PROPDMG))
## [1] 0
sum(is.na(stormdata$CROPDMG))
## [1] 0
sum(is.na(stormdata$PROPDMGEXP))
## [1] 0
sum(is.na(stormdata$CROPDMGEXP))
## [1] 0
There are no missing values.
Check what is in the variables PROPDMGEXP and CROPDMGEXP.
table(stormdata$PROPDMGEXP)
##
## - ? + 0 1 2 3 4 5 6
## 465934 1 8 5 216 25 13 4 4 28 4
## 7 8 B h H K m M
## 5 1 40 1 6 424665 7 11330
table(stormdata$CROPDMGEXP)
##
## ? 0 2 B k K m M
## 618413 7 19 1 9 21 281832 1 1994
It is expected to see only the characters “K”, “M” and “B” or nothing ("“), but as we can see there are some other characters as well, most likely typos. The number other unexpected characters is not very large so most likely they are not significant for the end result. Here it is assumed that small letters really means large letters, i.e. ”k" is “K”, “m” is “M”. All other characters are assumed to be blank.
Replace alphabetical characters in PROPDMGEXP and CROPDMGEXP with numbers. Create variables for property-, crop- and total economic damage (in millions of dollars).
# Replace alphabetic characters with numeric, use "1" for blank spaces and typos.
stormdata$PROPDMGEXP2 <- as.numeric(c("k" = "1e3", "K" = "1e3", "m" = "1e6", "M" = "1e6", "B" = "1e9")[stormdata$PROPDMGEXP])
stormdata$PROPDMGEXP2[is.na(stormdata$PROPDMGEXP2)] <- 1
stormdata$CROPDMGEXP2 <- as.numeric(c("k" = "1e3", "K" = "1e3", "m" = "1e6", "M" = "1e6", "B" = "1e9")[stormdata$CROPDMGEXP])
stormdata$CROPDMGEXP2[is.na(stormdata$CROPDMGEXP2)] <- 1
# Create new variables
stormdata <- mutate(stormdata, propertyDmg = PROPDMG*PROPDMGEXP2)
stormdata <- mutate(stormdata, cropDmg = CROPDMG*CROPDMGEXP2)
# economic damage in millions of dollars
stormdata <- mutate(stormdata, economicDmg = (propertyDmg + cropDmg)/1e6)
Aggregate fatalities and injuries over event types. Filter data frame and save the 10 most severe events.
fatal_events <- aggregate(FATALITIES~EVTYPE, stormdata, sum)
injuries_events <- aggregate(INJURIES~EVTYPE, stormdata, sum)
# Sort the data frames in descending order
fatal_events <- fatal_events[order(-fatal_events$FATALITIES),]
injuries_events <- injuries_events[order(-injuries_events$INJURIES),]
# Use only the 10 most severe events
fatal_events <- head(fatal_events, n=10)
injuries_events <- head(injuries_events, n=10)
Aggregate economic damage over event types. Filter data frame and save the 10 most severe events.
economicDmg_events <- aggregate(economicDmg~EVTYPE, stormdata, sum)
# Sort the data frame in descending order
economicDmg_events <- economicDmg_events[order(-economicDmg_events$economicDmg),]
# Use only the 10 most severe events
economicDmg_events <- head(economicDmg_events, n=10)
Plot fatalities due to severe weather
ggplot(fatal_events, aes(x=reorder(EVTYPE, -FATALITIES), y=FATALITIES)) +
geom_bar(stat = "identity", fill="red") +
theme(axis.text.x = element_text(angle = 90)) +
labs(title = "Top 10 Severe Weather Fatalities in US",
subtitle = "NOAA Storm Database, year 1950 to November 2011",
x="Weather event type",
y="Number of Fatalities")
From the plot above it is seen that tornados is the dominating cause for fatalities due to sever weather events in US.
Plot injuries due to severe weather
ggplot(injuries_events, aes(x=reorder(EVTYPE, -INJURIES), y=INJURIES)) +
geom_bar(stat = "identity", fill="blue") +
theme(axis.text.x = element_text(angle = 90)) +
labs(title = "Top 10 Severe Weather Injuries in US",
subtitle = "NOAA Storm Database, year 1950 to November 2011",
x="Weather event type",
y="Number of Injuries")
As for fatalities, it is seen from the plot above that tornados is the dominating cause for injuries due to sever weather events in US.
Plot economic damage due to severe weather
ggplot(economicDmg_events, aes(x=reorder(EVTYPE, -economicDmg), y=economicDmg)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90)) +
labs(title = "Top 10 Severe Weather Economic Damage in US",
subtitle = "NOAA Storm Database, year 1950 to November 2011",
x="Weather event type",
y="Damage in millions of $")
It is seen from the plot above that flood is the weather event causing most economic damage in US.