This is the analysis for the Peer Assignment 2 of Coursera Reproducible Research. The data was extracted from the U.S. National Oceanic and Atmospheric Administration's (NOAA) storm database. We want to know what is the harmful dister in the States. The analysis revealed that tornado is the most harmful with repect to the total population of fatalities and injuries. However, according to the economic damage cost, flood cause the most harmful effect.
Read the data file.
D <- read.csv("repdata-data-StormData.csv")
According to the Strom Data Documentation, the variable PROPDMGEXP indicates the magniude of PROPDMG, such as “K” for thousands, “M” for millions and “B” for billions.
Define the function for magnitude and set the magnitude values of PROPDMGMAG and CROPDMGMAG to the variables PROPDMGMAG and CROPDMGMAG respectively.
magnitude <- function(x) {
switch(x, K = 10^3, M = 10^6, B = 10^9, 1)
}
D$PROPDMGMAG <- mapply(magnitude, as.character(D$PROPDMGEXP))
D$CROPDMGMAG <- mapply(magnitude, as.character(D$CROPDMGEXP))
The sum for each disatrous events are calculated for fatalities and injuries. The top-10 harmful disaster is as follows.
D.sum <- aggregate(D[, c("FATALITIES", "INJURIES")], list(D$EVTYPE), sum)
D.sum$POPULATION <- D.sum$FATALITIES + D.sum$INJURIES
# D.sum <- D.sum[order( -D.sum$FATALITIES - D.sum$INJURIES), ]
D.sum <- D.sum[order(-D.sum$POPULATION), ]
names(D.sum) <- c("disaster", "fatalities", "injuries", "population")
row.names(D.sum) <- 1:dim(D.sum)[1]
head(D.sum, 10, addrownums = FALSE)
## disaster fatalities injuries population
## 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
## 7 FLASH FLOOD 978 1777 2755
## 8 ICE STORM 89 1975 2064
## 9 THUNDERSTORM WIND 133 1488 1621
## 10 WINTER STORM 206 1321 1527
The most harmful disater is TORNADO. The data was sorted in the summing order of fatalities and injuries population for ranking.
par(mai = c(0.5, 2.5, 0.5, 0.5))
D.mat <- t(as.matrix(D.sum[1:10, 2:4])) # matrix of fatalities and injuries
colnames(D.mat) <- D.sum[1:10, "disaster"]
D.mat <- D.mat[, order(D.mat[3, ])]
D.mat
## WINTER STORM THUNDERSTORM WIND ICE STORM FLASH FLOOD HEAT
## fatalities 206 133 89 978 937
## injuries 1321 1488 1975 1777 2100
## population 1527 1621 2064 2755 3037
## LIGHTNING FLOOD TSTM WIND EXCESSIVE HEAT TORNADO
## fatalities 816 470 504 1903 5633
## injuries 5230 6789 6957 6525 91346
## population 6046 7259 7461 8428 96979
barplot(D.mat[1:2, ], las = 1, legend.text = rownames(D.mat), xlim = c(0, 180000),
horiz = TRUE)
As shown in the barplot, TORNADO is absolutely the most harmful disaster with respect to the population suffered from the event.
What type of event causes the most harmful economic damage?
D.dmg <- data.frame(damagecost = D$PROPDMG * D$PROPDMGMAG + D$CROPDMG * D$CROPDMGMAG,
disaster = D$EVTYPE)
D.dmg.distr <- aggregate(D.dmg$damagecost, list(D.dmg$disaster), sum)
names(D.dmg.distr) <- c("disaster", "damagecost")
D.dmg.distr <- D.dmg.distr[order(-D.dmg.distr$damagecost), ]
row.names(D.dmg.distr) <- 1:dim(D.dmg.distr)[1]
head(D.dmg.distr, 10)
## disaster damagecost
## 1 FLOOD 1.503e+11
## 2 HURRICANE/TYPHOON 7.191e+10
## 3 TORNADO 5.734e+10
## 4 STORM SURGE 4.332e+10
## 5 HAIL 1.875e+10
## 6 FLASH FLOOD 1.756e+10
## 7 DROUGHT 1.502e+10
## 8 HURRICANE 1.461e+10
## 9 RIVER FLOOD 1.015e+10
## 10 ICE STORM 8.967e+09
D.econo10 <- subset(D.dmg, disaster %in% D.dmg.distr[1:10, ]$disaster)
D.econo10$disaster <- factor(D.econo10$disaster, levels = rev(D.dmg.distr[1:10,
]$disaster))
D.econo10 <- D.econo10[order(D.econo10$disaster, decreasing = TRUE), ]
par(mai = c(0.5, 2.5, 0.5, 0.5))
stripchart(D.econo10$damagecost ~ D.econo10$disaster, xlab = "Total Cost of Economic Damage",
xlim = c(1, 10^11), method = "jitter", las = 1, log = "x")
When we look at the distribution of disaster and damagecost, we found that many event of middle damage highly spread in the middle for the former although the event spread very sparsely in higher damage cost for the latter.