Storm Data Analysis

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.

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.

What is this analysis about?

The basic goal of this analysis 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.

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?

Data Processing

library(ggplot2)
library(knitr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(grid)
library(gridExtra)
opts_chunk$set(cache = TRUE)
download.file('http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2', 'StormData.csv.bz2')
raw_data <- read.csv(bzfile("StormData.csv.bz2"))
names(raw_data)
##  [1] "STATE__"    "BGN_DATE"   "BGN_TIME"   "TIME_ZONE"  "COUNTY"    
##  [6] "COUNTYNAME" "STATE"      "EVTYPE"     "BGN_RANGE"  "BGN_AZI"   
## [11] "BGN_LOCATI" "END_DATE"   "END_TIME"   "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE"  "END_AZI"    "END_LOCATI" "LENGTH"     "WIDTH"     
## [21] "F"          "MAG"        "FATALITIES" "INJURIES"   "PROPDMG"   
## [26] "PROPDMGEXP" "CROPDMG"    "CROPDMGEXP" "WFO"        "STATEOFFIC"
## [31] "ZONENAMES"  "LATITUDE"   "LONGITUDE"  "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS"    "REFNUM"
head(raw_data)
##   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
fatal_inj <- aggregate(cbind(FATALITIES, INJURIES) ~ EVTYPE, data = raw_data, sum)
# clean property damage column
prop_damage <-subset(raw_data, raw_data$PROPDMGEXP %in% c('B','M','m','K'))

# keep only EVTYPE, PROPDMG and PROPDMGEXP
prop_damage <- select(prop_damage,c(EVTYPE,PROPDMG,PROPDMGEXP))

# covert PROPDMGEXP into characters
prop_damage$PROPDMGEXP  <- as.character(prop_damage$PROPDMGEXP)

#Using PROPDMGEXP and PROPDMG add andother field that calculates the real amount of damage
prop <- mutate(prop_damage, prop_cost = ifelse(PROPDMGEXP == 'K' , PROPDMG*1000,
                                       ifelse(PROPDMGEXP %in% c('M','m') , PROPDMG*1000000,
                                              ifelse(PROPDMGEXP == 'B' , PROPDMG*1000000000,0))))

# sum for each event type
prop_damage_by_event <- aggregate(prop_cost ~ EVTYPE, data = prop, sum)

# sort
prop_sorted <- arrange(prop_damage_by_event, -prop_cost)
top_prop_sorted <- head(prop_sorted, 20)
# clean dataset for only crop damage
crop <-subset(raw_data, raw_data$CROPDMGEXP %in% c('B','M','m','K','k'))

# create new df only using  EVTYPE,CROPDMG,CROPDMGEXP
crop <- select(crop,c(EVTYPE,CROPDMG,CROPDMGEXP))

# convert CROPDMGEXP into characters
crop$CROPDMGEXP  <- as.character(crop$CROPDMGEXP)

# create "cost" column with damage cost in dollars (not thousands, millions or bilions)
crop <- mutate(crop, crop_cost = ifelse(CROPDMGEXP %in% c('K','k') , CROPDMG*1000,
                            ifelse(CROPDMGEXP %in% c('M','m') , CROPDMG*1000000,
                            ifelse(CROPDMGEXP == 'B' , CROPDMG*1000000000,0))))
# sum for each event type
crop_damage_by_event <- aggregate(crop_cost ~ EVTYPE, data = crop, sum)

# sort
crop_sorted <- arrange(crop_damage_by_event, -crop_cost)
top_crop_sorted <- head(crop_sorted, 20)
top_crop_sorted
##               EVTYPE   crop_cost
## 1            DROUGHT 13972566000
## 2              FLOOD  5661968450
## 3        RIVER FLOOD  5029459000
## 4          ICE STORM  5022113500
## 5               HAIL  3025954450
## 6          HURRICANE  2741910000
## 7  HURRICANE/TYPHOON  2607872800
## 8        FLASH FLOOD  1421317100
## 9       EXTREME COLD  1292973000
## 10      FROST/FREEZE  1094086000
## 11        HEAVY RAIN   733399800
## 12    TROPICAL STORM   678346000
## 13         HIGH WIND   638571300
## 14         TSTM WIND   554007350
## 15    EXCESSIVE HEAT   492402000
## 16            FREEZE   446225000
## 17           TORNADO   414953110
## 18 THUNDERSTORM WIND   414843050
## 19              HEAT   401461500
## 20          WILDFIRE   295472800
# merge datasets by EVTYPE. Dataset sizes are different so there are will be NA's after merging
merged <- merge(crop_sorted, prop_sorted, by = 'EVTYPE', all = TRUE)

# convert NA's into 0
merged$prop_cost[is.na(merged$prop_cost)] <- 0
merged <- mutate(merged, TOTAL = prop_cost + crop_cost)
merged <- arrange(merged, -TOTAL)

# top 20 destractive events
h_merged <- head(merged,20)

Results

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

Most harmful types of events in US for population

head(fatal_inj, 30)
##                            EVTYPE FATALITIES INJURIES
## 1                               ?          0        0
## 2                  ABNORMALLY DRY          0        0
## 3                  ABNORMALLY WET          0        0
## 4                 ABNORMAL WARMTH          0        0
## 5            ACCUMULATED SNOWFALL          0        0
## 6             AGRICULTURAL FREEZE          0        0
## 7                   APACHE COUNTY          0        0
## 8          ASTRONOMICAL HIGH TIDE          0        0
## 9           ASTRONOMICAL LOW TIDE          0        0
## 10                       AVALANCE          1        0
## 11                      AVALANCHE        224      170
## 12                   BEACH EROSIN          0        0
## 13                  Beach Erosion          0        0
## 14                  BEACH EROSION          0        0
## 15    BEACH EROSION/COASTAL FLOOD          0        0
## 16                    BEACH FLOOD          0        0
## 17     BELOW NORMAL PRECIPITATION          0        0
## 18              BITTER WIND CHILL          0        0
## 19 BITTER WIND CHILL TEMPERATURES          0        0
## 20                      Black Ice          0        0
## 21                      BLACK ICE          1       24
## 22                       BLIZZARD        101      805
## 23 BLIZZARD AND EXTREME WIND CHIL          0        0
## 24        BLIZZARD AND HEAVY SNOW          0        0
## 25         BLIZZARD/FREEZING RAIN          0        0
## 26            BLIZZARD/HEAVY SNOW          0        0
## 27             BLIZZARD/HIGH WIND          0        0
## 28               Blizzard Summary          0        0
## 29               BLIZZARD WEATHER          0        0
## 30          BLIZZARD/WINTER STORM          0        0
# sort FATALITIES from most destractive and take top 20
fatal_inj <- arrange(fatal_inj, -FATALITIES)
h_fatal_inj <- head(fatal_inj, 20)

# sort EVTYPE from most destractive to less destactive in fatalities
fatal_levels <- h_fatal_inj$EVTYPE
h_fatal_inj$EVTYPE <- factor(h_fatal_inj$EVTYPE, levels = fatal_levels)

# create plot 1
p1 <- ggplot(h_fatal_inj, aes(EVTYPE, FATALITIES)) + 
  geom_point(color = 'blue', size = 4) +
  theme(axis.text.x = element_text(angle = 30, hjust = 1))

# sort INJURIES from most destractive and take top 20
fatal_inj <- arrange(fatal_inj, -INJURIES)
h_fatal_inj <- head(fatal_inj, 20)

# sort EVTYPE from most destractive to less destactive in injuries
inj_levels <- h_fatal_inj$EVTYPE
h_fatal_inj$EVTYPE <- factor(h_fatal_inj$EVTYPE, levels = inj_levels)

# create plot 2
p2 <- ggplot(h_fatal_inj, aes(EVTYPE, INJURIES)) + 
  geom_point(color = 'green', size = 4) +
  theme(axis.text.x = element_text(angle = 30, hjust = 1))

# combine two plots in one figure
grid.arrange(p1, p2, ncol = 1, main = "Top-20 destractive events in US")

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

Most harmful types of events in US for property and crop

top_prop_sorted
##                       EVTYPE    prop_cost
## 1                      FLOOD 144657709800
## 2          HURRICANE/TYPHOON  69305840000
## 3                    TORNADO  56937160480
## 4                STORM SURGE  43323536000
## 5                FLASH FLOOD  16140811510
## 6                       HAIL  15732266720
## 7                  HURRICANE  11868319010
## 8             TROPICAL STORM   7703890550
## 9               WINTER STORM   6688497250
## 10                 HIGH WIND   5270046260
## 11               RIVER FLOOD   5118945500
## 12                  WILDFIRE   4765114000
## 13          STORM SURGE/TIDE   4641188000
## 14                 TSTM WIND   4484928440
## 15                 ICE STORM   3944927810
## 16         THUNDERSTORM WIND   3483121140
## 17            HURRICANE OPAL   3172846000
## 18          WILD/FOREST FIRE   3001829500
## 19 HEAVY RAIN/SEVERE WEATHER   2500000000
## 20        THUNDERSTORM WINDS   1735952850
top_crop_sorted
##               EVTYPE   crop_cost
## 1            DROUGHT 13972566000
## 2              FLOOD  5661968450
## 3        RIVER FLOOD  5029459000
## 4          ICE STORM  5022113500
## 5               HAIL  3025954450
## 6          HURRICANE  2741910000
## 7  HURRICANE/TYPHOON  2607872800
## 8        FLASH FLOOD  1421317100
## 9       EXTREME COLD  1292973000
## 10      FROST/FREEZE  1094086000
## 11        HEAVY RAIN   733399800
## 12    TROPICAL STORM   678346000
## 13         HIGH WIND   638571300
## 14         TSTM WIND   554007350
## 15    EXCESSIVE HEAT   492402000
## 16            FREEZE   446225000
## 17           TORNADO   414953110
## 18 THUNDERSTORM WIND   414843050
## 19              HEAT   401461500
## 20          WILDFIRE   295472800
h_merged
##                EVTYPE   crop_cost    prop_cost        TOTAL
## 1               FLOOD  5661968450 144657709800 150319678250
## 2   HURRICANE/TYPHOON  2607872800  69305840000  71913712800
## 3             TORNADO   414953110  56937160480  57352113590
## 4         STORM SURGE        5000  43323536000  43323541000
## 5                HAIL  3025954450  15732266720  18758221170
## 6         FLASH FLOOD  1421317100  16140811510  17562128610
## 7             DROUGHT 13972566000   1046106000  15018672000
## 8           HURRICANE  2741910000  11868319010  14610229010
## 9         RIVER FLOOD  5029459000   5118945500  10148404500
## 10          ICE STORM  5022113500   3944927810   8967041310
## 11     TROPICAL STORM   678346000   7703890550   8382236550
## 12       WINTER STORM    26944000   6688497250   6715441250
## 13          HIGH WIND   638571300   5270046260   5908617560
## 14           WILDFIRE   295472800   4765114000   5060586800
## 15          TSTM WIND   554007350   4484928440   5038935790
## 16   STORM SURGE/TIDE      850000   4641188000   4642038000
## 17  THUNDERSTORM WIND   414843050   3483121140   3897964190
## 18     HURRICANE OPAL    19000000   3172846000   3191846000
## 19   WILD/FOREST FIRE   106796830   3001829500   3108626330
## 20 THUNDERSTORM WINDS   190654700   1735952850   1926607550
# create levels for plot
crop_prop_levels <- h_merged$EVTYPE
h_merged$EVTYPE <- factor(h_merged$EVTYPE, levels = crop_prop_levels)


ggplot(h_merged, aes(EVTYPE, TOTAL)) + 
  geom_point(color = 'red', size = 4) +
  theme(axis.text.x = element_text(angle = 30, hjust = 1))