Synopsis

This analysis reports exploratory analysis of publicly available National Oceanic and Atmospheric Administration dataset. The dataset contains details of natural disasters in US. We have used a subset of this data pertaining to years between 1995 - 2011. The analysis shows that there is minimal overlap between the events that cause maximal financial impact and those that cause maximal loss of life & limb. For example, heavy rain and hurricane are associated with high crop & property damage. Whereas,tornadoes are associated with maximum loss of life & limb. This analysis is limited due to varying coding of event types and lack of an inferential analysis.

Data Processing

The data has been downloaded from Coursera website as a .bz compressed file. Further processing is reproducible with the code. In line with our questions we will retain data limited to the type of event, fatalities, injuries, property damage and crop damage. Information about the data is available at Documentation.
Figure 1 shows that the documented number of events has increased substantially since 1995. As noted in the assignment instructions the data pertaining to later years is much more reliable.

dat <- read.csv(file = "repdata_data_StormData.csv.bz2",stringsAsFactors = FALSE,comment.char = "")
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 object is masked from 'package:base':
## 
##     date
library(ggplot2)
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang
dat$DATE <- mdy_hms(dat$BGN_DATE)
dat$YEAR <- year(dat$DATE)
dat1 <- dat %>% 
  group_by(YEAR)%>% 
    summarise("Number of Events"= n()) 
plot(x = dat1$YEAR,y = dat1$`Number of Events`,type = "l") 

dat1 <- dat %>%
          filter(YEAR > 1994) %>%
        select(EVTYPE,FATALITIES,INJURIES,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP)
remove(dat)

A summary of variables, thier type and number of levels is shown in Table 1.

library(knitr)
library(magrittr)
library(xtable)
table1 <- data.frame("class" = sapply(dat1,class),"Unique/Levels" = sapply(dat1,function(x)
                    length(unique(x))))
table1 <- xtable(table1)
print(table1,"html")
class Unique.Levels
EVTYPE character 799
FATALITIES numeric 41
INJURIES numeric 139
PROPDMG numeric 1389
PROPDMGEXP character 18
CROPDMG numeric 432
CROPDMGEXP character 9

As we see there are two variables that are not easily understood: PROPDMGEXP and CROPDMGEXP. From the documentation we know that these are exponents for the corresponding damage estimates. We will have to recode them to yeild real estimates of damage on the same scale. Table 2 and 3 show the existing alphanumeric codes, while Table 4 and 5 show the values after recoding.

table2 <- dat1 %>% group_by(PROPDMGEXP) %>% summarise(n())
table2 <- xtable(table2)
print.AsIs(table2,"html")
PROPDMGEXP n()
1 294516
2
1
3 ? 5
4
4
5 0 187
6 1 25
7 2 13
8 3 4
9 4 3
10 5 26
11 6 3
12 7 5
13 8 1
14 B 37
15 H 6
16 K 378706
17 m 6
18 M 7952
table3 <- dat1 %>% group_by(CROPDMGEXP) %>% summarise(n())
table3 <- xtable(table3)
print(table3,"html")
CROPDMGEXP n()
1 400088
2 ? 5
3 0 8
4 2 1
5 B 7
6 k 3
7 K 279483
8 m 1
9 M 1904
dat1$PROPDMGEXP <- as.character(dat1$PROPDMGEXP)
Propdmg_key <- c("0"="0","1"="1","2"="2","3"="3","4"="4","5"="5","6"="6","7"="7",
                "8"="8","9"="9",
                 "H" = "2",
                 "h" = "2",
                 "K" = "3",
                 "k" = "3",
                 "M" = "6",
                 "m" = "6",
                 "B" = "9")
