Title

Analysis of storms data across the United States and impact on population health and economic activity

Synopsis

The objective ot the analysis is to assess the effects of severe weather events on both population and economy in the US using the NOAA Storm Database. The NOAA Storm Database contains the records of events for the time period between 1950 and November 2011.

Two sets of analysis have been carried out to find out the most harmful severe weather events with respect to:

  1. Population health (fatalities and injuries)
  2. Economy (damage to property and crops )

Data Processing

Load and explore the data

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
# Download the dataset
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
f <- file.path(getwd(), "data.csv.bz2")


if (!file.exists("data.csv.bz2")) {
        download.file(url = urlData, destfile = "data.csv.bz2");
}


# Read the dataset
storm <- read.table("data.csv.bz2", header = TRUE, sep = ",", quote = "\"")

# Let's take a look at the summary and structure of the dataset
head(storm)
##   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
str(storm)
## 'data.frame':    902297 obs. of  37 variables:
##  $ STATE__   : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : chr  "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
##  $ BGN_TIME  : chr  "0130" "0145" "1600" "0900" ...
##  $ TIME_ZONE : chr  "CST" "CST" "CST" "CST" ...
##  $ COUNTY    : num  97 3 57 89 43 77 9 123 125 57 ...
##  $ COUNTYNAME: chr  "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
##  $ STATE     : chr  "AL" "AL" "AL" "AL" ...
##  $ EVTYPE    : chr  "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : chr  "" "" "" "" ...
##  $ BGN_LOCATI: chr  "" "" "" "" ...
##  $ END_DATE  : chr  "" "" "" "" ...
##  $ END_TIME  : chr  "" "" "" "" ...
##  $ COUNTY_END: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ COUNTYENDN: logi  NA NA NA NA NA NA ...
##  $ END_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_AZI   : chr  "" "" "" "" ...
##  $ END_LOCATI: chr  "" "" "" "" ...
##  $ LENGTH    : num  14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
##  $ WIDTH     : num  100 150 123 100 150 177 33 33 100 100 ...
##  $ F         : int  3 2 2 2 2 2 2 1 3 3 ...
##  $ MAG       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ FATALITIES: num  0 0 0 0 0 0 0 0 1 0 ...
##  $ INJURIES  : num  15 0 2 2 2 6 1 0 14 0 ...
##  $ PROPDMG   : num  25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
##  $ PROPDMGEXP: chr  "K" "K" "K" "K" ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: chr  "" "" "" "" ...
##  $ WFO       : chr  "" "" "" "" ...
##  $ STATEOFFIC: chr  "" "" "" "" ...
##  $ ZONENAMES : chr  "" "" "" "" ...
##  $ LATITUDE  : num  3040 3042 3340 3458 3412 ...
##  $ LONGITUDE : num  8812 8755 8742 8626 8642 ...
##  $ LATITUDE_E: num  3051 0 0 0 0 ...
##  $ LONGITUDE_: num  8806 0 0 0 0 ...
##  $ REMARKS   : chr  "" "" "" "" ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...

Subset the data to include only those variables that are required for the analysis. In the next step, create new variables for cost of property damage and cost of crop damage

library(dplyr)

# Subset the dataset to only keep the parameters of interest.Only keep columns with health related or property related impact. Ignore any observations where event type or property damage, crop damage and fatalities or injuries are not reported.

storm_subset <- storm %>% 
  select(c(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)) %>% 
  filter((EVTYPE != "" | FATALITIES > 0 | INJURIES > 0 | PROPDMG > 0 | PROPDMGEXP > 0 | CROPDMG> 0 | CROPDMGEXP > 0 ))

# Create new columns with total cost related to property / crop damages and convert to correct format
storm_subset$PROPDMG_COST <- case_when(storm_subset$PROPDMGEXP == "-" ~ storm_subset$PROPDMG * 10^0,
                                       storm_subset$PROPDMGEXP == "+" ~ storm_subset$PROPDMG * 10^0,
                                       storm_subset$PROPDMGEXP == "0" ~ storm_subset$PROPDMG * 10^0,
                                       storm_subset$PROPDMGEXP == "1" ~ storm_subset$PROPDMG * 10^1,
                                       storm_subset$PROPDMGEXP == "2" ~ storm_subset$PROPDMG * 10^2,
                                       storm_subset$PROPDMGEXP == "3" ~ storm_subset$PROPDMG * 10^3,
                                       storm_subset$PROPDMGEXP == "4" ~ storm_subset$PROPDMG * 10^4,
                                       storm_subset$PROPDMGEXP == "5" ~ storm_subset$PROPDMG * 10^5,
                                       storm_subset$PROPDMGEXP == "6" ~ storm_subset$PROPDMG * 10^6,
                                       storm_subset$PROPDMGEXP == "7" ~ storm_subset$PROPDMG * 10^7,
                                       storm_subset$PROPDMGEXP == "8" ~ storm_subset$PROPDMG * 10^8,
                                       storm_subset$PROPDMGEXP == "h" ~ storm_subset$PROPDMG * 10^2,
                                       storm_subset$PROPDMGEXP == "H" ~ storm_subset$PROPDMG * 10^2,
                                       storm_subset$PROPDMGEXP == "K" ~ storm_subset$PROPDMG * 10^3,
                                       storm_subset$PROPDMGEXP == "m" ~ storm_subset$PROPDMG * 10^6,
                                       storm_subset$PROPDMGEXP == "M" ~ storm_subset$PROPDMG * 10^6,
                                       storm_subset$PROPDMGEXP == "B" ~ storm_subset$PROPDMG * 10^9,
                                       storm_subset$PROPDMGEXP == "" ~ storm_subset$PROPDMG * 10^0)


