Synopsis

This analysis is based on the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database, which tracks characteristics of major storms and weather events in the United States, including estimates of any fatalities, injuries, and property damage.

The goal of this analysis is to answer key questions about the impact of storm and weather events on US population health and their economic consequences.

Data Processing

Loading libraries required for the analysis

  library(R.utils)
## Loading required package: R.oo
## Loading required package: R.methodsS3
## R.methodsS3 v1.8.0 (2020-02-14 07:10:20 UTC) successfully loaded. See ?R.methodsS3 for help.
## R.oo v1.23.0 successfully loaded. See ?R.oo for help.
## 
## Attaching package: 'R.oo'
## The following object is masked from 'package:R.methodsS3':
## 
##     throw
## The following objects are masked from 'package:methods':
## 
##     getClasses, getMethods
## The following objects are masked from 'package:base':
## 
##     attach, detach, load, save
## R.utils v2.9.2 successfully loaded. See ?R.utils for help.
## 
## Attaching package: 'R.utils'
## The following object is masked from 'package:utils':
## 
##     timestamp
## The following objects are masked from 'package:base':
## 
##     cat, commandArgs, getOption, inherits, isOpen, nullfile, parse,
##     warnings
  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(ggplot2)

Creating and setting working directory

  setwd("/Users/user/Documents/Data Science Specialisation/Rerpoducible_Research")
  if(!file.exists("./US_Storm_Data")){dir.create("./US_Storm_Data")}
  setwd("./US_Storm_Data")

Downloading the database and supporting documents

  URLbz2 <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
  download.file(URLbz2, "StormData.csv.bz2", method = "curl")

  bunzip2("StormData.csv.bz2", "StormData.csv")
  
  URLpdf1 <- "https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf"
  download.file(URLpdf1, "Storm Data Documentation.pdf", method = "curl")
  
  URLpdf2 <- "https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2FNCDC%20Storm%20Events-FAQ%20Page.pdf"
  download.file(URLpdf2, "FAQ.pdf", method = "curl")

Loading data into R

  df <- read.csv("StormData.csv")
  str(df)
## '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 ""," Christiansburg",..: 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 ""," CANTON"," TULIA",..: 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","%SD",..: 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 "","\t","\t\t",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...

Data Analysis

1. Types of events that are most harmful with respect to population health across the United States.

Here we are selecting all health-related outcomes and summarise them by type of weather event. Total health damage is a sum of injuries and fatalities.

  Health <- c("FATALITIES", "INJURIES")
  
  Health_damage <- df %>% 
    select(EVTYPE, all_of(Health)) %>% 
    group_by(EVTYPE) %>%
    summarise(count = n(),
              Injuries = sum(INJURIES, na.rm = TRUE),
              Fatalities = sum(FATALITIES, na.rm = TRUE)) %>%
    mutate(Total_health = Injuries + Fatalities) %>%
    arrange(-Total_health)

2. Types of events that have the greatest economic consequences across the United States.

Recoding multiplier varible for poperty and crop damage into numeric values

df <- df %>% mutate_at(vars(PROPDMGEXP,CROPDMGEXP),
                         funs(as.numeric(dplyr::recode(.,'0'=1,'1'=10,'2'=100,'3'=1000,'4'=10000,'5'=100000,
                                            '6'=1000000,'7'=10000000,'8'=100000000, 'B'=1000000000,
                                            'h'=100,'H'=100, 'k'=1000,'K'=1000,'m'=1000000,'M'=1000000,
                                            ' '=0,'-'=0,'?'=0,'+'=0))))
## Warning: funs() is soft deprecated as of dplyr 0.8.0
## Please use a list of either functions or lambdas: 
## 
##   # Simple named list: 
##   list(mean = mean, median = median)
## 
##   # Auto named with `tibble::lst()`: 
##   tibble::lst(mean, median)
## 
##   # Using lambdas
##   list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once per session.

Creating Total Damage variable as a sum of property and crop damage multiplied by numeric multiplier created above

  Economic <- c("PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")
  
  Economic_damage <- df %>% 
    select(EVTYPE, all_of(Economic)) %>%
    mutate(PROPDMG = PROPDMG * PROPDMGEXP,
           CROPDMG = CROPDMG * CROPDMGEXP) %>%
    group_by(EVTYPE) %>%
    summarise(count = n(),
              PROPDMG = sum(PROPDMG, na.rm = TRUE),
              CROPDMG = sum(CROPDMG, na.rm = TRUE)) %>%
    mutate(TOTALDMG = PROPDMG + CROPDMG) %>%
    arrange(-TOTALDMG)

Results

1. Types of events that are most harmful with respect to population health across the United States.

  knitr::kable(Health_damage[1,],  caption = "max health damage")
max health damage
EVTYPE count Injuries Fatalities Total_health
TORNADO 60652 91346 5633 96979
  ggplot(Health_damage[1:10,], aes(x=reorder(EVTYPE, -Total_health), y = Total_health)) + 
    geom_bar(stat="identity", fill = "cyan4") +
    ggtitle("Top 10 Events with Highest Total Health Damage") + 
    labs(x="Event type", y="Total health damage") +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))

2. Types of events that have the greatest economic consequences across the United States.

  knitr::kable(Economic_damage[1,],  caption = "max economic damage")
max economic damage
EVTYPE count PROPDMG CROPDMG TOTALDMG
FLOOD 25326 144657709800 5661968450 150319678250
  ggplot(Economic_damage[1:10,], aes(x=reorder(EVTYPE, -TOTALDMG), y = TOTALDMG)) + 
    geom_bar(stat="identity", fill = "cyan4") +
    ggtitle("Top 10 Events with Highest Total Economic Damage") + 
    labs(x="Event type", y="Total economic damage") +
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))