This report analyzes the U.S. National Oceanic and Atmospheric Administration’s (NOAA) Storm Database (1950-2011) to evaluate the impact of severe weather events on public health and the economy in the United States. Data processing involved aggregating total fatalities, injuries, property damage, and crop damage by specific event types. The analysis reveals that Tornadoes are overwhelmingly the most harmful events to population health, causing the highest total number of both fatalities and injuries. In terms of economic consequences, Floods have caused the greatest overall financial damage, followed closely by Hurricanes/Typhoons and Tornadoes.
Library loading code block
# Load thư viện cần thiết
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(readr) # Dùng để đọc dữ liệu tốc độ cao
# Load thư viện để tạo bảng đẹp
library(knitr)Raw data loading code block
#Đặt URL nguồn dữ liệu và tên file đích
file_url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
dest_file <- "repdata_data_StormData.csv.bz2"
# 1. Tự động tải file nếu file chưa tồn tại trong thư mục làm việc
if (!file.exists(dest_file)) {
download.file(url = file_url, destfile = dest_file, method = "curl")
}
# 2. Đọc trực tiếp từ file nén bz2 (Không cần giải nén ra csv!)
# Sử dụng hàm read_csv thay vì read.csv để tăng tốc độ và tạo định dạng tibble gọn gàng
storm_data <- read_csv(dest_file)
## Rows: 902297 Columns: 37
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): BGN_DATE, BGN_TIME, TIME_ZONE, COUNTYNAME, STATE, EVTYPE, BGN_AZI,...
## dbl (18): STATE__, COUNTY, BGN_RANGE, COUNTY_END, END_RANGE, LENGTH, WIDTH, ...
## lgl (1): COUNTYENDN
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.Data cleaning and transformation code block
# BƯỚC 1: Lọc cột và chuẩn hóa tên sự kiện (EVTYPE)
storm_clean <- storm_data %>%
select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP) %>%
mutate(EVTYPE = toupper(trimws(EVTYPE))) # Viết hoa toàn bộ và cắt khoảng trắng thừa
# BƯỚC 2: Biến đổi dữ liệu Sức khỏe (Population Health)
health_summary <- storm_clean %>%
group_by(EVTYPE) %>%
summarise(
Total_Fatalities = sum(FATALITIES, na.rm = TRUE),
Total_Injuries = sum(INJURIES, na.rm = TRUE)
) %>%
mutate(Total_Harm = Total_Fatalities + Total_Injuries) %>%
arrange(desc(Total_Harm)) %>%
slice_head(n = 10) # Lấy Top 10 sự kiện gây hại nhất
# BƯỚC 3: Biến đổi dữ liệu Kinh tế (Economic Consequences)
# Viết hàm nội bộ để map ký tự số mũ thành hệ số nhân (Multiplier)
# Cập nhật hàm get_multiplier (Đã triệt tiêu cảnh báo ép kiểu)
get_multiplier <- function(exp_char) {
exp_char <- toupper(exp_char)
case_when(
exp_char == "K" ~ 10^3,
exp_char == "M" ~ 10^6,
exp_char == "B" ~ 10^9,
# Thêm suppressWarnings để triệt tiêu cảnh báo khi cố ép kiểu "K", "M" thành số
exp_char %in% as.character(0:8) ~ 10^suppressWarnings(as.numeric(exp_char)),
TRUE ~ 1 # Mặc định các ký tự lỗi rác coi như nhân với 1
)
}
# Chạy lại đoạn code biến đổi kinh tế
econ_summary <- storm_clean %>%
mutate(
Prop_Mult = get_multiplier(PROPDMGEXP),
Crop_Mult = get_multiplier(CROPDMGEXP),
Property_Damage = PROPDMG * Prop_Mult,
Crop_Damage = CROPDMG * Crop_Mult,
Total_Damage = Property_Damage + Crop_Damage
) %>%
group_by(EVTYPE) %>%
summarise(Total_Econ_Damage = sum(Total_Damage, na.rm = TRUE)) %>%
arrange(desc(Total_Econ_Damage)) %>%
slice_head(n = 10)
econ_summary <- storm_clean %>%
mutate(
Prop_Mult = get_multiplier(PROPDMGEXP),
Crop_Mult = get_multiplier(CROPDMGEXP),
Property_Damage = PROPDMG * Prop_Mult,
Crop_Damage = CROPDMG * Crop_Mult,
Total_Damage = Property_Damage + Crop_Damage
) %>%
group_by(EVTYPE) %>%
summarise(Total_Econ_Damage = sum(Total_Damage, na.rm = TRUE)) %>%
arrange(desc(Total_Econ_Damage)) %>%
slice_head(n = 10) # Lấy Top 10 sự kiện thiệt hại nặng nhất
To answer the first question, we visualize the top 10 weather events that cause the highest number of fatalities and injuries across the United States.
# Load thêm thư viện tidyr để chuyển đổi cấu trúc dữ liệu
library(tidyr)
library(ggplot2)
# Chuyển đổi dữ liệu sang dạng dài (Long format)
health_long <- health_summary %>%
select(EVTYPE, Total_Fatalities, Total_Injuries) %>%
pivot_longer(cols = c("Total_Fatalities", "Total_Injuries"),
names_to = "Impact_Type",
values_to = "Count")
# Vẽ biểu đồ
ggplot(health_long, aes(x = reorder(EVTYPE, -Count), y = Count, fill = Impact_Type)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Top 10 Most Harmful Weather Events in the US (1950-2011)",
x = "Event Type",
y = "Number of People Affected") +
scale_fill_manual(values = c("Total_Fatalities" = "darkred", "Total_Injuries" = "salmon"),
labels = c("Fatalities", "Injuries")) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 10, face = "bold"),
plot.title = element_text(face = "bold", size = 14))
Figure 1: Tornadoes are overwhelmingly the most dangerous weather event, causing significantly higher numbers of both injuries and fatalities compared to other events.
To answer the second question, we examine the total economic damage (combined property and crop damage in USD) caused by the top 10 weather events.
# Vẽ biểu đồ kinh tế
ggplot(econ_summary, aes(x = reorder(EVTYPE, -Total_Econ_Damage), y = Total_Econ_Damage)) +
geom_bar(stat = "identity", fill = "steelblue") +
labs(title = "Top 10 Weather Events with Greatest Economic Consequences (1950-2011)",
x = "Event Type",
y = "Total Economic Damage (USD)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 10, face = "bold"),
plot.title = element_text(face = "bold", size = 14))
Figure 2: Floods have caused the highest overall economic damage in the US, exceeding 150 billion dollars, followed by Hurricanes/Typhoons and Tornadoes.
While this analysis provides a clear high-level overview of the most harmful weather events in the United States, several methodological caveats must be acknowledged:
EVTYPE variable contains 985 unique entries, many of which
are typographical errors or synonymous terms (e.g., “TSTM WIND”
vs. “THUNDERSTORM WINDS”). Although basic text normalization
(capitalization and trimming) was applied in our data processing step, a
more rigorous epidemiological study would require using Regular
Expressions (Regex) to map all 985 raw entries into the 48 official NWS
Directive 10-1605 storm data events.Addressing these limitations in future analyses would yield a more precise and historically accurate assessment for municipal resource allocation.