storm_subset$CROPDMG_COST <- case_when(storm_subset$CROPDMGEXP == "?" ~ storm_subset$CROPDMG * 10^0,
                                       storm_subset$CROPDMGEXP == "0" ~ storm_subset$CROPDMG * 10^0,
                                       storm_subset$CROPDMGEXP == "2" ~ storm_subset$CROPDMG * 10^2,
                                       storm_subset$CROPDMGEXP == "k" ~ storm_subset$CROPDMG * 10^3,
                                       storm_subset$CROPDMGEXP == "K" ~ storm_subset$CROPDMG * 10^3,
                                       storm_subset$CROPDMGEXP == "m" ~ storm_subset$CROPDMG * 10^6,
                                       storm_subset$CROPDMGEXP == "M" ~ storm_subset$CROPDMG * 10^6,
                                       storm_subset$CROPDMGEXP == "B" ~ storm_subset$CROPDMG * 10^9,
                                       storm_subset$CROPDMGEXP == "" ~ storm_subset$CROPDMG * 10^0)

Summarize the events by highest economic impact

library(dplyr)

# Let's look at the events with highest economic impact

storm_cost_byevent <- storm_subset %>%
  group_by(EVTYPE) %>% 
  summarise(property = sum(PROPDMG_COST),
            crop = sum(CROPDMG_COST),
            total_cost = property + crop
            ) %>% 
  arrange(desc(total_cost))

head(storm_cost_byevent)
## # A tibble: 6 × 4
##   EVTYPE                 property        crop    total_cost
##   <chr>                     <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 DROUGHT             1046106000  13972566000  15018672000 
## 6 HURRICANE          11868319010   2741910000  14610229010

Summarize the events by highest impact on the population health

library(dplyr)

# Let's look at the events which has most impact on population health - in terms of death and injuries

storm_health_byevent <- storm_subset %>%
  group_by(EVTYPE) %>% 
  summarise(deaths = sum(FATALITIES),
            injuries = sum(INJURIES),
            total = deaths + injuries
            ) %>% 
  arrange(desc(total))

head(storm_health_byevent)
## # A tibble: 6 × 4
##   EVTYPE         deaths injuries total
##   <chr>           <dbl>    <dbl> <dbl>
## 1 TORNADO          5633    91346 96979
## 2 EXCESSIVE HEAT   1903     6525  8428
## 3 TSTM WIND         504     6957  7461
## 4 FLOOD             470     6789  7259
## 5 LIGHTNING         816     5230  6046
## 6 HEAT              937     2100  3037

Results

Events that causes highest economic impact

library(dplyr)
library(tidyr)

# Convert the the economic impact data frame to a longer data frame to use in next step for creating a chart

costs_byevent <- storm_cost_byevent %>% 
  pivot_longer(!EVTYPE, names_to="cost_type", values_to = "damage")

head(costs_byevent)
## # A tibble: 6 × 3
##   EVTYPE            cost_type        damage
##   <chr>             <chr>             <dbl>
## 1 FLOOD             property   144657709807
## 2 FLOOD             crop         5661968450
## 3 FLOOD             total_cost 150319678257
## 4 HURRICANE/TYPHOON property    69305840000
## 5 HURRICANE/TYPHOON crop         2607872800
## 6 HURRICANE/TYPHOON total_cost  71913712800
library(ggplot2)

# Create a chart to present the top 10 events with the highest economic impact

econ_plot <- ggplot(costs_byevent[1:30,], aes(x=reorder(EVTYPE, -damage), y = damage)) + 
  geom_bar(stat="identity", aes(fill=cost_type), width = 0.75, position = "dodge") +
  xlab("Event type") +
  theme(axis.text.x = element_text(angle=90, hjust=1)) +
  ylab("Economic impact") +
  ggtitle("Top 10 storm events in the US causing highest economic damage")
  
# Print the economic impact chart on the screen
econ_plot

Events that are most harmful to population health in term of deaths and injuries

library(dplyr)
library(tidyr)

# Convert the impact on population health dataframe to a longer data frame to use in next step for creating a chart

health_byevent <- storm_health_byevent %>% 
  pivot_longer(!EVTYPE, names_to="health_type", values_to = "value")

head(health_byevent)
## # A tibble: 6 × 3
##   EVTYPE         health_type value
##   <chr>          <chr>       <dbl>
## 1 TORNADO        deaths       5633
## 2 TORNADO        injuries    91346
## 3 TORNADO        total       96979
## 4 EXCESSIVE HEAT deaths       1903
## 5 EXCESSIVE HEAT injuries     6525
## 6 EXCESSIVE HEAT total        8428
library(ggplot2)

# Create a chart to present the top 10 events that are most harmful to population health

health_plot <- ggplot(health_byevent[1:30,], aes(x=reorder(EVTYPE, -value), y = value)) + 
  geom_bar(stat="identity", aes(fill=health_type), width = 0.75, position = "dodge") +
  xlab("Event type") +
  theme(axis.text.x = element_text(angle=90, hjust=1)) +
  ylab("Count") +
  ggtitle("Top 10 storm events in the US causing highest impact on population health")
  
# Print the population health impact chart on the screen
health_plot