dat1$PROPDMGEXPNEW <- recode(dat1$PROPDMGEXP, !!!Propdmg_key,.default = NA_character_,.missing = NA_character_)
dat1$PROPDMGEXPNEW <- as.numeric(dat1$PROPDMGEXPNEW)
dat1$CROPDMGEXP <- as.character(dat1$CROPDMGEXP)
dat1$CROPDMGEXPNEW <- recode(dat1$CROPDMGEXP,!!! Propdmg_key,.default = NA_character_,.missing = NA_character_)
dat1$CROPDMGEXPNEW <- as.numeric(dat1$CROPDMGEXPNEW)
dat1$PROPDMGNEW <- dat1$PROPDMG * (10^dat1$PROPDMGEXPNEW)
dat1$PROPDMGNEW[dat1$PROPDMG == 0] <- 0   
dat1$CROPDMGNEW <- dat1$CROPDMG * (10^dat1$CROPDMGEXPNEW)
dat1$CROPDMGNEW[dat1$CROPDMG == 0] <- 0
table4 <- dat1 %>% group_by(PROPDMGEXPNEW) %>% summarise(n())
table4 <- xtable(table4)
print(table4,"html")
PROPDMGEXPNEW n()
1 0.00 187
2 1.00 25
3 2.00 19
4 3.00 378710
5 4.00 3
6 5.00 26
7 6.00 7961
8 7.00 5
9 8.00 1
10 9.00 37
11 294526
table5 <- dat1 %>% group_by(CROPDMGEXPNEW) %>% summarise(n())
table5 <- xtable(table5)
print(table5,"html")
CROPDMGEXPNEW n()
1 0.00 8
2 2.00 1
3 3.00 279486
4 6.00 1905
5 9.00 7
6 400093

Transforming the damage estimate columns so that all the information is available in a single column i.e. PROPDMGNEW will have estimate of property damage as an integer and CROPDMGNEW will have crop damage estimate.

dat1$PROPDMGNEW <- dat1$PROPDMG * (10^dat1$PROPDMGEXPNEW)
dat1$PROPDMGNEW[dat1$PROPDMG == 0] <- 0   
dat1$CROPDMGNEW <- dat1$CROPDMG * (10^dat1$CROPDMGEXPNEW)
dat1$CROPDMGNEW[dat1$CROPDMG == 0] <- 0 

We also see that types of events i.e. EVTYPE has a large number of unique values (as shown in Table 1).Whereas, as per Page 5 of Documentation only 48 types of events are permitted. 1. Segregate all entries that match any of the 48 Event types.
2. Manually examine the entries left behind.
3. Recode the 20 entries which are most frequent and mismatched.

ev1 <- c("Astronomical Low Tide" ,"Avalanche", 
"Blizzard", 
"Coastal Flood",
"Cold/Wind Chill", 
"Debris Flow", 
"Dense Fog", 
"Dense Smoke", 
"Drought", 
"Dust Devil", 
"Dust Storm", 
"Excessive Heat", 
"Extreme Cold/Wind Chill", 
"Flash Flood",
"Flood", 
"Frost/Freeze", 
"Funnel Cloud", 
"Freezing Fog", 
"Hail", 
"Heat", 
"Heavy Rain", 
"Heavy Snow", 
"High Surf", 
"High Wind", 
"Hurricane (Typhoon)", 
"Ice Storm", 
"Lake-Effect Snow", 
"Lakeshore Flood", 
"Lightning", 
"Marine Hai",
"Marine High Wind",
"Marine Strong Wind",
"Marine Thunderstorm Wind", 
"Rip Current", 
"Seiche", 
"Sleet" ,
"Storm Surge/Tide", 
"Strong Wind", 
"Thunderstorm Wind", 
"Tornado", 
"Tropical Depression", 
"Tropical Storm", 
"Tsunami", 
"Volcanic Ash", 
"Waterspout", 
"Wildfire", 
"Winter Storm", 
"Winter Weather" )
ev1 <- tolower(ev1)
ev2 <- tolower(dat1$EVTYPE)
mtch <- ev2 %in% ev1
dat2 <- cbind.data.frame(ev2,mtch)
dat2 <- dat2 %>% filter(mtch == FALSE) %>% group_by(ev2) %>% summarise("Number" = n()) %>% arrange(desc(Number))%>% slice(1:20)
dat2 <- xtable(dat2)
print(dat2,"html")
ev2 Number
1 tstm wind 128925
2 thunderstorm winds 10041
3 marine tstm wind 6175
4 urban/sml stream fld 3392
5 wild/forest fire 1446
6 winter weather/mix 1104
7 tstm wind/hail 1028
8 high winds 776
9 extreme cold 634
10 landslide 599
11 snow 551
12 fog 535
13 marine hail 442
14 wind 335
15 rip currents 304
16 flash flooding 295
17 flood/flash flood 258
18 storm surge 253
19 heavy surf/high surf 228
20 freezing rain 223
x <- grep(pattern = c("[^.]*tstm[^.]","thunderstorm winds"),ev2,ignore.case = TRUE)
## Warning in grep(pattern = c("[^.]*tstm[^.]", "thunderstorm winds"), ev2, :
## argument 'pattern' has length > 1 and only the first element will be used
ev2[x] <- "thunderstorm wind"
ev2 <- gsub(pattern = dat2$ev2[4],replacement = "flood",ev2)
ev2 <- gsub(pattern = dat2$ev2[17], replacement = "flash flood",ev2)
ev2 <- gsub(pattern = dat2$ev2[16], replacement = "flash flood",ev2)
ev2 <- gsub(pattern = dat2$ev2[5], replacement = "wildfire",ev2)
ev2 <- gsub(pattern = dat2$ev2[6], replacement = "winter weather",ev2)
ev2 <- gsub(pattern = dat2$ev2[7], replacement = "high wind",ev2)
ev2 <- gsub(pattern = dat2$ev2[8], replacement = "extreme cold/wind chill",ev2)
ev2 <- gsub(pattern = dat2$ev2[9], replacement = "debris flow",ev2)
ev2 <- gsub(pattern = dat2$ev2[10], replacement = "heavy snow",ev2)
ev2 <- gsub(pattern = dat2$ev2[11], replacement = "dense fog",ev2)
ev2 <- gsub(pattern = dat2$ev2[12], replacement = "marine hail",ev2)
ev2 <- gsub(pattern = dat2$ev2[13], replacement = "strong wind",ev2)
ev2 <- gsub(pattern = dat2$ev2[14], replacement = "rip current",ev2)
ev2 <- gsub(pattern = dat2$ev2[18], replacement = "storm surge/tide",ev2)
ev2 <- gsub(pattern = dat2$ev2[19], replacement = "high surf",ev2)
ev2 <- gsub(pattern = dat2$ev2[20], replacement = "freezing fog",ev2)
dat1$EVTYPE <- ev2
remove(list = c("dat2","ev1","ev2","mtch","x","Propdmg_key"))

