Synopsis

This is a brief analysis of Storm Data with the aim to find events with highest number of fatalities and highest property damage caused. Since the source data is not very consistent (the list of events changes dramatically in time), first part of the analysis involves checking which events are recorded in which years to select the time frame and list of events that are directly comparable.

Loading data and libraries

The following program relies on these libraries to be loaded.

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(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(tidyr)
library(ggplot2)

Load the data table as a CSV from your working directory.

data<-read.csv("repdata_data_StormData.csv")

Data Processing

The BGN_DATE variable with the date of the event in recoded for the analytical purposes to a year and years are broken into longer periods for quick overview of the historical data.

data$date<- as.Date(data$BGN_DATE,format = "%m/%d/%Y")
data$year<-as.integer(year(data$date))
data$period<-cut(data$year,breaks=c(1950,1970,1980,1990,2000,2010,2021),include.lowest=TRUE,dig.lab=4)

Data exploration

Check whether there are any records in all periods and/or whether there are any dramatic changes in the ranks to get rid of the inconsistent data

# We get the rankings of the counts per period
n_by_period<-data %>%
  group_by(EVTYPE,period) %>%
  summarise(Number = n())
## `summarise()` has grouped output by 'EVTYPE'. You can override using the
## `.groups` argument.
n_by_period<-n_by_period %>% 
  arrange(period, Number) %>%
  group_by(period) %>%
  mutate(rank = rank(-Number))

#rankings are pivoted for an overview. We will later exclude event types for which we have no recent data and periods for which we have no consistent list of event types
n_wide <- n_by_period[,c("period","rank","EVTYPE")] %>% 
  pivot_wider(names_from = period, 
              values_from = rank)
n_wide <-arrange(n_wide[!is.na(n_wide$`(2010,2021]`),],`(2010,2021]`)

# Only periods since 2000 and the event types measured in these periods seem to be consistent and are kept
selected_types<-n_wide$EVTYPE
selected_periods<-c("(2000,2010]","(2010,2021]")

# Filtered data are saved as fdata
fdata<-data[data$period %in% selected_periods & data$EVTYPE %in% selected_types,]

Results

Fatalities

First the fatalities are analyzed. We get an ordered list of events by number of fatalities.

fatalities<-fdata %>%
  group_by(EVTYPE) %>%
  summarise(fatalities = sum(FATALITIES)) %>%
  arrange(-fatalities)

We filter the top 10 events by number of fatalities and plot the trend charts to check whether there is a trend or some special pattern (like high peaks in few years.)

top_fatalities<-fdata[fdata$EVTYPE %in% fatalities$EVTYPE[1:10],]
top_fatalities$EVTYPE<-factor(top_fatalities$EVTYPE,levels=fatalities$EVTYPE[1:10])

top_fatalities %>% 
  group_by(EVTYPE, year) %>% 
  summarize(sum = sum(FATALITIES)) %>%
  ggplot(aes(x = year, y = sum)) +
  geom_bar(stat='identity') +
  scale_x_continuous(breaks = ~ axisTicks(., log = FALSE)) +
  facet_wrap(~EVTYPE, ncol=4) +
  ylab("Number of fatalities")+
  ggtitle("Number of fatalities for top 10 events")
## `summarise()` has grouped output by 'EVTYPE'. You can override using the
## `.groups` argument.
Chart shows top 10 events sorted by number of fatalities since 2000

Chart shows top 10 events sorted by number of fatalities since 2000

Property damage

We repeat the analysis for property damage. We get an ordered list of events by toal property damage.

damage<-fdata %>%
  group_by(EVTYPE) %>%
  summarise(damage = sum(PROPDMG)) %>%
  arrange(-damage)

We filter the top 10 events by number of fatalities and plot the trend charts to check whether there is a trend or some special pattern (like high peaks in few years.)

top_damage<-fdata[fdata$EVTYPE %in% damage$EVTYPE[1:10],]
top_damage$EVTYPE<-factor(top_damage$EVTYPE,levels=damage$EVTYPE[1:10])

top_damage %>% 
  group_by(EVTYPE, year) %>% 
  summarize(sum = sum(PROPDMG)) %>% 
  ggplot(aes(x = year, y = sum)) +
  geom_bar(stat='identity') +
  scale_x_continuous(breaks = ~ axisTicks(., log = FALSE)) +
  facet_wrap(~EVTYPE, ncol=4) +
  ylab("Property damage")+
  ggtitle("Top 10 events by property damage") 
## `summarise()` has grouped output by 'EVTYPE'. You can override using the
## `.groups` argument.
Chart shows top 10 events sorted by total property damage since 2000

Chart shows top 10 events sorted by total property damage since 2000