From the storm database provided by the U.S. National Oceanic and Atmospheric Administration (NOAA), we examined fatalities, injuries, property damage, and crop damage caused by various events like floods, typhoons, tornadoes, hail, hurricanes, etc. Our aim was to identify the most detrimental events to the health of the U.S. population and those inflicting the most significant economic repercussions. Analysis of fatalities and injuries identified TORNADOES as the most harmful event to the health of the U.S. population. Conversely, assessing property and crop damage concluded that FLOODS pose the greatest economic consequences for the U.S.
The following questions shall be addressed in this project:
Across the United States, which types of events are most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
The data for this assignment come in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size. You can download the file from the course web site:
Storm data [47 MB]
Loading of required libraries and initial data set by saving it as ‘data’.
library(ggplot2)
library(dplyr)
library(lattice)
library(data.table)
data <- read.csv("repdata_data_StormData.csv.bz2")
Confirmation of the appropriate loading of dataset that should have 902297 records on 37 variables.
nr <- nrow(data)
nc <- ncol(data)
The dataset ‘data’ has 902297 records (rows) and 37 variables (columns) that confirm the appropriate reading of the data.
We examine the initial dataset ‘data’ starting with column names.
colnames(data)
## [1] "STATE__" "BGN_DATE" "BGN_TIME" "TIME_ZONE" "COUNTY"
## [6] "COUNTYNAME" "STATE" "EVTYPE" "BGN_RANGE" "BGN_AZI"
## [11] "BGN_LOCATI" "END_DATE" "END_TIME" "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE" "END_AZI" "END_LOCATI" "LENGTH" "WIDTH"
## [21] "F" "MAG" "FATALITIES" "INJURIES" "PROPDMG"
## [26] "PROPDMGEXP" "CROPDMG" "CROPDMGEXP" "WFO" "STATEOFFIC"
## [31] "ZONENAMES" "LATITUDE" "LONGITUDE" "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS" "REFNUM"
We need to identify which types of events are the most harmful with respect to population health and the greatest economic consequences. Therefore, we can narrow the dataset ‘data’ by extracting only relevant columns EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP with the values grater than 0.
data <- as.data.table(data)
data_extr <- data[(INJURIES > 0 | FATALITIES > 0 | PROPDMG > 0 | CROPDMG > 0), c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
Next, we examine the values of all variables in new dataset ‘data_extr’.
miss.data <- sum(!complete.cases(data_extr))
summary(data_extr)
## EVTYPE FATALITIES INJURIES PROPDMG
## Length:902297 Min. : 0.0000 Min. : 0.0000 Min. : 0.00
## Class :character 1st Qu.: 0.0000 1st Qu.: 0.0000 1st Qu.: 0.00
## Mode :character Median : 0.0000 Median : 0.0000 Median : 0.00
## Mean : 0.0168 Mean : 0.1557 Mean : 12.06
## 3rd Qu.: 0.0000 3rd Qu.: 0.0000 3rd Qu.: 0.50
## Max. :583.0000 Max. :1700.0000 Max. :5000.00
## PROPDMGEXP CROPDMG CROPDMGEXP
## Length:902297 Min. : 0.000 Length:902297
## Class :character 1st Qu.: 0.000 Class :character
## Mode :character Median : 0.000 Mode :character
## Mean : 1.527
## 3rd Qu.: 0.000
## Max. :990.000
unique(data_extr$PROPDMGEXP)
## [1] "K" "M" "" "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"
unique(data_extr$CROPDMGEXP)
## [1] "" "M" "K" "m" "B" "?" "0" "k" "2"
As we can see, 0 missing data is in new dataset ‘data_extr’. The variables FATALITIES, INJURIES, PROPDMG, and CROPDMG are numerical data, while the variables EVTYPE, PROPDMGEXP, and CROPDMGEXP contain characters. We convert character abbreviation of numbers with corresponded numeric values. Two columns of _DMG and _DMGEXP are merged as one column with numeric values for PROP and CROP, respectively. We also create overall parameters ‘HEALTH’ and ‘DAMAGE’.
replacements <- c("K" = 1e3, "M" = 1e6, "\"\"" = 1, "B" = 1e9, "m" = 1e6, "h" = 1e2, "+" = 1, "0" = 1, "5" = 1e5, "6" = 1e6, "?" = 1, "4" = 1e4, "2" = 1e2, "3" = 1e3, "7" = 1e7, "H" = 1e3, "-" = 1, "1" = 1e1, "8" = 1e8)
data_extr$PROPDMGEXP <- replacements[data_extr$PROPDMGEXP]
data_extr$CROPDMGEXP <- replacements[data_extr$CROPDMGEXP]
data_extr1 <- data_extr %>%
mutate(PROPDMGEXP = ifelse(is.na(PROPDMGEXP), 1, PROPDMGEXP)) %>%
mutate(CROPDMGEXP = ifelse(is.na(CROPDMGEXP), 1, CROPDMGEXP)) %>%
mutate(PROPDMG_T=PROPDMG*PROPDMGEXP) %>%
mutate(CROPDMG_T=CROPDMG*CROPDMGEXP) %>%
mutate(ALL_HEALTH=FATALITIES+INJURIES)%>%
mutate(ALL_DAMAGE=PROPDMG_T+CROPDMG_T)
data_extr2 <- data_extr1 %>%
select(-PROPDMG, -PROPDMGEXP, -CROPDMG, -CROPDMGEXP)
We aggregate the dataset “data_extr1” by variable EVTYPE with calculation of the sum of each numeric parameter. Then, we create two datasets ‘data_sum_h’ and ‘data_sum_d’ ordered by ‘HEALTH’ and ‘DAMAGE’, respectively.
data_sum <- aggregate(cbind(FATALITIES, INJURIES, PROPDMG_T, CROPDMG_T, ALL_HEALTH, ALL_DAMAGE) ~ EVTYPE, data = data_extr1, sum, na.rm = TRUE)
data_sum_h <- data_sum %>%
arrange(desc(ALL_HEALTH))
data_sum_d <- data_sum %>%
arrange(desc(ALL_DAMAGE))
To address the first question “Across the United States, which types of events are most harmful with respect to population health?”, we are going to use the ordered dataset ‘data_sum_h’.
head(data_sum_h)
## EVTYPE FATALITIES INJURIES PROPDMG_T CROPDMG_T ALL_HEALTH
## 1 TORNADO 5633 91346 56947380677 414953270 96979
## 2 EXCESSIVE HEAT 1903 6525 7753700 492402000 8428
## 3 TSTM WIND 504 6957 4484928495 554007350 7461
## 4 FLOOD 470 6789 144657709807 5661968450 7259
## 5 LIGHTNING 816 5230 930379430 12092090 6046
## 6 HEAT 937 2100 1797000 401461500 3037
## ALL_DAMAGE
## 1 57362333947
## 2 500155700
## 3 5038935845
## 4 150319678257
## 5 942471520
## 6 403258500
h1 <-data_sum_h[1,"EVTYPE"]
h2 <-data_sum_h[1,"ALL_HEALTH"]
h3 <-data_sum_h[1,"FATALITIES"]
h4 <-data_sum_h[1,"INJURIES"]
h5 <-data_sum_h[2,"EVTYPE"]
h6 <-data_sum_h[2,"ALL_HEALTH"]
data_sum_h1<-head(data_sum_h)
The analysis of first several columns from ordered dataset ‘data_sum_h’ revealed that the most harmful with respect to population health is the event TORNADO with overall number of cases as 9.6979^{4} including 5633 fatalities and 9.1346^{4} injuries. The graph below with top-10 US weather events having most harmful to population shows that the next event EXCESSIVE HEAT had much lower impact - 8428 cases.
ggplot(data_sum_h1, aes(x = factor(EVTYPE, levels = unique(EVTYPE)))) +
geom_bar(aes(y = ALL_HEALTH), fill="red", stat = "identity", position = "dodge", width = 0.7) +
xlab("Events") + ylab("Number of cases") + ggtitle("Top-10 US weather events having most harmful to population") + scale_x_discrete(guide = guide_axis(n.dodge = 2))
To address the second question “Across the United States, which types of events have the greatest economic consequences?”, we are going to use the ordered dataset ‘data_sum_d’.
head(data_sum_d)
## EVTYPE FATALITIES INJURIES PROPDMG_T CROPDMG_T ALL_HEALTH
## 1 FLOOD 470 6789 144657709807 5661968450 7259
## 2 HURRICANE/TYPHOON 64 1275 69305840000 2607872800 1339
## 3 TORNADO 5633 91346 56947380677 414953270 96979
## 4 STORM SURGE 13 38 43323536000 5000 51
## 5 HAIL 15 1361 15735272013 3025537890 1376
## 6 FLASH FLOOD 978 1777 16822673979 1421317100 2755
## ALL_DAMAGE
## 1 150319678257
## 2 71913712800
## 3 57362333947
## 4 43323541000
## 5 18760809903
## 6 18243991079
d1 <-data_sum_d[1,"EVTYPE"]
d2 <-data_sum_d[1,"ALL_DAMAGE"]
d3 <-data_sum_d[2,"EVTYPE"]
d4 <-data_sum_d[2,"ALL_DAMAGE"]
data_sum_d1<-head(data_sum_d)
The analysis of first several columns from ordered dataset ‘data_sum_d’ revealed that the most harmful with respect to economic consequences is the event FLOOD causing the loss of USD 1.5031968^{11}. The graph below with top-10 US weather events having greatest economic consequencesshows that the next event HURRICANE/TYPHOON had much lower loss - USD 7.1913713^{10}.
ggplot(data_sum_d1, aes(x = factor(EVTYPE, levels = unique(EVTYPE)))) +
geom_bar(aes(y = ALL_DAMAGE), fill="green", stat = "identity", position = "dodge", width = 0.7) + xlab("Events") + ylab("Economic consequences, USD") + ggtitle("Top-10 US weather events having greatest economic consequences") + scale_x_discrete(guide = guide_axis(n.dodge = 2))