In this report, the population health impact and associated economic costs of natural disasters from 1950 to 2011 is explored. Overall, we found that tornados is the natural disaster leading to the most fatalities and injuries. Furthermore, we found that tornados also have resulted in the highest economic impact throughout the time-period. However, the event leading to the largest economic impact per time was tropical storms. The code used for every step is attached, as well as comment showing the purpose of the various aspects of the code.
For preprocessing, relevant packages was loaded, before the raw datafile was downloaded and loaded to R.
#Script setup
library(dplyr)
library(ggplot2)
library(scales)
library(gridExtra)
#Download data
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
destination <- "assignment2_data.csv"
download.file(url, destfile = destination)
download_date <- Sys.Date()
#Load dataset
data <- read.csv("assignment2_data.csv")
Data was succesfully downloaded 2025-01-08.
In the exploratory phase, a general overview of the data was performed. Next, the frequency of events was assessed, along with some analysed for missing values, then descriptive data for the fatalities and injuries.
#Get an overview over dataset
str(data)
colSums(is.na(data))
#Count frequency of different events sorted
sorted_freq <- data %>%
count(EVTYPE, name = "Frequency") %>%
arrange(desc(Frequency))
#assess data quality of relevant variables: INJURIES AND FATALITIES by looking at unique values
unique(data$INJURIES)
unique(data$FATALITIES)
#Count number of fatalities and injuries during the time-period.
n_fatalities <- sum(data$FATALITIES)
n_injuries <-sum(data$INJURIES)
Briefly, the dataset contains 37 variables, with 902297 observations from 1950 to november 2011. The dataset occurs to be fairly complete, with few to no missing variables. The top five most common events throughout the time-period are displayed in the figure below, with hails being the most common event. During the time-period, there were 1.5145^{4} fatalities and 1.40528^{5} injuries.
#create figure of top 5 events to describe
top_events <- head(sorted_freq, 5)
ggplot(top_events, aes(x = reorder(EVTYPE, -Frequency), y = Frequency)) +
geom_bar(stat = "identity", fill = "skyblue") +
theme_minimal() +
labs(
title = "Top 5 Events",
x = "Event Type",
y = "Frequency"
) +
scale_y_continuous(labels = scales::comma) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
The top 10 causes of fatality and injury is shown below. Overall, it is seen that tornadoes by far is associated with the higest amount for both, followed by TSTM winds and floods for injuries, and exscessive heat and flash flood for fatalities.
# Sort top 10 injuries by event
top_10_injuries <- data %>%
group_by(EVTYPE) %>%
summarise(TotalInjuries = sum(INJURIES, na.rm = TRUE)) %>%
arrange(desc(TotalInjuries)) %>%
slice_head(n = 10)
# Create figure for injuries
plot_injuries <- ggplot(top_10_injuries, aes(x = reorder(EVTYPE, -TotalInjuries), y = TotalInjuries)) +
geom_bar(stat = "identity", fill = "skyblue") +
theme_minimal() +
labs(
title = "Top 10 Causes of Injuries",
x = "Event Type",
y = "Total Injuries"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Sort top 10 fatalities by event
top_10_fatalities <- data %>%
group_by(EVTYPE) %>%
summarise(TotalFatalities = sum(FATALITIES, na.rm = TRUE)) %>%
arrange(desc(TotalFatalities)) %>%
slice_head(n = 10)
# Create figure for fatalities
plot_fatalities <- ggplot(top_10_fatalities, aes(x = reorder(EVTYPE, -TotalFatalities), y = TotalFatalities)) +
geom_bar(stat = "identity", fill = "salmon") +
theme_minimal() +
labs(
title = "Top 10 Causes of Death",
x = "Event Type",
y = "Total Fatalities"
) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Arrange the plots side by side
grid.arrange(plot_injuries, plot_fatalities, ncol = 2)
Based on the analysis below, we found that the event that led to the highest cost on average for each time it occured was tropical storms. However, the event that led to the highest overall cost in the entire time-period was tornados.
#Identify the events that led to the higest average damage based on proprdmg and cropdmg variables.
# Create a new variable showing total damage
data <- data %>%
mutate(TotalDmg = PROPDMG + CROPDMG)
# Find the events associated with the highest average cost
top_10_expensive_events_mean <- data %>%
group_by(EVTYPE) %>%
summarise(TotalCost = mean(TotalDmg, na.rm = TRUE)) %>%
arrange(desc(TotalCost)) %>%
slice_head(n = 10)
# Find events associated with highest absolute cumulative cost
top_10_expensive_events_absolute <- data %>%
group_by(EVTYPE) %>%
summarise(TotalCost = sum(TotalDmg, na.rm = TRUE)) %>%
arrange(desc(TotalCost)) %>%
slice_head(n = 10)
# Create the first plot for the mean cost
plot_mean_cost <- ggplot(top_10_expensive_events_mean, aes(x = reorder(EVTYPE, -TotalCost), y = TotalCost)) +
geom_bar(stat = "identity", fill = "skyblue") +
theme_minimal() +
labs(
title = "Top 10 Most Expensive Events by Mean Cost",
x = "Event Type",
y = "Mean Cost (in USD)"
) +
scale_y_continuous(labels = scales::comma) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Create the second plot for the cumulative cost
plot_absolute_cost <- ggplot(top_10_expensive_events_absolute, aes(x = reorder(EVTYPE, -TotalCost), y = TotalCost)) +
geom_bar(stat = "identity", fill = "salmon") +
theme_minimal() +
labs(
title = "Top 10 Most Expensive Events by Cumulative Cost",
x = "Event Type",
y = "Cumulative Cost (in USD)"
) +
scale_y_continuous(labels = scales::comma) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Arrange the plots side by side
grid.arrange(plot_mean_cost, plot_absolute_cost, ncol = 2)