Results

EVENTS RESPONSIBLE FOR MAXIMUM LOSS OF PROPERTY & CROPS

Since, loss of property & crops is quantified in USD we can add the two to get a combined estimate. Table 6 shows the top 20 events associated with maximum capital loss.

dat1 <- dat1 %>% mutate("ECONOMIC IMPACT" = PROPDMGNEW+CROPDMGNEW)
dat2 <- 
  dat1 %>%
    group_by(EVTYPE) %>%
      summarise("ECONOMIC IMPACT" = mean(`ECONOMIC IMPACT`,na.rm = TRUE))%>%
        arrange(desc(`ECONOMIC IMPACT`))
table6 <- dat2[1:20,]  
table6 <- xtable(table6)
print(table6,"html")
EVTYPE ECONOMIC IMPACT
1 heavy rain/severe weather 1250000000.00
2 hurricane/typhoon 817201281.82
3 hurricane opal 354649555.56
4 storm surge/tide 170725458.50
5 excessive wetness 142000000.00
6 hurricane opal/debris flow/rip current chill 110000000.00
7 severe thunderstorm 109137272.73
8 hurricane 85613111.82
9 hailstorm 80333333.33
10 cold and wet conditions 66000000.00
11 winter storm debris flow/rip current chill 65000000.00
12 hurricane erin 56301428.57
13 typhoon 54641363.64
14 early frost 42000000.00
15 damaging freeze 38028750.00
16 storm surge/tide/tide 31365121.62
17 flood/rain/rip currents 18800000.00
18 coastal flooding/erosion 15000000.00
19 heavy rain/high surf 15000000.00
20 tropical storm 12180075.37

EVENTS ASSOCIATED WITH HIGHEST HUMAN TOLL

To combine the injuries we can use wieghing such that injuries are weighed 0.5 relative to deaths. Figure 2 shows the top 20 types of events associated with maximum human toll. Table 7 & 8 reports the top 20 types of events associated with maximum total number of casulaties and injuries between 1995 and 2011.

dat2 <- dat1 %>%
                mutate("HUMAN TOLL" = FATALITIES+(0.5*INJURIES))
