Analysis synopsis

The U.S. National Oceanic and Atmospheric Administration’s store data of the mayor enviromental and storm events throughout the United States. Keeping data about when they happened and their incidents. Casualties, economic impacts, injuries or property damage. This kind of events create insecurity and in some cases collapse of social services and early attencion by the autorithies. For this matter this study tries to understand in first place which events are the more harmful for the population health and those which have the worse economic consequences.

Library loading

Load treatment package

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

Load ploting interface

library(ggplot2)

Environment preparation

Download data file

url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
destfile ='repdata-data-StormData.csv'
if(!file.exists(destfile)){
        download.file(url, destfile)
}

Read data file.

event.db <- read.csv(file = "repdata-data-StormData.csv", header = TRUE, sep = ",")

Check the amount of data.

dim(event.db)
## [1] 902297     37

Review the variables names.

names(event.db)
##  [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"

Review the variables data types

str(event.db)
## 'data.frame':    902297 obs. of  37 variables:
##  $ STATE__   : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
##  $ BGN_TIME  : Factor w/ 3608 levels "00:00:00 AM",..: 272 287 2705 1683 2584 3186 242 1683 3186 3186 ...
##  $ TIME_ZONE : Factor w/ 22 levels "ADT","AKS","AST",..: 7 7 7 7 7 7 7 7 7 7 ...
##  $ COUNTY    : num  97 3 57 89 43 77 9 123 125 57 ...
##  $ COUNTYNAME: Factor w/ 29601 levels "","5NM E OF MACKINAC BRIDGE TO PRESQUE ISLE LT MI",..: 13513 1873 4598 10592 4372 10094 1973 23873 24418 4598 ...
##  $ STATE     : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ EVTYPE    : Factor w/ 985 levels "   HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : Factor w/ 35 levels "","  N"," NW",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_LOCATI: Factor w/ 54429 levels "","- 1 N Albion",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_DATE  : Factor w/ 6663 levels "","1/1/1993 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_TIME  : Factor w/ 3647 levels ""," 0900CST",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ COUNTY_END: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ COUNTYENDN: logi  NA NA NA NA NA NA ...
##  $ END_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_AZI   : Factor w/ 24 levels "","E","ENE","ESE",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_LOCATI: Factor w/ 34506 levels "","- .5 NNW",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ LENGTH    : num  14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
##  $ WIDTH     : num  100 150 123 100 150 177 33 33 100 100 ...
##  $ F         : int  3 2 2 2 2 2 2 1 3 3 ...
##  $ MAG       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ FATALITIES: num  0 0 0 0 0 0 0 0 1 0 ...
##  $ INJURIES  : num  15 0 2 2 2 6 1 0 14 0 ...
##  $ PROPDMG   : num  25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
##  $ PROPDMGEXP: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ WFO       : Factor w/ 542 levels ""," CI","$AC",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ STATEOFFIC: Factor w/ 250 levels "","ALABAMA, Central",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ ZONENAMES : Factor w/ 25112 levels "","                                                                                                               "| __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ LATITUDE  : num  3040 3042 3340 3458 3412 ...
##  $ LONGITUDE : num  8812 8755 8742 8626 8642 ...
##  $ LATITUDE_E: num  3051 0 0 0 0 ...
##  $ LONGITUDE_: num  8806 0 0 0 0 ...
##  $ REMARKS   : Factor w/ 436781 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...

Data procesing

It is necesary to isolate the results for injuries, fatalities and damages. Those variables will lead us to answer the questions of this analysis.

Injuries

Events with unless 1 injury

injuries.event <- event.db %>% group_by(EVTYPE) %>% summarize(total.injuries = sum(INJURIES, na.rm = TRUE)) %>% filter(total.injuries!=0) %>% arrange(-total.injuries)
injuries.event <- injuries.event[1:6,]
injuries.event
## # A tibble: 6 x 2
##   EVTYPE         total.injuries
##   <fct>                   <dbl>
## 1 TORNADO                 91346
## 2 TSTM WIND                6957
## 3 FLOOD                    6789
## 4 EXCESSIVE HEAT           6525
## 5 LIGHTNING                5230
## 6 HEAT                     2100

Ploting the injuries distribution top 6

p <- ggplot(injuries.event, aes(x = reorder(EVTYPE, -total.injuries) , y =total.injuries )) + geom_bar(stat="identity") + ggtitle("Injuries by Event") + xlab("Event") + ylab("Number of Injuries")
p

Fatalities

Events with unless 1 fatality

