Synopsis

Severe weather events can result in economic and public health problems. Using the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database, we identify the chief causes of weather-related fatalities, injuries, and damage to property and crops. Data from the calendar years 1982 through 2011 (inclusive) are summarized and presented.

Loading R packages

library(knitr);
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(lubridate);

Data Processing

Downloading file from web

download.file("http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", "stormData.csv.bz2")

Loading the compressed file StormData.csv.bz2 into R

stormData <- read.csv("stormData.csv.bz2"
                      ,header = TRUE
                      ,na.strings = ""
                      ,stringsAsFactors = FALSE
                      );

Transforming raw data into datasets useful to our analyses

  1. Calculate dtYear as the year in which each event occured and filter out years prior to 1982 (i.e., keep only most recent 30 years’ data)
  2. Calculate monetary values of Property and Crop Damage, decoding (PROPDMGEXP and CROPDMGEXP) as follows: H/h = 100, K/k = 1000, M/m = million, and B/b = billion
  3. Summarize Fatalities, Injuries, Property Damage, and Crop Damage annually (.ie., from 1982 - 2011)
myData <- mutate(stormData, beginDate = as.Date(BGN_DATE, "%m/%d/%Y %H:%M:%S")) %>%
        mutate(dtYear = year(beginDate)) %>%
        filter(dtYear > 1981) %>%
        mutate(propDamage = ifelse(PROPDMGEXP=="H" | PROPDMGEXP=="h"
                                   ,PROPDMG * 100
                                   ,ifelse(PROPDMGEXP=="K" | PROPDMGEXP=="k"
                                           ,PROPDMG * 1000
                                           ,ifelse (PROPDMGEXP=="M" | PROPDMGEXP=="m"
                                                    ,PROPDMG * 1000000
                                                    ,ifelse (PROPDMGEXP=="B" | PROPDMGEXP=="b"
                                                             ,PROPDMG * 1000000000
                                                             ,0))))) %>%
         mutate(cropDamage = ifelse(CROPDMGEXP=="H" | CROPDMGEXP=="h"
                                   ,CROPDMG * 100
                                   ,ifelse(CROPDMGEXP=="K" | CROPDMGEXP=="k"
                                           ,CROPDMG * 1000
                                           ,ifelse (CROPDMGEXP=="M" | CROPDMGEXP=="m"
                                                    ,CROPDMG * 1000000
                                                    ,ifelse (CROPDMGEXP=="B" | CROPDMGEXP=="b"
                                                             ,CROPDMG * 1000000000
                                                             ,0))))) %>%
        group_by(EVTYPE);

byType <- summarise(myData, FATALITIES = sum(FATALITIES), INJURIES = sum(INJURIES),
                    propDamage = sum(propDamage), cropDamage = sum(cropDamage));

Methods

Population Health

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

  1. Define “population health” as FATALITIES and INJURIES, reported separately, in thousands of persons/lives
  2. Determine top 10 causes of FATALITIES and INJURIES from 1982 to 2001
# sort in ascending order and take tail to easily produce descending order charts later
fatTop10 <- arrange(byType, FATALITIES) %>%
        filter(!is.na(FATALITIES)) %>%
        mutate(thousFat = FATALITIES/1000) %>%
        tail(10);
injTop10 <- arrange(byType, INJURIES) %>%
        filter(!is.na(INJURIES)) %>%
        mutate(thousInj = INJURIES/1000) %>%
        tail(10);

Economic Consequences

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

  1. Define “economic consequences” as “Damage” to Property and Crops, reported separately, in millions of US dollars
  2. Determine top 10 causes of Property and Crop Damage from 1982 to 2001
# sort in ascending order and take tail to easily produce descending order charts later
pdmgTop10 <- arrange(byType, propDamage) %>%
        filter(!is.na(propDamage)) %>%
        mutate(millPropDmg = propDamage/1000000) %>%
        tail(10);
cdmgTop10 <- arrange(byType, cropDamage) %>%
        filter(!is.na(cropDamage)) %>%
        mutate(millCropDmg = cropDamage/1000000) %>%
        tail(10);

Results

Illustrated here are the top 10 causes of fatalities and injuries due to storm events:

## is this section redundant, perhaps?
par(mfrow = c(2,1))     # stack two charts in one figure
par(las = 1)            # make all label text horizontal
par(mar = c(5,9,4,2))   # increase y-axis margin.

with(
        fatTop10, barplot(
                thousFat, main = "Top 10 Causes of Weather-related Fatalities\nUnited States 1982 - 2011", horiz = TRUE, names.arg  = EVTYPE, cex.names = 0.6, xlab = "1000's of Persons"
        )
);

with(
        injTop10, barplot(
                thousInj, main = "Top 10 Causes of Weather-related Injuries\nUnited States 1982 - 2011", horiz = TRUE, names.arg  = EVTYPE, cex.names = 0.6, xlab = "1000's of Persons"
        )
);

The following show the top 10 causes of property and crop damage due to storm events:

par(mfrow = c(2,1))     # stack two charts in one figure
par(las = 1)            # make all label text horizontal
par(mar = c(5,9,4,2))   # increase y-axis margin.

with(
        pdmgTop10, barplot(
                millPropDmg, main = "Top 10 Causes of Weather-related Property Damage\nUnited States 1982 - 2011", horiz = TRUE, names.arg  = EVTYPE, cex.names = 0.6, xlab = "Millions of U.S Dollars"
        )
);

with(
        cdmgTop10, barplot(
                millCropDmg, main = "Top 10 Causes of Weather-related Crop Damage\nUnited States 1982 - 2011", horiz = TRUE, names.arg  = EVTYPE, cex.names = 0.6, xlab = "Millions of U.S Dollars"
        )
);