Major storms and weather events in the United States: lead to fatalities, injuries, and enormous property damage.

1.Database

NOAA Storm Database: US Severe Weather impacts on Health and Economics

2.Assignment

The main goal of this project is to process and analyze the database and to answer the following questions: which wwather events have caused the greatest financial damage and which events have the most harmful influence on the health of the people in the individual countries. The analysis consists tables, figures, or other summaries by using R to support the analysis.

3.Synopsis

The NOAA database tracks characteristics of major storms and weather events in the United States. Information on the exact location, time, duration, strength etc. could be helpful in the analysis so that the consequences of these events can be recorded. These consequences are divided into 2 groups: on the one hand there is property damage and on the other hand there is health damage, i.e. fatalities and injuries.

4.This data analysis must address the following *questions :

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

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

5.Results

5.1Findings on Question 1: Floods cause the most significant total damage (property and crop.)

The graph for the financial damage caused shows that “hurricane” and “typhoon” caused the greatest financial damage. In third place is “flood”. However, if you examine the two graphics individually you will see:

  1. The reason for most of the damage in the area of “property” is “flood”

  2. The reason for most of the damage in the “crop” area is “hurricane”

5.2Findings on Question 2: Tornado’s by far cause the most fatalities and injuries, by far the most signifcant harm to public health.

The graphic for “events leading to death” shows that the tornado is the event that usually led to death. Among the most dangerous events that caused death are “excessive heat”, “flash flood”, “heat”, “rip current”. The other graph, “events leading to injuries”, shows that “tornado” was the cause of most injuries. Among the top 20 most common injuries there are only 2 states in which “flood” and “excessive heat” were the reason for numerous injuries. All in all, it can be summarized that “tornado” most often led to injuries and a fatal outcome.

6. Loading and preprocessing the data

activity <- read.csv("/Users/diyanananova/Documents/cours5_week4/repdata-data-StormData.csv.bz2",header = T, sep = ",")
head(activity)
##   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
library(chron)
library(lubridate)
library(dplyr)
library(tidyverse)
library(lattice)
library(ggplot2)
library(ggpubr)
6.1.functions
`%!in%` = Negate(`%in%`)
6.2. Question 1: Across the United States, which types of events have the greatest economic consequences? Processing of the collected data. Amount of finnacial damages listed by type of event.
#### Replace B-M-K
act_newpropdmgexp <- activity %>% 
  mutate(PROPDMGEXP_new = case_when(PROPDMGEXP == "K" ~  1000, PROPDMGEXP == "M" ~  1000000,
                                    PROPDMGEXP == "B" ~  1000000000, PROPDMGEXP == "k" ~  1000, 
                                    PROPDMGEXP == "m" ~  1000000, PROPDMGEXP == "b" ~  1000000000,
                                    PROPDMGEXP %!in% c("K","M","B", "k", "m", "b") ~ 0),
         CROPDMGEXP_new=case_when(PROPDMGEXP == "K" ~  1000, PROPDMGEXP == "M" ~  1000000,
                                  PROPDMGEXP == "B" ~  1000000000, PROPDMGEXP == "k" ~  1000, 
                                  PROPDMGEXP == "m" ~  1000000, PROPDMGEXP == "b" ~  1000000000, 
                                  PROPDMGEXP %!in% c("K","M","B", "k", "m", "b") ~ 0)) 
#### cleaning up the names of the types of events

EVTYPE_upper = toupper(act_newpropdmgexp$EVTYPE)
EVTYPE_upper_space = trimws(EVTYPE_upper)
EVTYPE_upper_numb = gsub('[[:digit:]]+', '', EVTYPE_upper_space)
EVTYPE_upper_dot = gsub('\\.', '', EVTYPE_upper_numb)
EVTYPE_upper_brakets = gsub('[(, )]', '', EVTYPE_upper_dot)
EVTYPE_upper_question = gsub('[?]', '', EVTYPE_upper_dot)
#### multiplicate for Million, Billions, Thousand
property_damage <- act_newpropdmgexp %>% 
  select(STATE, PROPDMG, PROPDMGEXP_new, CROPDMG, CROPDMGEXP_new) %>%
  mutate(PROPDMG_num = PROPDMG * PROPDMGEXP_new, CROPDMG_num = CROPDMG * CROPDMGEXP_new, EVTYPE_upper_question ) 
