INTRODUCTION

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.

ASSIGNMENT

The basic goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events. You must use the database to answer the questions below and show the code for your entire analysis. Your analysis can consist of tables, figures, or other summaries. You may use any R package you want to support your analysis.

QUESTIONS

Your data analysis must address the following questions:

  1. Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
  2. Across the United States, which types of events have the greatest economic consequences?

SYNOPSIS

This assignment 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. We assed two questions:1) which types of events are most harmful with respect to population health and 2) hich types of events have the greatest economic consequences. We first process, summarizes, transform and create new data variables when necessary to respond the questions above. In order to answer the questions, we subset the dataset by selecting key variables. The selected variables include: EVent type (EVTYPE), FATALITIES, INJURIES and cost related varibles including propery and crop damages with their respecive data unit (i.e millions, thousands, billions). The result show that accross the USA, Tornado is the most fatal events and main cause of injuries. On the other hand, Flood related events lead others in terms of major economic consequences.

DATA PROCESSING

The data is downloaded from the Storm Data course website and saved as ‘StormData.csv’

DOWNLOADING OF DATA

if(!file.exists("StormData.csv.bz2")) {
URL <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(URL, destfile="StormData.csv.bz2")
}

LOADING DATA

Aftre the data are downloaded and saved in my working directory, the next step is to load data into R.

myData <- read.csv("StormData.csv.bz2")
head (myData, 3)
##   STATE__          BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE  EVTYPE
## 1       1 4/18/1950 0:00:00     0130       CST     97     MOBILE    AL TORNADO
## 2       1 4/18/1950 0:00:00     0145       CST      3    BALDWIN    AL TORNADO
## 3       1 2/20/1951 0:00:00     1600       CST     57    FAYETTE    AL TORNADO
##   BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1         0                                               0         NA
## 2         0                                               0         NA
## 3         0                                               0         NA
##   END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1         0                      14.0   100 3   0          0       15    25.0
## 2         0                       2.0   150 2   0          0        0     2.5
## 3         0                       0.1   123 2   0          0        2    25.0
##   PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1          K       0                                         3040      8812
## 2          K       0                                         3042      8755
## 3          K       0                                         3340      8742
##   LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1       3051       8806              1
## 2          0          0              2
## 3          0          0              3

EXPLORING THE DATA

str(myData)
## '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 ...

TRANSFORMING DATE

myData$BGN_DATE <- as.Date(myData$BGN_DATE, "%m/%d/%Y %H:%M:%S")
myData$END_DATE <- as.Date(myData$END_DATE, "%m/%d/%Y %H:%M:%S")

RESULT

1. Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?

Let us subset a database that would respond to the above questions. In the dataset, the variables that would indicate harmful effects of events with respect to population health are: FATALITIES and INJURIES.

library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
subData <- myData %>%
          select (EVTYPE, FATALITIES, INJURIES) %>% 
          group_by(EVTYPE) %>% 
          summarize(TotalFatalities = sum(FATALITIES),TotalInjuries = sum(INJURIES), .groups = 'drop') 

We then subset fatalities and injuries separately. First let’s start with the worst events.

Fatalities <- subData %>% select(EVTYPE, TotalFatalities) %>% arrange(desc(TotalFatalities))
topFatalities <- head(Fatalities,10)
topFatalities
## # A tibble: 10 x 2
##    EVTYPE         TotalFatalities
##    <fct>                    <dbl>
##  1 TORNADO                   5633
##  2 EXCESSIVE HEAT            1903
##  3 FLASH FLOOD                978
##  4 HEAT                       937
##  5 LIGHTNING                  816
##  6 TSTM WIND                  504
##  7 FLOOD                      470
##  8 RIP CURRENT                368
##  9 HIGH WIND                  248
## 10 AVALANCHE                  224

Second, we take the top five events in terms of number of injuries to people.

Injuries <- subData %>% select(EVTYPE, TotalInjuries) %>% arrange(desc(TotalInjuries))
topInjuries <- head(Injuries,10)
topInjuries
## # A tibble: 10 x 2
##    EVTYPE            TotalInjuries
##    <fct>                     <dbl>
##  1 TORNADO                   91346
##  2 TSTM WIND                  6957
##  3 FLOOD                      6789
##  4 EXCESSIVE HEAT             6525
##  5 LIGHTNING                  5230
##  6 HEAT                       2100
##  7 ICE STORM                  1975
##  8 FLASH FLOOD                1777
##  9 THUNDERSTORM WIND          1488
## 10 HAIL                       1361

THE PLOT

par(mfrow = c(1,2))
#barplot of the top ten events to cause injuries in USA
with(topInjuries, barplot(TotalInjuries, 
                              main = "Top ten leading events of injuries in USA",
                              ylab = "# of injuries in thousands",
                          names = topInjuries$EVTYPE,
                          col = "pink",
                          border = "pink",
                          las = 2,
                          cex.names = 0.6,
                          cex.main = 1,
                          cex.axis = 0.8,
                          cex.lab = 0.8))

#bar plot of the top ten fatal events in USA
with(topFatalities, barplot(TotalFatalities,
                                main = "Top ten fatal events in USA",
                                ylab = "# of deaths in thousands",
                            names = topFatalities$EVTYPE,
                            col = "black",
                            las = 2,
                            cex.names = .6,
                            cex.main = 1,
                            cex.axis = 0.8,
                            cex.lab = 0.8))

2. Across the United States, which types of events have the greatest economic consequences?

We first find out the variables that would show the economic impact of event. The PROPDMG, CROPDMG and their unit as reported in PROPDMGEXP and CROPDMGEXP, respectively.

So, we subset the datasets with respect to the identified variables

subEconomic <- myData %>% select(EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)

We then create a new variable, TotalDamage that add together the damages on property and crop. We also sort the TotalDamage column to get events with the greatest economic consequences.

#Let's first group the dataset by events and sort them to get the event with greatest economic consequences
grouped_EcoDmg <- subEconomic %>% group_by(EVTYPE) %>% mutate(Total = PROPDMG + CROPDMG) %>%
  summarise(TotalDamage= sum(Total), .groups = "drop") %>% 
  arrange(desc(TotalDamage))

# Let us just collect top 10 events.
top_economicDamage <- head(grouped_EcoDmg, 10)
top_economicDamage
## # A tibble: 10 x 2
##    EVTYPE             TotalDamage
##    <fct>                    <dbl>
##  1 TORNADO               3312277.
##  2 FLASH FLOOD           1599325.
##  3 TSTM WIND             1445168.
##  4 HAIL                  1268290.
##  5 FLOOD                 1067976.
##  6 THUNDERSTORM WIND      943636.
##  7 LIGHTNING              606932.
##  8 THUNDERSTORM WINDS     464978.
##  9 HIGH WIND              342015.
## 10 WINTER STORM           134700.

We then plot the bar chart of the above dataset

par(mai = c(0.9, 2, 0.5, 0.8))
with(top_economicDamage, barplot(TotalDamage/1000000, 
                                 main = "Top 10 events with the greatest economic consequences",
                                 ylab = "$ million",
                                 names.arg = EVTYPE,
                                 las = 2,
                                 cex.names = 0.6,
                                 col = "blue",
                                 border = "blue"))