The basic goal of this research is to explore the NOAA Storm Database and answer some basic questions about severe weather events. The questions follow below:
*Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health.
*Across the United States, which types of events have the greatest economic consequences.
*Fatalities and injuiries are the main indicator of how harmful an event is on the population.
*Propery and crop damage are the main indicators of how harmful an event is on the economy.
We will begin by downloading the data to our directory and reading it into R. We will then look at the variables in the file and what type of data they are.
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2","./StormData.csv")
s.d<-read.csv("StormData.csv")
str(s.d)
## '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 ...
We will load the packages we are going to use.
require(lubridate)
## Warning: package 'lubridate' was built under R version 3.2.5
require(dplyr)
## Warning: package 'dplyr' was built under R version 3.2.5
require(ggplot2)
We notice that the date are not being recognised as dates, so we will need to transform those.
s.d$END_DATE<-mdy_hms(s.d$END_DATE)
s.d$BGN_DATE<-mdy_hms(s.d$BGN_DATE)
If we re-run the str() function on our dataset we will see the date variables have now been converted.
As we plan on looking at both the population and economical effects it will be ideal to create subsets of the main data file (s.d) that contains only the variables we are interested in.
s.pop<-select(s.d, EVTYPE, FATALITIES, INJURIES)
s.econ<-select(s.d,EVTYPE, PROPDMG, CROPDMG, PROPDMGEXP, CROPDMGEXP)
Now we have 2 variables that have the population factors (i.e FATALITIES,INJURIES) and economic factors (i.e PROPDMG,CROPDMG,PROPDMGEXP,CROPDMGEXP)
We now need to replace the letters used to represent exponentials in the data
levels(s.econ$PROPDMGEXP)<-c("0", "0", "0", "0", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "3", "3", "3", "6", "6")
levels(s.econ$CROPDMGEXP)<-c("0", "0", "0", "2", "9", "3", "3", "6", "6")
s.econ$p.d<-s.econ$PROPDMG*(10^as.numeric(s.econ$PROPDMGEXP))
s.econ$c.d<-s.econ$CROPDMG*(10^as.numeric(s.econ$CROPDMGEXP))
Now we have new variables with the actual property and crop damage.
We can proceed to answering the questions we have set aside.
Our aim is to look at the event that has caused the highest count of fatalities and injuries.
s.pop.fat<-aggregate(FATALITIES~EVTYPE,data=s.pop,FUN=sum)
s.pop.fat$CATEGORY<-0
s.pop.fat$CATEGORY<-"FATALITIES"
names(s.pop.fat)[2]<-"FAT.INJ"
s.pop.fat<-s.pop.fat[order(s.pop.fat$FAT.INJ,decreasing=T),]
s.pop.fat<-head(s.pop.fat,10)
s.pop.inj<-aggregate(INJURIES~EVTYPE,data=s.pop,FUN=sum)
s.pop.inj$CATEGORY<-0
s.pop.inj$CATEGORY<-"INJURIES"
names(s.pop.inj)[2]<-"FAT.INJ"
s.pop.inj<-s.pop.inj[order(s.pop.inj$FAT.INJ,decreasing=T),]
s.pop.inj<-head(s.pop.inj,10)
s.pop.data2<-rbind(s.pop.fat,s.pop.inj)
s.pop.data2$CATEGORY<-factor(s.pop.data2$CATEGORY)
m.f<-s.pop.fat[1,1]
m.i<-s.pop.inj[1,1]
m.pop.fat<-aggregate(FATALITIES~EVTYPE,data=s.pop,FUN=mean)
options(scipen=999)
m.fat<-m.pop.fat[order(m.pop.fat$FATALITIES,decreasing = T),][1,2]
ggplot(s.pop.data2, aes(x=EVTYPE, y=FAT.INJ, fill=CATEGORY)) +
geom_bar(stat="identity", position="dodge") +
facet_grid(.~CATEGORY, scales="free_y") +
theme(axis.text.x = element_text(angle = 90, vjust=0.5, hjust = 1)) +
xlab("Events") +
ylab("Total number involved") +
labs(title="Top 10 events causing death or injury (1950-2011)")
From the figure above we can see that TORNADO has caused the most fatalites with a mean of 25, aswell as TORNADO having caused the most injuries.
We will replicate the process above on the economy data set holding the economical factors.
s.econ.data<-aggregate(p.d+c.d~EVTYPE,data=s.econ,FUN=sum)
s.econ.data<-s.econ.data[order(s.econ.data$`p.d + c.d`,decreasing = T),]
s.econ.data<-head(s.econ.data,10)
names(s.econ.data)[2]<-"TOTAL.DAMAGE"
m.e<-s.econ.data[1,1]
m.econ.data<-aggregate(p.d+c.d~EVTYPE,data=s.econ,FUN=mean)
m.econ.value<-m.econ.data[order(m.econ.data$`p.d + c.d`,decreasing = T),][1,2]
m.econ.name<-m.econ.data[order(m.econ.data$`p.d + c.d`,decreasing = T),][1,1]
ggplot(s.econ.data, aes(x=EVTYPE, y=TOTAL.DAMAGE)) +
geom_bar(stat="identity", position="dodge") +
theme(axis.text.x = element_text(angle = 90, vjust=0.5, hjust = 1)) +
xlab("Events") +
ylab("Total Damage($)") +
labs(title="Top 10 events causing economical damage (1950-2011)")
From the graph we see FLOOD has led to the most economical damage. However, looking at the mean, we see TORNADOES, TSTM WIND, HAIL has the highest mean with 16000250000.
So we have identified TORNADO as the most fatal event to the population, and FLOOD the most impactful on the economy.We can then focus our efforts in determining ways to reduce this in the following years.