#### summarize damages PROP and CROP
property_damage_sum <- property_damage %>% 
  group_by(EVTYPE_upper_question, STATE) %>%
  summarise(PDMG_sum = sum(PROPDMG_num), CDMG_sum = sum(CROPDMG_num)) %>%
  mutate(DMG_sum = PDMG_sum + CDMG_sum) 
#### top 20 of damage caused
property_damage_top20 <- property_damage_sum %>% 
  select(EVTYPE_upper_question, STATE, DMG_sum) %>% 
  group_by(EVTYPE_upper_question, STATE) %>%
  arrange(desc(DMG_sum)) %>%
  ungroup %>%
  slice(1:20)

#### plot the results
ggplot(property_damage_top20, aes(x = STATE, y = DMG_sum, fill = EVTYPE_upper_question, label = DMG_sum)) +
  geom_bar(stat = "identity") +
  scale_fill_discrete(name = "type of event")+
  labs(x = "STATE", y = "finnacial damages", title = "Amount of finnacial damages listed by type of event")

#### plot the results
prop_damage_top20 <- property_damage_sum %>% 
  select(EVTYPE_upper_question, STATE, PDMG_sum) %>% 
  group_by(EVTYPE_upper_question, STATE) %>%
  arrange(desc(PDMG_sum)) %>%
  ungroup %>%
  slice(1:20)

prop_ggplot <- ggplot(prop_damage_top20, aes(x = STATE, y = PDMG_sum, fill = EVTYPE_upper_question, label = PDMG_sum)) +
  geom_bar(stat = "identity") +
  scale_fill_discrete(name = "type of event")+
  labs(x = "STATE", y = "property damages", title = "Amount of property damages listed by type of event")
#### plot the results
crop_damage_top20 <- property_damage_sum %>% 
  select(EVTYPE_upper_question, STATE, CDMG_sum) %>% 
  group_by(EVTYPE_upper_question, STATE) %>%
  arrange(desc(CDMG_sum)) %>%
  ungroup %>%
  slice(1:20)

crop_ggplot <- ggplot(crop_damage_top20, aes(x = STATE, y = CDMG_sum, fill = EVTYPE_upper_question, label = CDMG_sum)) +
  geom_bar(stat = "identity") +
  scale_fill_discrete(name = "type of event")+
  labs(x = "STATE", y = "crop damages", title = "Amount of crop damages listed by type of event")
#### combine the 2 plots 
ggarrange(prop_ggplot, crop_ggplot, 
        nrow = 2, ncol = 1)

6.3.Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health? Processing of the collected data. Amount of health damage (injuries and death) listed by type of event.
#### top 20 of fatalities
fat_top20 <- activity %>%
  select(STATE, FATALITIES) %>%
  mutate(EVTYPE_upper_question) %>%
  group_by(EVTYPE_upper_question, STATE) %>%
  summarise(fat_sum = sum(FATALITIES)) %>%
  arrange(desc(fat_sum)) %>%
  ungroup %>%
  slice(1:20)
#### top 20 of injuries
inj_top20 <- activity %>%
  select(STATE, INJURIES) %>%
  mutate(EVTYPE_upper_question) %>%
  group_by(EVTYPE_upper_question, STATE) %>%
  summarise(inj_sum = sum(INJURIES)) %>%
  arrange(desc(inj_sum)) %>%
  ungroup %>%
  slice(1:20)
#### plot the results for fatalities
ggfat <- ggplot(fat_top20, aes(x = STATE, y = fat_sum, fill = EVTYPE_upper_question, label = fat_sum)) +
  geom_bar(stat = "identity") +
  geom_text(size = 3, position = position_stack(vjust = 0.5))+
  scale_fill_discrete(name = "type of event")+
  labs(x = "STATE", y = "FATALITIES", title = "Events leading to death")
#### plot the results for injuries
gginj <- ggplot(inj_top20, aes(x = STATE, y = inj_sum, fill = EVTYPE_upper_question, label = inj_sum)) +
  geom_bar(stat = "identity") +
  geom_text(size = 3, position = position_stack(vjust = 0.5))+
  scale_fill_discrete(name = "type of event")+
  labs(x = "STATE", y = "INJURIES", title = "Events leading to injuries")
#### combine the 2 plots 
ggarrange(ggfat, gginj, 
        nrow = 2, ncol = 1)