#Synopsis 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 report analyzes the U.S. National Oceanic and Atmospheric Administration’s (NOAA) Storm Database to determine which types of severe weather events have the greatest impact on public health and economic stability in the United States. The analysis focuses on data from 1950 to November 2011.

We first have to load the dataset into R and process the data for analysis.

# Load libraries
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(readr)

# Load dataset 
data <- read.csv("/home/rstudio/Reproducible Research/week2/repdata_data_StormData1.csv")

# Take a quick look at the dataset
head(data)
##   STATE__           BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE  EVTYPE
## 1       1  4/18/1950 0:00:00     0130       CST     97     MOBILE    AL TORNADO
## 2       1  4/18/1950 0:00:00     0145       CST      3    BALDWIN    AL TORNADO
## 3       1  2/20/1951 0:00:00     1600       CST     57    FAYETTE    AL TORNADO
## 4       1   6/8/1951 0:00:00     0900       CST     89    MADISON    AL TORNADO
## 5       1 11/15/1951 0:00:00     1500       CST     43    CULLMAN    AL TORNADO
## 6       1 11/15/1951 0:00:00     2000       CST     77 LAUDERDALE    AL TORNADO
##   BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1         0                                               0         NA
## 2         0                                               0         NA
## 3         0                                               0         NA
## 4         0                                               0         NA
## 5         0                                               0         NA
## 6         0                                               0         NA
##   END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1         0                      14.0   100 3   0          0       15    25.0
## 2         0                       2.0   150 2   0          0        0     2.5
## 3         0                       0.1   123 2   0          0        2    25.0
## 4         0                       0.0   100 2   0          0        2     2.5
## 5         0                       0.0   150 2   0          0        2     2.5
## 6         0                       1.5   177 2   0          0        6     2.5
##   PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1          K       0                                         3040      8812
## 2          K       0                                         3042      8755
## 3          K       0                                         3340      8742
## 4          K       0                                         3458      8626
## 5          K       0                                         3412      8642
## 6          K       0                                         3450      8748
##   LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1       3051       8806              1
## 2          0          0              2
## 3          0          0              3
## 4          0          0              4
## 5          0          0              5
## 6          0          0              6

Results

Here, we will present the main results from our analysis of the NOAA database. We will investigate the impact of severe weather events on 1) public health and 2) economy.

Health impact

We aim to answer the question what types of events in the US are most harmful to the health of the population?

# Summarize health impact
health_impact <- data %>% 
  group_by(EVTYPE) %>%
  summarise(
    TotalFatalities = sum(FATALITIES, na.rm = TRUE),
    TotalInjuries = sum(INJURIES, na.rm = TRUE), 
    TotalHealthImpact = TotalFatalities + TotalInjuries
  ) %>%
  arrange(desc(TotalHealthImpact))
## `summarise()` ungrouping output (override with `.groups` argument)
# Plot the top 10 event types by health impact
top_health_impact <- head(health_impact, 10)

ggplot(top_health_impact, aes(x=reorder(EVTYPE, -TotalHealthImpact), y = TotalHealthImpact, fill = EVTYPE)) +
  geom_bar(stat = "identity") +
  labs(title = "Top 10 Event Types by Health Impact", x = "Event Type", y = "Total Health Impact") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

As shown in the plot, the most harmful event type by far is tornado, with a total health impact (total amount of injured people and deaths) of almost 100.000. Tornado is followed by excessive heat and TSTM wind, which both have a total health impact of about 10.000.

Economic impact

We aim to answer the question what types of events have the greatest economic consequences in the US?

# Normalize damage exponents
damage_exp <- function(x) {
  if (x %in% c("H", "h")) return(100)
  if (x %in% c("K", "k")) return(1000)
  if (x %in% c("M", "m")) return(1e6)
  if (x %in% c("B", "b")) return(1e9)
  if (x %in% c("", "0")) return(1)
  return(1) # Default to 1 for unknown values
}

data <- data %>%
  mutate(
    PROPDMGEXP = sapply(PROPDMGEXP, damage_exp),
    CROPDMGEXP = sapply(CROPDMGEXP, damage_exp),
    TotalPropDamage = PROPDMG * PROPDMGEXP,
    TotalCropDamage = CROPDMG * CROPDMGEXP,
    TotalEconomicDamage = TotalPropDamage + TotalCropDamage
  )

# Summarize economic impact
economic_impact <- data %>%
  group_by(EVTYPE) %>%
  summarise(TotalEconomicDamage = sum(TotalEconomicDamage, na.rm = TRUE)) %>%
  arrange(desc(TotalEconomicDamage))
## `summarise()` ungrouping output (override with `.groups` argument)
# Plot the top 10 event types by economic damage
top_economic_impact <- head(economic_impact, 10)

ggplot(top_economic_impact, aes(x = reorder(EVTYPE, -TotalEconomicDamage), y = TotalEconomicDamage / 1e9, fill = EVTYPE)) +
  geom_bar(stat = "identity") +
  labs(title = "Top 10 Event Types by Economic Damage", x = "Event Type", y = "Total Economic Damage (in Billions)") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

We show that the event with the highest economic impact by far is flooding, followed by hurricane/typhoon and tornado.