Synopsis

This project analyses the storm database from the U.S. National Oceanic and Atmospheric Administration (NOAA) to find which type of weather events cause most damage to population health and which has the largest economic consequesnses in the Unites States between 1950-2011. Damage to the population health is measured by number of fatalities and injuries. Economic consequences are measured by damages to properties and crops. Tornades causes most fatalities and injuries and floods caused the largest economic consequences.

Load relevant packages

First we load the necessary packages into our R session.

library(plyr)
library(tidyverse)

Data Processing

The data was downloaded from the course website:

Storm Data [47MB]

The documentation for the database is available at the below links:

The databse covers events from 1950 to 2011. Fewer events were generallt recorded in earlier years due to lack of good records. Recent years should be more complete.

Loading data into R

The data was downloaded from the above mentioned wesite and then loaded into R.

data <- read.csv("Storm Data.bzip2")

Inspecting the data

head(data)
##   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
## 4       1   6/8/1951 0:00:00     0900       CST     89    MADISON    AL TORNADO
## 5       1 11/15/1951 0:00:00     1500       CST     43    CULLMAN    AL TORNADO
## 6       1 11/15/1951 0:00:00     2000       CST     77 LAUDERDALE    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
## 4         0                                               0         NA
## 5         0                                               0         NA
## 6         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
## 4         0                       0.0   100 2   0          0        2     2.5
## 5         0                       0.0   150 2   0          0        2     2.5
## 6         0                       1.5   177 2   0          0        6     2.5
##   PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1          K       0                                         3040      8812
## 2          K       0                                         3042      8755
## 3          K       0                                         3340      8742
## 4          K       0                                         3458      8626
## 5          K       0                                         3412      8642
## 6          K       0                                         3450      8748
##   LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1       3051       8806              1
## 2          0          0              2
## 3          0          0              3
## 4          0          0              4
## 5          0          0              5
## 6          0          0              6
str(data)
## '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 ...
sum(is.na(df))
## Warning in is.na(df): is.na() applied to non-(list or vector) of type 'closure'
## [1] 0

Subsetting the data

We select only the columns needed in this analysis.

# Select tthe variables we need in this analysis
df <- data %>%
        select(EVTYPE,
               FATALITIES,
               INJURIES,
               PROPDMG,
               PROPDMGEXP,
               CROPDMG,
               CROPDMGEXP)

Data transformation

Damages are stored in two columns with the base in one column and the exponent in another column. This makes it impractical for analysis so we will transform the two base/exp columns into one with the numerical value for both damages to property and crops.

# convert exp columns into numbers: K = 1000, M = 1000000 etc
unique(df$PROPDMGEXP)
##  [1] "K" "M" ""  "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"
df$PROPDMGEXP <- mapvalues(df$PROPDMGEXP, 
          from = c( "K", "M", "" , "B", "m", "+", "0", "5", "6", "?", "4", "2", "3", "h", "7", "H", "-", "1", "8"),
            to = c(10^3, 10^6, 1, 10^9, 10^6, 0, 1, 10^5, 10^6, 0, 10^4, 10^2, 10^3, 10^2, 10^7, 10^2, 0, 10, 10^8))
df$PROPDMGEXP <- as.numeric(df$PROPDMGEXP)

unique(df$CROPDMGEXP)
## [1] ""  "M" "K" "m" "B" "?" "0" "k" "2"
df$CROPDMGEXP <- mapvalues(df$CROPDMGEXP, 
                           from = c("", "M", "K", "m", "B", "?", "0", "k", "2"),
                             to = c(0, 10^6, 10^3, 10^6, 10^9, 10^0, 10^0, 10^3, 10^2))
df$CROPDMGEXP <- as.numeric(df$CROPDMGEXP)


# create new columns PROPMDGTOTAL and CROPDMGTOTAL with actual values
df$PROPDMGTOTAL <- df$PROPDMG * df$PROPDMGEXP
df$CROPDMGTOTAL <- df$CROPDMG * df$CROPDMGEXP

Since fatalities and injuries together measure the harmful effects on population health we will add these together and store in one column HEALTH_TOT. We will do the same for damages on property and crops and store the total value in one column ECONOMIC_TOT.

# create one column for health impact and one for economic impact
df_totals <- df %>% 
        mutate(HEALTH_TOT = FATALITIES + INJURIES,
               ECONOMIC_TOT = PROPDMGTOTAL + CROPDMGTOTAL)

Results

Weather events most harmful to population health

# Across the United States, which types of events are most harmful 
# with respect to population health?

agg_health <- with(df_totals, aggregate(HEALTH_TOT ~ EVTYPE, FUN = sum))
health_impact <- agg_health[order(-agg_health$HEALTH_TOT), ][1:10,]

ggplot(health_impact, aes(x = reorder(EVTYPE, -HEALTH_TOT), y = HEALTH_TOT, fill = EVTYPE)) +
    geom_bar(stat = "identity") +
    labs(title = "Total Number of Fatalities and Injuries Due to Severe Weather                    Events in the US 1950-2011",
         y = "Fatalities and injuries",
         x = "") +
    theme(axis.text.x = element_text(angle = 45, hjust = 1))

Weather events with greatest economic consequences

agg_economic <- with(df_totals, aggregate(ECONOMIC_TOT ~ EVTYPE, FUN = sum))
economic_impact <- agg_economic[order(-agg_economic$ECONOMIC_TOT), ][1:10,]

ggplot(economic_impact, aes(x = reorder(EVTYPE, -ECONOMIC_TOT), y = ECONOMIC_TOT, fill = EVTYPE)) +
    geom_bar(stat = "identity") +
    labs(title = "Total Economic Damages Due to Severe Weather Events in the US                    1950-2011",
         y = "total cost for damage on property and crop",
         x = "") +
    theme(axis.text.x = element_text(angle = 45, hjust = 1))

1-3 plots