Synopsis

Data from the NOAA Storm Database was analyzed to figure out the types of events that cause the most loss of life and money. The data was transformed to sum up the losses from each type of events. Then they were graphed to show the effects visually. From this we can see that Tornado causes the most loss of life, while Flood causes the most loss of money.

Data processing

Loading the libraries

library(readr)
## Warning: package 'readr' was built under R version 4.3.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.3
## 
## 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)
## Warning: package 'ggplot2' was built under R version 4.3.3

Loading the data

and transforming the character variables to factors

The function read_csv from readr package was used to directly read the compressed .bz2 file.
Then all the chr type columns were transformed into factors for easier analysis.

Storm.Data <- read_csv("repdata_data_StormData.csv.bz2") 
## 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.
Storm.Data <- Storm.Data %>% mutate_if(is.character, factor)

Calculating the total fatality and injury for each type of events

After grouping by EVTYPE, sum of all fatalities and injuries were calculated using the summarize function.
Then the data frame is sorted in descending order of Total fatality, then total injury.

Population.Health <- Storm.Data %>% 
  group_by(EVTYPE) %>% 
  summarize(Total.fatality = sum(FATALITIES), Total.injury = sum(INJURIES)) %>%
  arrange(desc(Total.fatality), desc(Total.injury))

Calculating the total damage expenditure for each type of events

Both property damage and crop damage data were saved using two columns each. One for the value, and one for the suffix to indicate the exponentiaion.
First these had to be combined to form a single numerical column each, for property damage and crop damage.
After grouping by EVTYPE, sum of all property damage and crop damage were calculated using the summarize function. Then these two were added to figure out the Total damage for each type.
Then the data frame is sorted in descending order of Total damage, then Total property damage, then Total crop damage.

Economic.Damage <- Storm.Data %>% 
  mutate(
    PROPDMG1 = case_when(
        .default = PROPDMG,
        PROPDMGEXP == "B" ~ PROPDMG*1000000000,
        PROPDMGEXP == "M" ~ PROPDMG*1000000,
        PROPDMGEXP == "m" ~ PROPDMG*1000000,
        PROPDMGEXP == "K" ~ PROPDMG*1000,
        PROPDMGEXP == "k" ~ PROPDMG*1000,
        PROPDMGEXP == "H" ~ PROPDMG*100,
        PROPDMGEXP == "h" ~ PROPDMG*100,
        PROPDMGEXP == "8" ~ PROPDMG*100000000,
        PROPDMGEXP == "7" ~ PROPDMG*10000000,
        PROPDMGEXP == "6" ~ PROPDMG*1000000,
        PROPDMGEXP == "5" ~ PROPDMG*100000,
        PROPDMGEXP == "4" ~ PROPDMG*10000,
        PROPDMGEXP == "3" ~ PROPDMG*1000,
        PROPDMGEXP == "2" ~ PROPDMG*100,
        PROPDMGEXP == "1" ~ PROPDMG*10
      ),
    CROPDMG1 = case_when(
        .default = CROPDMG,
        CROPDMGEXP == "B" ~ CROPDMG*1000000000,
        CROPDMGEXP == "M" ~ CROPDMG*1000000,
        CROPDMGEXP == "m" ~ CROPDMG*1000000,
        CROPDMGEXP == "K" ~ CROPDMG*1000,
        CROPDMGEXP == "k" ~ CROPDMG*1000,
        CROPDMGEXP == "H" ~ CROPDMG*100,
        CROPDMGEXP == "h" ~ CROPDMG*100,
        CROPDMGEXP == "8" ~ CROPDMG*100000000,
        CROPDMGEXP == "7" ~ CROPDMG*10000000,
        CROPDMGEXP == "6" ~ CROPDMG*1000000,
        CROPDMGEXP == "5" ~ CROPDMG*100000,
        CROPDMGEXP == "4" ~ CROPDMG*10000,
        CROPDMGEXP == "3" ~ CROPDMG*1000,
        CROPDMGEXP == "2" ~ CROPDMG*100,
        CROPDMGEXP == "1" ~ CROPDMG*10
      ) 
    ) %>%
    group_by(EVTYPE) %>%
    summarize(Total.PROPDMG = sum(PROPDMG1), Total.CROPDMG = sum(CROPDMG1)) %>%
    mutate(Total.DMG = Total.PROPDMG + Total.CROPDMG) %>%
    arrange(desc(Total.DMG), desc(Total.PROPDMG), desc(Total.CROPDMG))

