1. Synopsis

Severe weather events can have a huge impact on public health and the economy of communities and municipalities in the United States. Understanding the impact of these events will facilitate preventative strategies for reducing fatalities, injuries and property damaged.

The current project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database, which contains data on characteristics of major storms and weather events, when and where they occur, as well as estimates of any fatalities, injuries, and property damage, as a result of these events. The objective is to identify and answer these questions:

Tornadoes caused the highest number of harmful events for public health. Flood caused the greatest economic consequence to damaged crops, while floods was the highest cause for damaged properties.

1.1 Data

The data has been collected from 1950 to the end of November 2011.

Information about the data can be found at; https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf

2. Data Processing

2.1 Reading in the data

#Loading necessary packages
library(ggplot2)
library(knitr)
## Warning: package 'knitr' was built under R version 4.5.3
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
#Reading in the CSV-file containing the data to R
df <- read.csv("repdata_data_StormData.csv", stringsAsFactors = F)

2.2 Exploring the variables

colnames(df)
##  [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"

2.3 Selecting variables for analysis

The variables needed for the analysis will be selected and put into another dataset and used for downstream analysis:

  • For Public health: FATALITIES, INJURIES

  • For measuring economic consequences: PROPDMG (property damage), PROPDMGEXP (exponent of property damage), CROPDMG (crop damage), CROPDMGEXP (exponent of crop damage)

  • Weather events: EVTYPE

wk_df <- select(df, EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP, FATALITIES, INJURIES)

2.4 Converting the exponents column

The exponents columns, PROPDMGEXP and CROPDMGEXP have values such as ““, M, K, m, B, H, k, h, +, -, ?. These will be converted to numeric values and used for calculating the costs of property and crop damage. The new exponents will be put into a new column in the dataset.

# Checking which values are in the exponents columns
unique(wk_df$PROPDMGEXP) 
##  [1] "K" "M" ""  "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"
unique(wk_df$CROPDMGEXP)
## [1] ""  "M" "K" "m" "B" "?" "0" "k" "2"
# Converting the exponents to numeric and putting it in a new column
wk_df$pdmg_exp <- case_when(
    wk_df$PROPDMGEXP == "H" ~ 10^2,
    wk_df$PROPDMGEXP == "h" ~ 10^2,
    wk_df$PROPDMGEXP == "K" ~ 10^3,
    wk_df$PROPDMGEXP == "M" ~ 10^6,
    wk_df$PROPDMGEXP == "m" ~ 10^6,
    wk_df$PROPDMGEXP == "B" ~ 10^9,
    wk_df$PROPDMGEXP == ""  ~ 10^0,
    wk_df$PROPDMGEXP == "?" ~ 10^0,
    wk_df$PROPDMGEXP == "+" ~ 10^0,
    wk_df$PROPDMGEXP == "-" ~ 10^0,
    !is.na(as.numeric(wk_df$PROPDMGEXP)) ~ as.numeric(wk_df$PROPDMGEXP))
## Warning in eval_tidy(pair$lhs, env = default_env): NAs introduced by coercion
## Warning in eval_tidy(pair$rhs, env = default_env): NAs introduced by coercion
wk_df$cdmg_exp <- case_when(
    wk_df$CROPDMGEXP == "K" ~ 10^3,
    wk_df$CROPDMGEXP == "k" ~ 10^3,
    wk_df$CROPDMGEXP == "M" ~ 10^6,
    wk_df$CROPDMGEXP == "m" ~ 10^6,
    wk_df$CROPDMGEXP == "B" ~ 10^9,
    wk_df$CROPDMGEXP == "" ~ 10^0,
    wk_df$CROPDMGEXP == "?" ~ 10^0,
    !is.na(as.numeric(wk_df$CROPDMGEXP)) ~ as.numeric(wk_df$CROPDMGEXP))
## Warning in eval_tidy(pair$lhs, env = default_env): NAs introduced by coercion
## Warning in eval_tidy(pair$lhs, env = default_env): NAs introduced by coercion
# Checking if any NA's were introduced after the conversion
table(is.na(wk_df$pdmg_exp))
## 
##  FALSE 
## 902297
table(is.na(wk_df$cdmg_exp))
## 
##  FALSE 
## 902297

2.5 Making Damage cost columns

The damage columns will be multiplied with the exponents columns to create a cost column for each damage type

# Making damage cost columns
wk_df <- mutate(wk_df,
                prop_cost=PROPDMG * pdmg_exp,
                crop_cost=CROPDMG * cdmg_exp)

3. Data Analysis

3.1 Harm to public health

# Calculating total harm to public health
Tot_harm <- wk_df %>%
    group_by(EVTYPE) %>%
    summarise(tot_fatalities = sum(FATALITIES, na.rm = TRUE),
              tot_injuries = sum(INJURIES, na.rm = TRUE))

# Arrange the Tot_harm to get the top 10 highest fatalities and injuries
top10_fatalities <- Tot_harm %>% arrange(desc(tot_fatalities)) %>% select(EVTYPE, tot_fatalities) %>% head(10)
top10_injuries <- Tot_harm %>% arrange(desc(tot_injuries)) %>% select(EVTYPE, tot_injuries) %>% head(10)

#Combining the top 10 fatalities and injuries into one dataset for creating plots
top10_fatalities <- top10_fatalities %>%  rename(Total="tot_fatalities") %>% mutate(measure="FATALITIES")
top10_injuries <-top10_injuries %>% rename(Total="tot_injuries") %>% mutate(measure="INJURIES")
top10_harm <- rbind(top10_fatalities, top10_injuries)

3.2 Greatest economic consequences

# Calculating total economic expenditures
Tot_expenses <- wk_df %>%
    group_by(EVTYPE) %>%
    summarise(tot_prop = sum(prop_cost, na.rm = TRUE),
              tot_crop = sum(crop_cost, na.rm = TRUE))

# Arrange the Tot_expenses to get the top 10 highest property and crop damage cost
top10_pcost <- Tot_expenses %>% arrange(desc(tot_prop)) %>% select(EVTYPE, tot_prop) %>% head(10)
top10_ccost <- Tot_expenses %>% arrange(desc(tot_crop)) %>% select(EVTYPE, tot_crop) %>% head(10)

#Combining the top 10 property and crop damage cost into one dataset for creating plots
top10_pcost <- top10_pcost %>%  rename(Total="tot_prop") %>% mutate(measure="PROPDMG_cost")
top10_ccost <-top10_ccost %>% rename(Total="tot_crop") %>% mutate(measure="CROPDMG_cost")

top10_cost <- rbind(top10_pcost, top10_ccost)

4. Result

4.1 Harm to public health

# Making barplots to compare most harmful events according to fatalities and injuries
ggplot(top10_harm, aes(EVTYPE, Total)) +
    geom_col() +
    labs(y="Frequency", x="Weather Event", title="Most frequent harm caused by weather event") +
    facet_wrap(.~measure, ncol=2, scale="free") +
    theme_classic() +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) 
Top 10 weather events causing the highest number of harmful evens in the United States.

Top 10 weather events causing the highest number of harmful evens in the United States.

4.2 Greatest economic consequences

ggplot(top10_cost, aes(EVTYPE, Total)) +
    geom_col() +
    labs(y="Cost (USD)", x="Weather Event", title="Greatest economic consequences caused by weather event") +
    scale_y_continuous(labels = scales::comma) +
    facet_wrap(.~measure, ncol=2, scale="free") +
    theme_classic() +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) 
Top 10 weather events causing the greatest economic consequences in the United States.

Top 10 weather events causing the greatest economic consequences in the United States.