dat2 <- dat2 %>%
                group_by(EVTYPE)%>%
                summarise("HUMAN TOLL" = mean(`HUMAN TOLL`,na.rm = TRUE)) %>% 
                arrange(desc(`HUMAN TOLL`))
dat2 <- dat2 %>% mutate("Order" = row_number()) %>% slice(1:20)
dat2$Order <- as.numeric(dat2$Order)
dat2 %>%
  ggplot(aes(x = Order))+
    geom_linerange(aes(x = Order, ymin = 0, ymax = dat2$`HUMAN TOLL`), color = "red")+
    geom_point(aes(x = Order, y = dat2$`HUMAN TOLL`),color = "red")+
    scale_x_continuous(breaks = dat2$Order,
        labels = dat2$EVTYPE,
        name = NULL) +
    labs(title = "Human Toll due to Natural Disasters in US (1995 - 2011)",
      subtitle = "Top 20 Event Types", y = "Human Toll (No. of fatalities + 0.5* No. of injuries)",x = "Event Types")+
  coord_flip()

 dat2 <- dat1 %>% 
  group_by(EVTYPE) %>%
  summarise("Total Fatalities" = sum(FATALITIES,na.rm = TRUE)) 
table7 <- dat2 %>% arrange(desc(`Total Fatalities`)) %>% slice(1:20) 
dat2 <- dat1 %>% 
  group_by(EVTYPE) %>%
  summarise("Total Injuries" = sum(INJURIES,na.rm = TRUE)) 
table8 <- dat2 %>% arrange(desc(`Total Injuries`)) %>% slice(1:20)
table7 <- xtable(table7) 
table8 <- xtable(table8)
print(table7,"html")
EVTYPE Total Fatalities
1 excessive heat 1903.00
2 tornado 1545.00
3 flash flood 950.00
4 heat 924.00
5 lightning 729.00
6 flood 451.00
7 thunderstorm rip current 387.00
8 rip current 380.00
9 high rip current 241.00
10 avalanche 223.00
11 rip currents 205.00
12 winter storm 195.00
13 strong rip current 164.00
14 heat wave 161.00
15 heavy dense strong rip current 153.00
16 high surf 144.00
17 debris flow/rip current chill 136.00
18 debris flow 128.00
19 cold/rip current chill 95.00
20 heavy rain 95.00
print(table8,"html")
EVTYPE Total Injuries
1 tornado 21765.00
2 flood 6848.00
3 excessive heat 6525.00
4 thunderstorm rip current 5164.00
5 lightning 4631.00
6 heat 2030.00
7 flash flood 1739.00
8 wildfire 1456.00
9 winter storm 1298.00
10 hurricane/typhoon 1275.00
11 high rip current 1093.00
12 strong rip current 996.00
13 hail 916.00
14 heavy dense strong rip current 803.00
15 winter weather 470.00
16 thunderstorm rip currents 444.00
17 dust storm 420.00
18 blizzard 385.00
19 heat wave 378.00
20 ice storm 357.00

Limitations

This analysis has following limitations: 1 The data cleaning for event types is incomplete.
2 No inferential analysis is undertaken.

sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18362)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=English_India.1252  LC_CTYPE=English_India.1252   
## [3] LC_MONETARY=English_India.1252 LC_NUMERIC=C                  
## [5] LC_TIME=English_India.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] xtable_1.8-4    magrittr_1.5    knitr_1.22      ggplot2_3.1.1  
## [5] lubridate_1.7.4 dplyr_0.8.0.1  
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.1       munsell_0.5.0    tidyselect_0.2.5 colorspace_1.4-1
##  [5] R6_2.4.0         rlang_0.3.4      plyr_1.8.4       stringr_1.4.0   
##  [9] tools_3.6.0      grid_3.6.0       gtable_0.3.0     xfun_0.6        
## [13] withr_2.1.2      htmltools_0.3.6  lazyeval_0.2.2   yaml_2.2.0      
## [17] assertthat_0.2.1 digest_0.6.18    tibble_2.1.1     crayon_1.3.4    
## [21] purrr_0.3.2      glue_1.3.1       evaluate_0.13    rmarkdown_1.12  
## [25] labeling_0.3     stringi_1.4.3    compiler_3.6.0   pillar_1.3.1    
## [29] scales_1.0.0     pkgconfig_2.0.2