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. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage.
Download the data from file URL and read the data from bz file.
fileUrl <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(fileUrl, 'data.csv.bz2')
Data <- read.csv("data.csv.bz2", stringsAsFactors = F)
variables <- c("EVTYPE","FATALITIES","INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")
Storm <- Data[variables]
head(Storm)
## 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
Transforming variables In this part, the variables EVTYPE, PROPDMGEXP and CROPDMGEXP are transformed to be more clear and certain. First of all, we rename of values from EVTYPE variable with the intention of doing more easy the reading of results.
Also, We change de values from PROPDMGEXP and CROPDMGEXP because the raw data is in letters classification, and to do analysis at number level was necessary modify the answer at number level.
library(plyr)
## Warning: package 'plyr' was built under R version 3.4.2
Storm$EVTYPE <- mapvalues(Storm$EVTYPE, from = c("TSTM WIND", "THUNDERSTORM WINDS", "RIVER FLOOD", "HURRICANE/TYPHOON", "HURRICANE"), to = c("THUNDERSTORM WIND", "THUNDERSTORM WIND", "FLOOD", "HURRICANE-TYPHOON", "HURRICANE-TYPHOON"))
Storm$PROPDMGEXP <- mapvalues(Storm$PROPDMGEXP, from = c("K", "M", "", "B", "m", "+", "0", "5", "6", "?","4","2","3","h","7","H","-","1","8"), to = c(10^3,10^6,1,10^9,10^6,1,1,10^5,10^6,1,10^4,10^2,10^3,10^3,10^7,10^2,1,1,10^8))
Storm$CROPDMGEXP <- mapvalues(Storm$CROPDMGEXP, from = c("M", "K", "m", "B", "?", "0", "k", "2"), to = c(10^6,10^3,10^3,10^9,1,1,10^3,10^2))
PROP <- (as.numeric(Storm$PROPDMGEXP)) * Storm$PROPDMG
CROP <- (as.numeric(Storm$CROPDMGEXP)) * Storm$CROPDMG
Storm$ECONDMG <- PROP + CROP
1.Which types of events are most harmful to population health?
2.Which types of events have the greatest economic consequences?
Approach : Get the total number of Injuries and fatalities for diiferent Event types.And calculate the total damages in decresing order
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.3
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
injuries.damages <- aggregate(INJURIES~EVTYPE, data = Storm, FUN = sum)
fatalities.damages <- aggregate(FATALITIES~EVTYPE, data = Storm, FUN = sum)
total.damages<- cbind(injuries.damages,FATALITIES=(fatalities.damages$FATALITIES))
total.damages2 <- mutate(total.damages, TOTAL=INJURIES+FATALITIES)
## Warning: package 'bindrcpp' was built under R version 3.4.2
total.damages2 <- total.damages2[order(total.damages2$TOTAL, decreasing = TRUE),]
library(knitr)
## Warning: package 'knitr' was built under R version 3.4.3
kable(total.damages2[1:10,], caption="10 Principals weather events that are the most injuries and fatalities impact in population")
| EVTYPE | INJURIES | FATALITIES | TOTAL | |
|---|---|---|---|---|
| 831 | TORNADO | 91346 | 5633 | 96979 |
| 758 | THUNDERSTORM WIND | 9353 | 701 | 10054 |
| 130 | EXCESSIVE HEAT | 6525 | 1903 | 8428 |
| 170 | FLOOD | 6791 | 472 | 7263 |
| 463 | LIGHTNING | 5230 | 816 | 6046 |
| 275 | HEAT | 2100 | 937 | 3037 |
| 153 | FLASH FLOOD | 1777 | 978 | 2755 |
| 426 | ICE STORM | 1975 | 89 | 2064 |
| 968 | WINTER STORM | 1321 | 206 | 1527 |
| 403 | HURRICANE-TYPHOON | 1321 | 125 | 1446 |
| Genera | te the bar plot to s | how harmful | l weather eve | nts and greatest economic consequences. |
barplot(height = (total.damages2$TOTAL[1:10]/(1e3)), names.arg = total.damages2$EVTYPE[1:10],col=terrain.colors(10, alpha = 1), main = "Top 10 Injuries and Fatalities for US Weather Events", ylab = "Number of Injuries and Fatalities (thousands)", las = 2, cex.names= 0.6)
economic.damage <- aggregate(ECONDMG~EVTYPE, data = Storm, FUN = sum)
economic.damage <- economic.damage[order(economic.damage$ECONDMG, decreasing = TRUE),]
kable(economic.damage[1:10,], caption="10 Principals weather events that are the most economically costly")
| EVTYPE | ECONDMG | |
|---|---|---|
| 35 | FLOOD | 148607551500 |
| 78 | HURRICANE-TYPHOON | 41806435800 |
| 127 | TORNADO | 16581900013 |
| 16 | DROUGHT | 14206287000 |
| 53 | HAIL | 11020743163 |
| 30 | FLASH FLOOD | 8749813302 |
| 85 | ICE STORM | 5925150850 |
| 115 | THUNDERSTORM WIND | 5497024289 |
| 109 | STORM SURGE/TIDE | 4641493000 |
| 150 | WILDFIRE | 3793838270 |
barplot(height = (economic.damage$ECONDMG[1:10]/(1e9)), names.arg = economic.damage$EVTYPE[1:10],col=terrain.colors(10, alpha = 1), main = "Top 10 Economically Costly Events for US Weather Events", ylab = "Cost ($ billions)", las = 2, cex.names= 0.6)
**Tornados are the most harmfull to population health and Floods cause the greatest economic consequences