Setting Global Options

## Warning: package 'knitr' was built under R version 4.2.3

Analysis on which events are the most harmful to population health and which events have the greatest economic consequences

Introduction

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.

Synopsis

In this report, we aim to address 2 questions:

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

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

To address these questions, we obtained data from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database, from 1950 till November 2011. We found that Tornadoes pose the greatest risk to population health, causing the highest number of fatalities and injuries. In addition, Tornadoes have the most significant economic impact, resulting in damage to properties and crops.

Data Processing

From the NOAA storm database, we obtained data on major storms and weather events which happened in the United States, from 1950 till November 2011.

Check if the directory exists

We first check if the directory “Dataset” which is used to store the dataset exists. If the directory does not exist, we will create it.

if (!file.exists("Dataset")) {
    dir.create("Dataset")
}

Download the data into directory

Once the directory “Dataset” has been created, we downloaded the dataset into the directory (to save a copy on the computer), and load the dataset into R.

Url = "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(Url, destfile = "./Dataset/StormData.csv")

Load the data into R

StormData <- read.csv("./Dataset/StormData.csv")

We check the first few rows of the dataset after reading the dataset in. There are 902,297 rows in the dataset.

dim(StormData)

[1] 902297 37

library(xtable)

head <- xtable(head(StormData))
print(head, type = "html")
STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
1 1.00 4/18/1950 0:00:00 0130 CST 97.00 MOBILE AL TORNADO 0.00 0.00 0.00 14.00 100.00 3 0.00 0.00 15.00 25.00 K 0.00 3040.00 8812.00 3051.00 8806.00 1.00
2 1.00 4/18/1950 0:00:00 0145 CST 3.00 BALDWIN AL TORNADO 0.00 0.00 0.00 2.00 150.00 2 0.00 0.00 0.00 2.50 K 0.00 3042.00 8755.00 0.00 0.00 2.00
3 1.00 2/20/1951 0:00:00 1600 CST 57.00 FAYETTE AL TORNADO 0.00 0.00 0.00 0.10 123.00 2 0.00 0.00 2.00 25.00 K 0.00 3340.00 8742.00 0.00 0.00 3.00
4 1.00 6/8/1951 0:00:00 0900 CST 89.00 MADISON AL TORNADO 0.00 0.00 0.00 0.00 100.00 2 0.00 0.00 2.00 2.50 K 0.00 3458.00 8626.00 0.00 0.00 4.00
5 1.00 11/15/1951 0:00:00 1500 CST 43.00 CULLMAN AL TORNADO 0.00 0.00 0.00 0.00 150.00 2 0.00 0.00 2.00 2.50 K 0.00 3412.00 8642.00 0.00 0.00 5.00
6 1.00 11/15/1951 0:00:00 2000 CST 77.00 LAUDERDALE AL TORNADO 0.00 0.00 0.00 1.50 177.00 2 0.00 0.00 6.00 2.50 K 0.00 3450.00 8748.00 0.00 0.00 6.00

Let’s trim the dataset to get the columns that we need.

NewDataset <- StormData[, c("BGN_DATE", "EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]

## Print out the table to view
headNewDataset <- xtable(head(NewDataset))
print(headNewDataset, type = "html")
BGN_DATE EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
1 4/18/1950 0:00:00 TORNADO 0.00 15.00 25.00 K 0.00
2 4/18/1950 0:00:00 TORNADO 0.00 0.00 2.50 K 0.00
3 2/20/1951 0:00:00 TORNADO 0.00 2.00 25.00 K 0.00
4 6/8/1951 0:00:00 TORNADO 0.00 2.00 2.50 K 0.00
5 11/15/1951 0:00:00 TORNADO 0.00 2.00 2.50 K 0.00
6 11/15/1951 0:00:00 TORNADO 0.00 6.00 2.50 K 0.00

Fatalities and Injuries Data

## Subset the "NewDataset" to create a new dataset for fatalities and injuries
Population_Impact <- subset(NewDataset, !NewDataset$FATALITIES == 0 | !NewDataset$INJURIES == 0, select = c(EVTYPE, FATALITIES, INJURIES))

## Print out the table to view
headPopulationImpact <- xtable(head(Population_Impact))
print(headPopulationImpact, type = "html")
EVTYPE FATALITIES INJURIES
1 TORNADO 0.00 15.00
3 TORNADO 0.00 2.00
4 TORNADO 0.00 2.00
5 TORNADO 0.00 2.00
6 TORNADO 0.00 6.00
7 TORNADO 0.00 1.00

Property and Crop Damage Data

## Subset the "NewDataset" to create a new dataset for property damages and crop damages
Economic_Impact <- subset(NewDataset, !NewDataset$PROPDMG == 0 | !NewDataset$CROPDMG == 0, select = c(EVTYPE, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP))

## Print out the table to view
headEconomicImpact <- xtable(head(Economic_Impact))
print(headEconomicImpact, type = "html")
EVTYPE PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
1 TORNADO 25.00 K 0.00
2 TORNADO 2.50 K 0.00
3 TORNADO 25.00 K 0.00
4 TORNADO 2.50 K 0.00
5 TORNADO 2.50 K 0.00
6 TORNADO 2.50 K 0.00

Results

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

Let’s first prepare the data to see which events are the most harmful to humans, in terms of fatalities and injuries.

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
## Group the total number of fatalities and injuries by event type
Population_Impact <- Population_Impact %>%
                            group_by(EVTYPE) %>%
                            summarise(across(everything(), sum))

## Fatalities Data
Fatalities <- Population_Impact %>% 
                    select(EVTYPE, FATALITIES)

## Injuries Data
Injuries <- Population_Impact %>%
                    select(EVTYPE, INJURIES)

## Print out the table to view
headFatalities <- xtable(head(Fatalities))
print(headFatalities, type = "html")
EVTYPE FATALITIES
1 AVALANCE 1.00
2 AVALANCHE 224.00
3 BLACK ICE 1.00
4 BLIZZARD 101.00
5 BLOWING SNOW 1.00
6 BRUSH FIRE 0.00
## Print out the table to view
headInjuries <- xtable(head(Injuries))
print(headInjuries, type = "html")
EVTYPE INJURIES
1 AVALANCE 0.00
2 AVALANCHE 170.00
3 BLACK ICE 24.00
4 BLIZZARD 805.00
5 BLOWING SNOW 13.00
6 BRUSH FIRE 2.00

Now, let’s plot two charts to view which events are the most harmful to humans, in terms of fatalities and injuries.

## Fatalities Plot (Show the top 10 events)
library(ggplot2)

top_n(Fatalities, n = 10, FATALITIES) %>%
    ggplot(., aes(x = EVTYPE, y = FATALITIES, fill = EVTYPE)) +
    geom_bar(stat = "identity") +
    xlab("Event Types") + 
    ylab("Number of Fatalities") +
    ggtitle("Top 10 Events Related Fatalities") + 
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))