Analysis

Top 10 types of events causing most fatality and injury

Population.Health[1:10,]
## # A tibble: 10 × 3
##    EVTYPE         Total.fatality Total.injury
##    <fct>                   <dbl>        <dbl>
##  1 TORNADO                  5633        91346
##  2 EXCESSIVE HEAT           1903         6525
##  3 FLASH FLOOD               978         1777
##  4 HEAT                      937         2100
##  5 LIGHTNING                 816         5230
##  6 TSTM WIND                 504         6957
##  7 FLOOD                     470         6789
##  8 RIP CURRENT               368          232
##  9 HIGH WIND                 248         1137
## 10 AVALANCHE                 224          170

Let’s see using graphs how significant these are

I deliberately choose to not equate fatalities with specific numbers of injuries and thus plot both in a scatter plot.

ggplot(Population.Health, aes(Total.fatality, Total.injury)) + 
  geom_jitter()

The first data, ie, Tornado far surpasses everythis else, so it is not that clear how many of the other types are doing the most damage,

Using log10 scale for better visualization

ggplot(Population.Health, aes(log10(Total.fatality), log10(Total.injury))) +
  geom_jitter()

It appears that the first seven of the types are the ones most responsible here, even in log scale.

Top 10 types of events causing most expenditure

Economic.Damage[1:10,]
## # A tibble: 10 × 4
##    EVTYPE            Total.PROPDMG Total.CROPDMG     Total.DMG
##    <fct>                     <dbl>         <dbl>         <dbl>
##  1 FLOOD             144657709807     5661968450 150319678257 
##  2 HURRICANE/TYPHOON  69305840000     2607872800  71913712800 
##  3 TORNADO            56947380676.     414953270  57362333946.
##  4 STORM SURGE        43323536000           5000  43323541000 
##  5 HAIL               15735267513.    3025954473  18761221986.
##  6 FLASH FLOOD        16822723978.    1421317100  18244041078.
##  7 DROUGHT             1046106000    13972566000  15018672000 
##  8 HURRICANE          11868319010     2741910000  14610229010 
##  9 RIVER FLOOD         5118945500     5029459000  10148404500 
## 10 ICE STORM           3944927860     5022113500   8967041360

Let’s see using a graph how significant these are

ggplot(Economic.Damage[1:10,], aes(EVTYPE, Total.DMG)) + 
  geom_col() + 
  guides(x =  guide_axis(angle = 90))

It appears that the first four of the types are the ones most responsible here.

Results

Types of events most harmful with respect to population health:

with total fatalities and total injury by each

Population.Health[1:7,]
## # A tibble: 7 × 3
##   EVTYPE         Total.fatality Total.injury
##   <fct>                   <dbl>        <dbl>
## 1 TORNADO                  5633        91346
## 2 EXCESSIVE HEAT           1903         6525
## 3 FLASH FLOOD               978         1777
## 4 HEAT                      937         2100
## 5 LIGHTNING                 816         5230
## 6 TSTM WIND                 504         6957
## 7 FLOOD                     470         6789

Types of events having the greatest economic consequences:

with total damage, total property damage and total crop damage caused by each.

Economic.Damage[1:4, c(1, 4, 2, 3)]
## # A tibble: 4 × 4
##   EVTYPE                Total.DMG Total.PROPDMG Total.CROPDMG
##   <fct>                     <dbl>         <dbl>         <dbl>
## 1 FLOOD             150319678257  144657709807     5661968450
## 2 HURRICANE/TYPHOON  71913712800   69305840000     2607872800
## 3 TORNADO            57362333946.  56947380676.     414953270
## 4 STORM SURGE        43323541000   43323536000           5000