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.

This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage.

Assignment The basic goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events. You must use the database to answer the questions below and show the code for your entire analysis. Your analysis can consist of tables, figures, or other summaries. You may use any R package you want to support your analysis.

Questions Your data analysis must address the following questions:

  1. Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?

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

SYNOPSIS

In this report, we aim to discover the weather events responsible for the events that are most harmful with respect to population health and that have the greatest economic consequences across the United States. To interpret this, we obtained data from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. Our results indicate that the weather event “Tornado” causes the most impact in regards to population health (fatalities and injuries) and Tornado is also the weather event that causes the most economic consequences (crop and property damages).

  1. LOAD PACKAGES
# Load necessary library for downloading
library(downloader)
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)
library(patchwork)
# Load necessary library for reading CSV
library(readr)
  1. DATA PROCESSING: READ IN DATA
# Define the URL
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"

# Define the local file name
local_file <- "StormData.csv.bz2"

# Download the file
download(url, destfile = local_file, mode = "wb")


# Read the CSV file
storm_data <- read_csv(bzfile(local_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
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Print the first few rows of the data
head(storm_data)
## # A tibble: 6 x 37
##   STATE__ BGN_DATE   BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE BGN_RANGE
##     <dbl> <chr>      <chr>    <chr>      <dbl> <chr>      <chr> <chr>      <dbl>
## 1       1 4/18/1950~ 0130     CST           97 MOBILE     AL    TORNA~         0
## 2       1 4/18/1950~ 0145     CST            3 BALDWIN    AL    TORNA~         0
## 3       1 2/20/1951~ 1600     CST           57 FAYETTE    AL    TORNA~         0
## 4       1 6/8/1951 ~ 0900     CST           89 MADISON    AL    TORNA~         0
## 5       1 11/15/195~ 1500     CST           43 CULLMAN    AL    TORNA~         0
## 6       1 11/15/195~ 2000     CST           77 LAUDERDALE AL    TORNA~         0
## # i 28 more variables: BGN_AZI <chr>, BGN_LOCATI <chr>, END_DATE <chr>,
## #   END_TIME <chr>, COUNTY_END <dbl>, COUNTYENDN <lgl>, END_RANGE <dbl>,
## #   END_AZI <chr>, END_LOCATI <chr>, LENGTH <dbl>, WIDTH <dbl>, F <dbl>,
## #   MAG <dbl>, FATALITIES <dbl>, INJURIES <dbl>, PROPDMG <dbl>,
## #   PROPDMGEXP <chr>, CROPDMG <dbl>, CROPDMGEXP <chr>, WFO <chr>,
## #   STATEOFFIC <chr>, ZONENAMES <chr>, LATITUDE <dbl>, LONGITUDE <dbl>,
## #   LATITUDE_E <dbl>, LONGITUDE_ <dbl>, REMARKS <chr>, REFNUM <dbl>
# Looking at the colnames of storm data
colnames(storm_data)
##  [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"
  1. DATA PROCESSING: EVENT THAT CAUSES MOST HARM TO POPULATION HEALTH
# Group by event type and calculate the total fatalities and injuries for each type
population_health_consequences <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(total_fatalities = sum(FATALITIES, na.rm = TRUE),
            total_injuries = sum(INJURIES, na.rm = TRUE),
            total_population_health = sum(FATALITIES + INJURIES, na.rm = TRUE)) %>%
  arrange(desc(total_population_health))

# Display the event with the greatest population health consequences
event_with_greatest_population_health <- population_health_consequences %>%
  slice(which.max(total_population_health))

print("The event that causes the greatest population health impact is:")
## [1] "The event that causes the greatest population health impact is:"
print(event_with_greatest_population_health)
## # A tibble: 1 x 4
##   EVTYPE  total_fatalities total_injuries total_population_health
##   <chr>              <dbl>          <dbl>                   <dbl>
## 1 TORNADO             5633          91346                   96979
  1. DATA PROCESSING: EVENT THAT CAUSES MOST HARM TO ECONOMY
# Group by event type and calculate the total property and crop damages for each type
economic_consequences <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(total_property_damage = sum(PROPDMG, na.rm = TRUE),
            total_crop_damage = sum(CROPDMG, na.rm = TRUE),
            total_economic_damage = sum(PROPDMG + CROPDMG, na.rm = TRUE)) %>%
  arrange(desc(total_economic_damage))

# Display the event with the greatest economic consequences
event_with_greatest_economic_consequences <- economic_consequences %>%
  slice(which.max(total_economic_damage))

print("The event that causes the greatest economic impact is:")
## [1] "The event that causes the greatest economic impact is:"
print(event_with_greatest_economic_consequences)
## # A tibble: 1 x 4
##   EVTYPE  total_property_damage total_crop_damage total_economic_damage
##   <chr>                   <dbl>             <dbl>                 <dbl>
## 1 TORNADO              3212258.           100019.              3312277.
  1. RESULTS: EVENT THAT CAUSES MOST HARM TO POPULATION HEALTH
# Group by event type and calculate the total fatalities and injuries for each type
event_health_impact <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(total_fatalities = sum(FATALITIES, na.rm = TRUE),
            total_injuries = sum(INJURIES, na.rm = TRUE)) %>%
  arrange(desc(total_fatalities + total_injuries))


# Group by event type and calculate the total fatalities and injuries for each type
event_health_impact <- event_health_impact %>%
  group_by(EVTYPE) %>%
  summarise(total_fatalities = sum(total_fatalities, na.rm = TRUE),
            total_injuries = sum(total_injuries, na.rm = TRUE)) %>%
  arrange(desc(total_fatalities + total_injuries))

# Select the top 5 event types for fatalities and injuries
top_event_types_fatalities <- event_health_impact %>%
  slice_max(order_by = total_fatalities, n = 5, with_ties = FALSE)
top_event_types_injuries <- event_health_impact %>%
  slice_max(order_by = total_injuries, n = 5, with_ties = FALSE)

# Create a bar plot for total fatalities
plot_fatalities <- ggplot(top_event_types_fatalities, aes(x = reorder(EVTYPE, -total_fatalities), y = total_fatalities, fill = "Fatalities")) +
  geom_bar(stat = "identity", color = "black") +
  labs(title = "Total Fatalities by Event Type (Top 5)",
       x = "Event Type",
       y = "Count") +
  scale_fill_manual(values = "skyblue", name = NULL) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Create a bar plot for total injuries
plot_injuries <- ggplot(top_event_types_injuries, aes(x = reorder(EVTYPE, -total_injuries), y = total_injuries, fill = "Injuries")) +
  geom_bar(stat = "identity", color = "black") +
  labs(title = "Total Injuries by Event Type (Top 5)",
       x = "Event Type",
       y = "Count") +
  scale_fill_manual(values = "lightcoral", name = NULL) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Combine the two plots into a single panel plot
combined_plot <- plot_fatalities + plot_injuries + plot_layout(ncol = 2)

# Display the combined plot
print(combined_plot)

Based on the graphs, it is evident that Tornado is the lead cause for both fatalities and injuries, deeming it as the lead cause for causing most impact to population health.

  1. RESULTS: EVENT THAT CAUSES MOST HARM TO ECONOMY
# Group by event type and calculate the total property and crop damages for each type
economic_consequences <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(total_property_damage = sum(PROPDMG, na.rm = TRUE),
            total_crop_damage = sum(CROPDMG, na.rm = TRUE)) %>%
  arrange(desc(total_property_damage + total_crop_damage))

# Display the top events with the greatest economic consequences
top_economic_events <- head(economic_consequences, 10)
print(top_economic_events)
## # A tibble: 10 x 3
##    EVTYPE             total_property_damage total_crop_damage
##    <chr>                              <dbl>             <dbl>
##  1 TORNADO                         3212258.           100019.
##  2 FLASH FLOOD                     1420175.           179200.
##  3 TSTM WIND                       1336074.           109203.
##  4 HAIL                             688693.           579596.
##  5 FLOOD                            899938.           168038.
##  6 THUNDERSTORM WIND                876844.            66791.
##  7 LIGHTNING                        603352.             3581.
##  8 THUNDERSTORM WINDS               446293.            18685.
##  9 HIGH WIND                        324732.            17283.
## 10 WINTER STORM                     132721.             1979.
# Assuming your dataframe is named 'storm_data'
# Group by event type and calculate the total property damage for each type
property_damage <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(total_property_damage = sum(PROPDMG, na.rm = TRUE)) %>%
  arrange(desc(total_property_damage))

# Select the top 5 event types for property damage
top_property_damage <- property_damage %>%
  slice_max(order_by = total_property_damage, n = 5, with_ties = FALSE)

# Create a bar plot for total property damage
plot_property_damage <- ggplot(top_property_damage, aes(x = reorder(EVTYPE, -total_property_damage), y = total_property_damage, fill = "Property Damage")) +
  geom_bar(stat = "identity", color = "black") +
  labs(title = "Total Property Damage by Event Type (Top 5)",
       x = "Event Type",
       y = "Count") +
  scale_fill_manual(values = "skyblue", name = NULL) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Group by event type and calculate the total crop damage for each type
crop_damage <- storm_data %>%
  group_by(EVTYPE) %>%
  summarise(total_crop_damage = sum(CROPDMG, na.rm = TRUE)) %>%
  arrange(desc(total_crop_damage))

# Select the top 5 event types for crop damage
top_crop_damage <- crop_damage %>%
  slice_max(order_by = total_crop_damage, n = 5, with_ties = FALSE)

# Create a bar plot for total crop damage
plot_crop_damage <- ggplot(top_crop_damage, aes(x = reorder(EVTYPE, -total_crop_damage), y = total_crop_damage, fill = "Crop Damage")) +
  geom_bar(stat = "identity", color = "black") +
  labs(title = "Total Crop Damage by Event Type (Top 5)",
       x = "Event Type",
       y = "Count") +
  scale_fill_manual(values = "lightcoral", name = NULL) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

# Combine the two plots into a single panel plot
combined_plot_damage <- plot_property_damage + plot_crop_damage + plot_layout(ncol = 2)

# Display the combined plot
print(combined_plot_damage)

Based on the graphs, it is evident that Tornado is the lead cause for property damage while hail is the lead cause for crop damage. Overall, Tornado is the lead cause for causing most impact to economy.

sessionInfo()
## R version 4.2.3 (2023-03-15 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 17763)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_United States.1252 
## [2] LC_CTYPE=English_United States.1252   
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] readr_2.1.4     patchwork_1.1.2 ggplot2_3.4.4   dplyr_1.1.2    
## [5] downloader_0.4 
## 
## loaded via a namespace (and not attached):
##  [1] highr_0.10       pillar_1.9.0     bslib_0.5.1      compiler_4.2.3  
##  [5] jquerylib_0.1.4  tools_4.2.3      bit_4.0.5        digest_0.6.31   
##  [9] jsonlite_1.8.4   evaluate_0.23    lifecycle_1.0.3  tibble_3.2.1    
## [13] gtable_0.3.4     pkgconfig_2.0.3  rlang_1.1.0      cli_3.6.1       
## [17] rstudioapi_0.14  parallel_4.2.3   yaml_2.3.7       xfun_0.41       
## [21] fastmap_1.1.1    withr_2.5.2      knitr_1.45       generics_0.1.3  
## [25] vctrs_0.6.1      sass_0.4.5       hms_1.1.3        bit64_4.0.5     
## [29] grid_4.2.3       tidyselect_1.2.0 glue_1.6.2       R6_2.5.1        
## [33] fansi_1.0.4      vroom_1.6.5      rmarkdown_2.25   farver_2.1.1    
## [37] tzdb_0.4.0       magrittr_2.0.3   scales_1.2.1     htmltools_0.5.5 
## [41] colorspace_2.1-0 labeling_0.4.3   utf8_1.2.3       munsell_0.5.0   
## [45] cachem_1.0.7     crayon_1.5.2