## Injuries Plot (Show the top 10 events)
top_n(Injuries, n = 10, INJURIES) %>%
    ggplot(., aes(x = EVTYPE, y = INJURIES, fill = EVTYPE)) +
    geom_bar(stat = "identity") +
    xlab("Event Types") + 
    ylab("Number of Injuries") +
    ggtitle("Top 10 Events Related Injuries") + 
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))

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

Let’s first prepare the data to see which events have the greatest economic consequences.

## Convert the SI Units into number for PROPDMGEXP
Economic_Impact$PROPDMGEXP <- gsub("h", 1e+02, Economic_Impact$PROPDMGEXP)
Economic_Impact$PROPDMGEXP <- gsub("K", 1e+03, Economic_Impact$PROPDMGEXP)
Economic_Impact$PROPDMGEXP <- gsub("m", 1e-03, Economic_Impact$PROPDMGEXP)
Economic_Impact$PROPDMGEXP <- gsub("M", 1e+06, Economic_Impact$PROPDMGEXP)
Economic_Impact$PROPDMGEXP <- as.numeric(Economic_Impact$PROPDMGEXP)

## Convert the SI Units into number for CROPDMGEXP
Economic_Impact$CROPDMGEXP <- gsub("K", 1e+03, Economic_Impact$CROPDMGEXP)
Economic_Impact$CROPDMGEXP <- gsub("k", 1e+03, Economic_Impact$CROPDMGEXP)
Economic_Impact$CROPDMGEXP <- gsub("m", 1e-03, Economic_Impact$CROPDMGEXP)
Economic_Impact$CROPDMGEXP <- gsub("M", 1e+06, Economic_Impact$CROPDMGEXP)
Economic_Impact$CROPDMGEXP <- as.numeric(Economic_Impact$CROPDMGEXP)

## Replace all NAs rows with 0
Economic_Impact[is.na(Economic_Impact)] <- 0

## Calculate the total amount of damage (property damage + crop damage) for each event type
Economic_Impact$TOTALDMG <- (Economic_Impact$PROPDMG * Economic_Impact$PROPDMGEXP) + (Economic_Impact$CROPDMG * Economic_Impact$CROPDMGEXP)

## Group the total amount of damage by event type
Economic_Impact <- Economic_Impact %>%
                            group_by(EVTYPE) %>%
                            summarise(TOTALDMG = sum(TOTALDMG))

## Print out the table to view
headDamage <- xtable(head(Economic_Impact))
print(headDamage, type = "html")
EVTYPE TOTALDMG
1 HIGH SURF ADVISORY 200000.00
2 FLASH FLOOD 50000.00
3 TSTM WIND 8100000.00
4 TSTM WIND (G45) 8000.00
5 ? 5000.00
6 AGRICULTURAL FREEZE 28820000.00

Now, let’s plot the chart to view which events have the greatest economic consequences.

## Property Damage and Crop Damage Plot (Show the top 10 events)

top_n(Economic_Impact, n = 10, TOTALDMG) %>%
    ggplot(., aes(x = EVTYPE, y = TOTALDMG, fill = EVTYPE)) +
    geom_bar(stat = "identity") +
    xlab("Event Types") + 
    ylab("Total Amount of Damages") +
    ggtitle("Top 10 Events Related Damages") + 
    theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))

Summary

Based on the plots, Tornadoes pose the greatest risk to population health, causing the highest number of fatalities and injuries. In addition, Tornadoes have the most significant economic impact, resulting in damage to properties and crops.