Summary

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.

Data Pre-processing

We will load the data of the NOAA’s database by the following R code.

require(ggplot2)
require(dplyr)
require(gridExtra)
## Loading required package: gridExtra
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
require(cowplot)
## Loading required package: cowplot
## 
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggplot2':
## 
##     ggsave
r <- read.csv("repdata%2Fdata%2FStormData.csv")

Now, we will look at the summary of the dataset by the calling the str() function

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

The following dataset contains 902297 observations and 37 variables. We will not require all these variables. Only a handful of variables will be enough to answer the questions. These variables will be

1.EVTYPE: Type of Event i.e. Tornado, Hurricane, Floods etc.

2.FATALITIES: Harm to human health

3.INJURIES: Harm to human health

4.PROPDMG: Property damage in USD

5.PROPDMGEXP: Magnitude of Property damage in USD(Billions, Millions, etc)

6.CROPDMG: Crop damage in USD

7.CROPDMGEXP: Magnitude of crop damage in USD(Billions, Millions, etc)

We will use select() function of dplyr package to select all these variables from our main dataset.

s <- select(r, EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
str(s)
## 'data.frame':    902297 obs. of  7 variables:
##  $ EVTYPE    : Factor w/ 985 levels "   HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
##  $ 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 ...

What are the number of FATALITIES caused by different types of Events?

To calculate the number of fatalities of the different events we will use FATALITIS column of the selected dataset. The following R code will give us the Events which caused the maximum fatalities.

library(dplyr)
## 
## 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
library(ggplot2)
library(RColorBrewer)
cols <- brewer.pal(8, "Set2")
pal <- colorRampPalette(cols)
gp <- group_by(s, EVTYPE)
gp_fatalities <- summarise(gp, `No. of Deaths` = sum(FATALITIES)) %>% arrange(desc(`No. of Deaths`))  %>% top_n(10)
## Selecting by No. of Deaths
gp_fatalities
## # A tibble: 10 × 2
##            EVTYPE `No. of Deaths`
##            <fctr>           <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
g <- ggplot(gp_fatalities, aes(EVTYPE, `No. of Deaths`))
g + geom_bar(stat = "identity", fill = pal(10)) + coord_flip() +xlab("Event Type") + theme_minimal() + ggtitle("FATALITIES caused by Different types of Events")

What Weather Events caused the most Severe injuries?

The following will show the Top 10 Events that caused the most severe injuries to the population

cols <- brewer.pal(5, "Accent")
pal <- colorRampPalette(cols)
gp <- group_by(s, EVTYPE)
gp_injuries <- summarise(gp, `No. of Injuries` = sum(INJURIES)) %>% arrange(desc(`No. of Injuries`))  %>% top_n(10)
## Selecting by No. of Injuries
gp_injuries
## # A tibble: 10 × 2
##               EVTYPE `No. of Injuries`
##               <fctr>             <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
j <- ggplot(gp_injuries, aes(EVTYPE, `No. of Injuries`))
j + geom_bar(stat = "identity", fill = pal(10)) + coord_flip() +xlab("Event Type") + theme_minimal() + ggtitle("INJURIES caused by Different types of Events")

What are the Events that caused the Greatest Property Damage?

The Economic damage in the dataset is summed upto the Property damage and the crop damage. Now we will convert the PROPDMGEXP and CROPDMGEXP to their related numbers. For example B|b is 9 etc.

##Convert the PROPDMGEXP to character class
s$PROPDMGEXP <- as.character(s$PROPDMGEXP)
s$PROPDMGEXP <- gsub("\\-|\\+|\\?", "0", s$PROPDMGEXP)
s$PROPDMGEXP <- gsub("B|b", "9", s$PROPDMGEXP)
s$PROPDMGEXP <- gsub("M|m", "6", s$PROPDMGEXP)
s$PROPDMGEXP <- gsub("K|k", "3", s$PROPDMGEXP)
s$PROPDMGEXP <- gsub("H|h", "2", s$PROPDMGEXP)
##Convert the PROPDMGEXP to numeric class
s$PROPDMGEXP <- as.numeric(s$PROPDMGEXP)
s$PROPDMGEXP[is.na(s$PROPDMGEXP)] = 0
s$PropertyDamage <- s$PROPDMG * 10^s$PROPDMGEXP
gp <- group_by(s, EVTYPE)
gp_propdamage <- summarise(gp, PropDamage = sum(PropertyDamage)) %>% arrange(desc(PropDamage))
gppdmg <- data.frame(gp_propdamage[1:10, ])
gppdmg
##               EVTYPE   PropDamage
## 1              FLOOD 144657709807
## 2  HURRICANE/TYPHOON  69305840000
## 3            TORNADO  56947380677
## 4        STORM SURGE  43323536000
## 5        FLASH FLOOD  16822673979
## 6               HAIL  15735267513
## 7          HURRICANE  11868319010
## 8     TROPICAL STORM   7703890550
## 9       WINTER STORM   6688497251
## 10         HIGH WIND   5270046295
In the same manner we will convert the CRPDMGEXP
##Convert the cROPDMGEXP to character class
s$CROPDMGEXP <- as.character(s$CROPDMGEXP)
s$CROPDMGEXP <- gsub("\\-|\\+|\\?", "0", s$CROPDMGEXP)
s$CROPDMGEXP <- gsub("B|b", "9", s$CROPDMGEXP)
s$CROPDMGEXP <- gsub("M|m", "6", s$CROPDMGEXP)
s$CROPDMGEXP <- gsub("K|k", "3", s$CROPDMGEXP)
s$CROPDMGEXP <- gsub("H|h", "2", s$CROPDMGEXP)
##Convert the CROPDMGEXP to numeric class
s$CROPDMGEXP <- as.numeric(s$CROPDMGEXP)
s$CROPDMGEXP[is.na(s$CROPDMGEXP)] = 0
s$CropDamage <- s$CROPDMG * 10^s$CROPDMGEXP
gp <- group_by(s, EVTYPE)
gp_cropdamage <- summarise(gp, CropDamage = sum(CropDamage)) %>% arrange(desc(CropDamage))
gpcdmg <- data.frame(gp_cropdamage[1:10, ])
gpcdmg
##               EVTYPE  CropDamage
## 1            DROUGHT 13972566000
## 2              FLOOD  5661968450
## 3        RIVER FLOOD  5029459000
## 4          ICE STORM  5022113500
## 5               HAIL  3025954473
## 6          HURRICANE  2741910000
## 7  HURRICANE/TYPHOON  2607872800
## 8        FLASH FLOOD  1421317100
## 9       EXTREME COLD  1292973000
## 10      FROST/FREEZE  1094086000

The Total Economic Damage caused by these Catastrophes can be given as follows

totdamage <- merge(gp_propdamage, gp_cropdamage)
totdamage$`Total Damage` <- totdamage$PropDamage + totdamage$CropDamage
EVTYPE <- totdamage$EVTYPE
`Total Damage` <- totdamage$`Total Damage`
TOTAL_df <- data.frame(EVTYPE, `Total Damage`)
gptdm <- arrange(TOTAL_df, desc(`Total Damage`))
gptdmg <- gptdm[1:10, ]
gptdmg
##               EVTYPE Total.Damage
## 1              FLOOD 150319678257
## 2  HURRICANE/TYPHOON  71913712800
## 3            TORNADO  57362333947
## 4        STORM SURGE  43323541000
## 5               HAIL  18761221986
## 6        FLASH FLOOD  18243991079
## 7            DROUGHT  15018672000
## 8          HURRICANE  14610229010
## 9        RIVER FLOOD  10148404500
## 10         ICE STORM   8967041360

The Total, Property & Crop Damage incured by Different Events is shown in the following plots

library(ggplot2)
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
cols <- brewer.pal(10, "Spectral")
pal <- colorRampPalette(cols)
prop <- ggplot(gppdmg, aes(EVTYPE, PropDamage)) + geom_bar(stat = "identity", fill = pal(10)) + xlab("Event Type") + theme(axis.text.x = element_text(angle = 90)) + ylab("Property Damage ($)") + ggtitle("Top 10 Events Causing Most Property Damage")

crop <- ggplot(gpcdmg, aes(EVTYPE, CropDamage)) + geom_bar(stat = "identity", fill = pal(10)) + xlab("Event Type") + theme(axis.text.x = element_text(angle = 90)) + ylab("Crop Damage ($)") + ggtitle("Top 10 Events Causing Most Crop Damage")

tot <- ggplot(gptdmg, aes(EVTYPE, Total.Damage)) + geom_bar(stat = "identity", fill = pal(10)) + xlab("Event Type") + theme(axis.text.x = element_text(angle = 90)) + ylab("Total Economic Damage ($)") + ggtitle("Top 10 Events Causing Most Economic Damage")
grid.arrange(prop ,crop ,tot, ncol = 3)

RESULTS

Hence we can say from the above Analysis that

1.TORNADO had the largest number of FATALITIES and INJURIES

2.FLOOD did the most Property Damage

3.Drought did the most Crop Damage

4.FLOOD did the most Economic Damage