Synopsis

This work is part of the final assigment of the course Reproducible research. The objective is to explore the data contained in the “U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database” and determine, across the United States, which types of events (as indicated in the EVTYPEEVTYPE variable) are most harmful with respect to population health, and which ones have the greatest economic consequences.

Data Processing

The data for this projects was downloaded from “https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2”.

# download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", destfile = "data.csv.bz2")
data<-read.csv("data.csv.bz2", sep = "," )

This dataset contains the following categories:

names(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"

There are two variables that can be associated with harm to population FATALITIES and INJURIES. Let’s get the mean of these variables for each event type:

deaths_evtype <-tapply(data$FATALITIES, INDEX=as.factor(data$EVTYPE), FUN=mean)
injuries_evtype <-tapply(data$INJURIES, INDEX=as.factor(data$EVTYPE), FUN=mean)

And sorting them in decreasing order we get:

head(sort(deaths_evtype, decreasing = TRUE))
## TORNADOES, TSTM WIND, HAIL              COLD AND SNOW 
##                  25.000000                  14.000000 
##      TROPICAL STORM GORDON      RECORD/EXCESSIVE HEAT 
##                   8.000000                   5.666667 
##               EXTREME HEAT          HEAT WAVE DROUGHT 
##                   4.363636                   4.000000
head(sort(injuries_evtype, decreasing = TRUE))
##             Heat Wave TROPICAL STORM GORDON            WILD FIRES 
##                  70.0                  43.0                  37.5 
##         THUNDERSTORMW    HIGH WIND AND SEAS       SNOW/HIGH WINDS 
##                  27.0                  20.0                  18.0

To answer the second question we notice that there are two possible economic losses: PROPDMG related to private property and CROPDMG related to crops. Each one has a column containing the unit corresponding to the amount given. For example, looking the units in PROPDMGEXP

unique(data$PROPDMGEXP)
##  [1] "K" "M" ""  "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"

We can see that they seems to be mixed in format. W need therefore to tidy them and put them in a consistent format that we can use. For this I will assume h=H=100(10^2), K=1000(10^3), M=m=1000000(10^6), B=1000000000 (10^9). I will also assume that the numerical values in this variable correspond to the corresponding power of ten. Finally, looking at the values associated with the non-numerical units:

max(data$PROPDMG[data$PROPDMGEXP=="?"])  #this is irrelevant, as all the values are zero
## [1] 0
max(data$PROPDMG[data$PROPDMGEXP==""])
## [1] 75
max(data$PROPDMG[data$PROPDMGEXP=="-"])
## [1] 15
max(data$PROPDMG[data$PROPDMGEXP=="+"])
## [1] 60

I will assume them to represent a unit (10^0==1) (I will check later if these values correspond to old inputs) I will, therefore, replace the values in these columns with the corresponding power of ten:

data2<-data
data2$PROPDMGEXP[data$PROPDMGEXP=="h"|data$PROPDMGEXP=="H"]<-as.numeric(2)
data2$PROPDMGEXP[data$PROPDMGEXP=="K"|data$PROPDMGEXP=="k"]<-as.numeric(3)
data2$PROPDMGEXP[data$PROPDMGEXP=="m"|data$PROPDMGEXP=="M"]<-as.numeric(6)
data2$PROPDMGEXP[data$PROPDMGEXP=="b"|data$PROPDMGEXP=="B"]<-as.numeric(9)
data2$PROPDMGEXP[data$PROPDMGEXP=="?"|data$PROPDMGEXP==""|data$PROPDMGEXP=="+"|data$PROPDMGEXP=="-"]<-as.numeric(1)

data2$CROPDMGEXP[data$CROPDMGEXP=="h"|data$CROPDMGEXP=="H"]<-as.numeric(2)
data2$CROPDMGEXP[data$CROPDMGEXP=="K"|data$CROPDMGEXP=="k"]<-as.numeric(3)
data2$CROPDMGEXP[data$CROPDMGEXP=="m"|data$CROPDMGEXP=="M"]<-as.numeric(6)
data2$CROPDMGEXP[data$CROPDMGEXP=="b"|data$CROPDMGEXP=="B"]<-as.numeric(9)
data2$CROPDMGEXP[data$CROPDMGEXP=="?"|data$CROPDMGEXP==""|data$CROPDMGEXP=="+"|data$CROPDMGEXP=="-"]<-as.numeric(1)

Checking now:

unique(data2$PROPDMGEXP)
##  [1] "3" "6" "1" "9" "0" "5" "4" "2" "7" "8"
unique(data2$CROPDMGEXP)
## [1] "1" "6" "3" "9" "0" "2"

Have now numerical values that we can manipulate. The total economic cost of an event will be therefore the sum of both variables:

data$ECONOMIC<- as.numeric(data2$PROPDMG)*10**as.numeric(data2$PROPDMGEXP)+as.numeric(data2$CROPDMG)*10**as.numeric(data2$CROPDMGEXP)
economic_evtype<-tapply(data$ECONOMIC, INDEX=as.factor(data$EVTYPE), FUN=mean)  #average per event
head(sort(economic_evtype, decreasing = TRUE))
## TORNADOES, TSTM WIND, HAIL  HEAVY RAIN/SEVERE WEATHER 
##                 1602500000                 1250000000 
##          HURRICANE/TYPHOON             HURRICANE OPAL 
##                  817201282                  354649556 
##                STORM SURGE                 WILD FIRES 
##                  165990579                  156025000

Results

We can now see that the event types causing the maximum deaths are TORNADOES, TSTM WIND, HAIL and COLD AND SNOW

barplot(sort(deaths_evtype, decreasing = TRUE)[1:10], col = as.factor(names(sort(deaths_evtype, decreasing = TRUE)[1:10])), legend.text = TRUE,  axisnames=FALSE, ylab = "Deaths", main = "Average number of deaths per event type")

Events with more number of injuries are Heat Wave and TROPICAL STORM GORDON.

barplot(sort(injuries_evtype, decreasing = TRUE)[1:10], col = as.factor(names(sort(injuries_evtype, decreasing = TRUE)[1:10])), legend.text = TRUE,  axisnames=FALSE, ylab = "Number of injuries", main = "Average number of injuries per event type")

On the same way, the events causing more economical losses (to private property and/or to the crops) are: TORNADOES, TSTM WIND, HAIL and HEAVY RAIN/SEVERE WEATHER.

barplot(sort(economic_evtype, decreasing = TRUE)[1:10], col = as.factor(names(sort(economic_evtype, decreasing = TRUE)[1:10])), legend.text = TRUE,  axisnames=FALSE, ylab = "Economic loss (US$)")