fatalities.event <- event.db %>% group_by(EVTYPE) %>% summarize(total.fatalities = sum(FATALITIES)) %>% filter(total.fatalities!=0) %>% arrange(-total.fatalities)
fatalities.event <- fatalities.event[1:6,]
fatalities.event
## # A tibble: 6 x 2
##   EVTYPE         total.fatalities
##   <fct>                     <dbl>
## 1 TORNADO                    5633
## 2 EXCESSIVE HEAT             1903
## 3 FLASH FLOOD                 978
## 4 HEAT                        937
## 5 LIGHTNING                   816
## 6 TSTM WIND                   504

Ploting the fatalities distribution top 6

p <- ggplot(fatalities.event, aes(x = reorder(EVTYPE, -total.fatalities) , y =total.fatalities )) + geom_bar(stat="identity") + ggtitle("Fatalities by Event") + xlab("Event") + ylab("Number of fatalities")
p

Economic Damage

In here we have two economic causes, the property damage and the crop one. the result of economical consequencs has to be the sum of both

But first of all It has to be reviewed the multipliyers related to both.

head(event.db$PROPDMGEXP,5)
## [1] K K K K K
## Levels:  - ? + 0 1 2 3 4 5 6 7 8 B h H K m M
head(event.db$CROPDMGEXP,5)
## [1]     
## Levels:  ? 0 2 B k K m M

And convert them properly by property

event.db$PROPEXP[event.db$PROPDMGEXP == "" ] <- 1
event.db$PROPEXP[event.db$PROPDMGEXP == "0"] <- 1
event.db$PROPEXP[event.db$PROPDMGEXP == "1"] <- 10
event.db$PROPEXP[event.db$PROPDMGEXP == "2"] <- 100
event.db$PROPEXP[event.db$PROPDMGEXP == "3"] <- 1000
event.db$PROPEXP[event.db$PROPDMGEXP == "4"] <- 10000
event.db$PROPEXP[event.db$PROPDMGEXP == "5"] <- 1e+05
event.db$PROPEXP[event.db$PROPDMGEXP == "6"] <- 1e+06
event.db$PROPEXP[event.db$PROPDMGEXP == "7"] <- 1e+07
event.db$PROPEXP[event.db$PROPDMGEXP == "8"] <- 1e+08
event.db$PROPEXP[event.db$PROPDMGEXP == "H"] <- 100          
event.db$PROPEXP[event.db$PROPDMGEXP == "h"] <- 100
event.db$PROPEXP[event.db$PROPDMGEXP == "K"] <- 1000        
event.db$PROPEXP[event.db$PROPDMGEXP == "M"] <- 1e+06
event.db$PROPEXP[event.db$PROPDMGEXP == "m"] <- 1e+06
event.db$PROPEXP[event.db$PROPDMGEXP == "B"] <- 1e+09        
event.db$PROPEXP[event.db$PROPDMGEXP == "+"] <- 0
event.db$PROPEXP[event.db$PROPDMGEXP == "-"] <- 0
event.db$PROPEXP[event.db$PROPDMGEXP == "?"] <- 0

And by crop

event.db$CROPEXP[event.db$CROPDMGEXP  == "" ] <- 1
event.db$CROPEXP[event.db$CROPDMGEXP  == "0"] <- 1
event.db$CROPEXP[event.db$CROPDMGEXP  == "2"] <- 100
event.db$CROPEXP[event.db$CROPDMGEXP  == "k"] <- 100
event.db$CROPEXP[event.db$CROPDMGEXP  == "K"] <- 1000        
event.db$CROPEXP[event.db$CROPDMGEXP  == "M"] <- 1e+06
event.db$CROPEXP[event.db$CROPDMGEXP  == "m"] <- 1e+06
event.db$CROPEXP[event.db$CROPDMGEXP  == "?"] <- 0

Events with biggest economic damage top 6

damage.event <- event.db %>% group_by(EVTYPE) %>% summarize(total.damage= sum((PROPDMG * PROPEXP) + (CROPDMG * CROPEXP))) %>% filter(total.damage!=0) %>% arrange(-total.damage)
damage.event <- damage.event[1:6,]
damage.event
## # A tibble: 6 x 2
##   EVTYPE       total.damage
##   <fct>               <dbl>
## 1 FLOOD       150319678257 
## 2 TORNADO      57362333886.
## 3 STORM SURGE  43323541000 
## 4 HAIL         18760846686.
## 5 FLASH FLOOD  18243991078.
## 6 HURRICANE    14610229010

Ploting the fatalities distribution top 6

p <- ggplot(damage.event, aes(x = reorder(EVTYPE, -total.damage) , y =total.damage)) + geom_bar(stat="identity") + ggtitle("Total Damage by Event") + xlab("Event") + ylab("Damage amount")
p

Results

  1. We could say that tornados are the most harmful phenomenon which has more injuries and fatalities level

  2. In the other way the Floods is the one which creates the bigger economic disasters. Joining the property loses and crops ones.