1: Synopsis

The basic goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events.

Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. Many severe events can result in fatalities, injuries, and property damage, and preventing such outcomes to the extent possible is a key concern.

This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database in order to answer two questions.

1.Across the United States, which types of events are most harmful with respect to population health?

2.Across the United States, which types of events have greatest economic consequences?

2.1: Data Processing

Set working directory and load dplyr package. Read data from the csv file.

setwd("C:/Users/Digital Hub/Course5/Week4")
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.2
## 
## 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
data1 <- read.csv("repdata_data_StormData.csv.bz2")

Check dimensions and view column names of the data.

dim(data1)
## [1] 902297     37
head(data1)
##   STATE__           BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1       1  4/18/1950 0:00:00     0130       CST     97     MOBILE    AL
## 2       1  4/18/1950 0:00:00     0145       CST      3    BALDWIN    AL
## 3       1  2/20/1951 0:00:00     1600       CST     57    FAYETTE    AL
## 4       1   6/8/1951 0:00:00     0900       CST     89    MADISON    AL
## 5       1 11/15/1951 0:00:00     1500       CST     43    CULLMAN    AL
## 6       1 11/15/1951 0:00:00     2000       CST     77 LAUDERDALE    AL
##    EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1 TORNADO         0                                               0
## 2 TORNADO         0                                               0
## 3 TORNADO         0                                               0
## 4 TORNADO         0                                               0
## 5 TORNADO         0                                               0
## 6 TORNADO         0                                               0
##   COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1         NA         0                      14.0   100 3   0          0
## 2         NA         0                       2.0   150 2   0          0
## 3         NA         0                       0.1   123 2   0          0
## 4         NA         0                       0.0   100 2   0          0
## 5         NA         0                       0.0   150 2   0          0
## 6         NA         0                       1.5   177 2   0          0
##   INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1       15    25.0          K       0                                    
## 2        0     2.5          K       0                                    
## 3        2    25.0          K       0                                    
## 4        2     2.5          K       0                                    
## 5        2     2.5          K       0                                    
## 6        6     2.5          K       0                                    
##   LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1     3040      8812       3051       8806              1
## 2     3042      8755          0          0              2
## 3     3340      8742          0          0              3
## 4     3458      8626          0          0              4
## 5     3412      8642          0          0              5
## 6     3450      8748          0          0              6

Select only a few relevant columns from the data. Remove previous data. View column names of the subset data. alternative: x <- c(“EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP”) data2 <- storm[x]

data2 <- data1[ , c(8, 23:28)]
rm(data1)
head(data2)
##    EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1 TORNADO          0       15    25.0          K       0           
## 2 TORNADO          0        0     2.5          K       0           
## 3 TORNADO          0        2    25.0          K       0           
## 4 TORNADO          0        2     2.5          K       0           
## 5 TORNADO          0        2     2.5          K       0           
## 6 TORNADO          0        6     2.5          K       0

View summary of FATALITIES and INJURIES from subset data.

summary(data2$FATALITIES)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
##   0.0000   0.0000   0.0000   0.0168   0.0000 583.0000
summary(data2$INJURIES)
##      Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
##    0.0000    0.0000    0.0000    0.1557    0.0000 1700.0000

Aggregate fatalities and injuries by event types in descending order and subset the top 10.

fatal <- aggregate(FATALITIES~EVTYPE, data2, sum)
fatal <- arrange(fatal, desc(FATALITIES))
fatal <- fatal[1:10, ]
fatal
##            EVTYPE FATALITIES
## 1         TORNADO       5633
## 2  EXCESSIVE HEAT       1903
## 3     FLASH FLOOD        978
## 4            HEAT        937
## 5       LIGHTNING        816
## 6       TSTM WIND        504
## 7           FLOOD        470
## 8     RIP CURRENT        368
## 9       HIGH WIND        248
## 10      AVALANCHE        224
injury <- aggregate(INJURIES~EVTYPE, data2, sum)
injury <- arrange(injury, desc(INJURIES))
injury <- injury[1:10, ]
injury
##               EVTYPE INJURIES
## 1            TORNADO    91346
## 2          TSTM WIND     6957
## 3              FLOOD     6789
## 4     EXCESSIVE HEAT     6525
## 5          LIGHTNING     5230
## 6               HEAT     2100
## 7          ICE STORM     1975
## 8        FLASH FLOOD     1777
## 9  THUNDERSTORM WIND     1488
## 10              HAIL     1361

Merge fatalities and injuries in one data set. Create bar plot.

totals<- merge(fatal, injury, by.x = "EVTYPE", by.y = "EVTYPE")
totals<-arrange(totals,desc(FATALITIES+INJURIES))
event_type <- totals$EVTYPE
barplot(t(totals[,-1]), names.arg = event_type, main="Top 10 Disaster Casualties", ylim = c(0,100000), cex.names = 0.4, cex.axis = 0.5,cex.lab = 0.5, cex.main = 0.8, las=2, beside = T, col = c("red", "blue"),ylab = "Number of Casualties", xlab = "Event Types" )
legend("topright",c("Fatalities","Injuries"),fill=c("red","blue"))

2.2: Data Processing

Convert property and crop damage numbers (H=10^2, K=10^3, M =10^6, and B=10^9). Create two new variables: PROPDAMAGE, CROPDAMAGE

data2$PROPDAMAGE = 0
data2[data2$PROPDMGEXP == "H", ]$PROPDAMAGE = data2[data2$PROPDMGEXP == "H", ]$PROPDMG * 10^2
data2[data2$PROPDMGEXP == "K", ]$PROPDAMAGE = data2[data2$PROPDMGEXP == "K", ]$PROPDMG * 10^3
data2[data2$PROPDMGEXP == "M", ]$PROPDAMAGE = data2[data2$PROPDMGEXP == "M", ]$PROPDMG * 10^6
data2[data2$PROPDMGEXP == "B", ]$PROPDAMAGE = data2[data2$PROPDMGEXP == "B", ]$PROPDMG * 10^9
data2$CROPDAMAGE = 0
data2[data2$CROPDMGEXP == "H", ]$CROPDAMAGE = data2[data2$CROPDMGEXP == "H", ]$CROPDMG * 10^2
data2[data2$CROPDMGEXP == "K", ]$CROPDAMAGE = data2[data2$CROPDMGEXP == "K", ]$CROPDMG * 10^3
data2[data2$CROPDMGEXP == "M", ]$CROPDAMAGE = data2[data2$CROPDMGEXP == "M", ]$CROPDMG * 10^6
data2[data2$CROPDMGEXP == "B", ]$CROPDAMAGE = data2[data2$CROPDMGEXP == "B", ]$CROPDMG * 10^9

Aggregate property and crop damage by event types in descending order and subset the top 10.

ecodamage <- aggregate(PROPDAMAGE + CROPDAMAGE ~ EVTYPE, data2, sum)
names(ecodamage) = c("EVENT_TYPE", "TOTAL_DAMAGE")
ecodamage <- arrange(ecodamage, desc(TOTAL_DAMAGE))
ecodamage <- ecodamage[1:10, ]
ecodamage$TOTAL_DAMAGE <- ecodamage$TOTAL_DAMAGE/10^9
ecodamage$EVENT_TYPE <- factor(ecodamage$EVENT_TYPE, levels = ecodamage$EVENT_TYPE)
head(ecodamage)
##          EVENT_TYPE TOTAL_DAMAGE
## 1             FLOOD    150.31968
## 2 HURRICANE/TYPHOON     71.91371
## 3           TORNADO     57.34061
## 4       STORM SURGE     43.32354
## 5              HAIL     18.75290
## 6       FLASH FLOOD     17.56213

Create barplot.

with(ecodamage, barplot(TOTAL_DAMAGE, names.arg = EVENT_TYPE, main = "Total Property and Crop Damage by Top 10 Event Types", beside = T, cex.names = 0.5, cex.axis = 0.5, cex.lab = 0.6, cex.main = 0.8, las=2, col = "green", ylab = "Total Damage in USD (10^9)", xlab = "Event Types"))

3: Results

Q1.Tornado has the hightest level of both Injuries and Fatalities.

Q2.Flood has the hightest economic impact.