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.
In the results, Tornado is the event have the most harmful to population health and the most greatest damage to economic in 2010.
The data for this assignment come in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size. We can download the file from the course web site: Storm Data
The events in the database start in the year 1950 and end in November 2011. In the earlier years of the database there are generally fewer events recorded, most likely due to a lack of good records. More recent years should be considered more complete. So, in this assignment, we take data in 2010 to do the analysis.
We first read data from the csv file.
data <- read.csv("repdata_data_StormData.csv")
After reading in the data we check the first few rows (there are 902,297) rows in this dataset.
str(data)
## 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : chr "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
## $ BGN_TIME : chr "0130" "0145" "1600" "0900" ...
## $ TIME_ZONE : chr "CST" "CST" "CST" "CST" ...
## $ COUNTY : num 97 3 57 89 43 77 9 123 125 57 ...
## $ COUNTYNAME: chr "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
## $ STATE : chr "AL" "AL" "AL" "AL" ...
## $ EVTYPE : chr "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
## $ BGN_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ BGN_AZI : chr "" "" "" "" ...
## $ BGN_LOCATI: chr "" "" "" "" ...
## $ END_DATE : chr "" "" "" "" ...
## $ END_TIME : chr "" "" "" "" ...
## $ 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 : chr "" "" "" "" ...
## $ END_LOCATI: chr "" "" "" "" ...
## $ 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: chr "K" "K" "K" "K" ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: chr "" "" "" "" ...
## $ WFO : chr "" "" "" "" ...
## $ STATEOFFIC: chr "" "" "" "" ...
## $ ZONENAMES : chr "" "" "" "" ...
## $ 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 : chr "" "" "" "" ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
Then we transform data in column BGN_DATE.
data$BGN_DATE <- as.Date(data$BGN_DATE,"%m/%d/%Y %H:%M:%S")
In this assignment, we take data in 2010 to do the analysis
data1 <- subset(data,BGN_DATE>=as.Date("2010","%Y")&BGN_DATE<as.Date("2011","%Y"))
We check distinct value of column PROPDMGEXP and CROPDMGEXP
unique(data1$PROPDMGEXP)
## [1] "K" "M" "B" "0"
unique(data1$CROPDMGEXP)
## [1] "K" "M" "B"
Then, we calculate column PROPDMG and CROPDMG in millions USD unit
nr <- nrow(data1)
for(i in 1:nr){
if(data1$PROPDMGEXP[i]=="K"){
data1$PROPDMG[i] <- data1$PROPDMG[i]/1000
} else {
if(data1$PROPDMGEXP[i]=="M"){
data1$PROPDMG[i] <- data1$PROPDMG[i]*1
} else {
if(data1$PROPDMGEXP[i]=="B"){
data1$PROPDMG[i] <- data1$PROPDMG[i]*1000
} else {
data1$PROPDMG[i] <- data1$PROPDMG[i]/1000000
}
}
}
if(data1$CROPDMGEXP[i]=="K"){
data1$CROPDMG[i] <- data1$CROPDMG[i]/1000
} else {
if(data1$CROPDMGEXP[i]=="M"){
data1$CROPDMG[i] <- data1$CROPDMG[i]*1
} else {
if(data1$CROPDMGEXP[i]=="B"){
data1$CROPDMG[i] <- data1$CROPDMG[i]*1000
} else {
data1$CROPDMG[i] <- data1$CROPDMG[i]/1000000
}
}
}
}
We calculate total of fatalities and injuries each event in 2010.
event <- unique(data1$EVTYPE)
le <- length(event)
harmhealth <- vector(mode="numeric")
for(i in 1:le){
harmhealth <- c(harmhealth,sum(data1[data1$EVTYPE==event[i],]$FATALITIES)+sum(data1[data1$EVTYPE==event[i],]$INJURIES))
}
data2 <- data.frame(event,harmhealth)
head(data2)
## event harmhealth
## 1 HAIL 32
## 2 THUNDERSTORM WIND 422
## 3 TORNADO 6846
## 4 HEAVY RAIN 4
## 5 FLOOD 200
## 6 FLASH FLOOD 93
Then, we plot top 10 of the most harmful population health events in 2010.
top10 <- data2[order(harmhealth,decreasing = TRUE),][1:10,]
library(ggplot2)
ggplot(top10,aes(x=event,y=harmhealth))+geom_col()+theme(axis.text.x=element_text(angle=45,hjust=1,vjust=1))+labs(x="Event",y="Harmful to population health",title="The most harmful events to population health")
So, Tornado is the most harmful event with respect to population health in 2010.
top10[which.max(top10$harmhealth),]$event
## [1] "TORNADO"
top10[which.max(top10$harmhealth),]$harmhealth
## [1] 6846
We calculate total of property damage and crop damage each event in 2010.
damage <- vector(mode="numeric")
for(i in 1:le){
damage <- c(damage,sum(data1[data1$EVTYPE==event[i],]$PROPDMG)+sum(data1[data1$EVTYPE==event[i],]$CROPDMG))
}
data3 <- data.frame(event,damage)
head(data3)
## event damage
## 1 HAIL 3565.6780
## 2 THUNDERSTORM WIND 539.1496
## 3 TORNADO 10032.9212
## 4 HEAVY RAIN 32.7545
## 5 FLOOD 8149.4451
## 6 FLASH FLOOD 1645.2595
Then, we plot top 10 of the events have the greatest economic consequences.
top10i <- data3[order(damage,decreasing = TRUE),][1:10,]
ggplot(top10i,aes(x=event,y=damage))+geom_col()+theme(axis.text.x=element_text(angle=45,hjust=1,vjust=1))+labs(x="Event",y="Damage in millions USD",title="The events have the greatest damege to economic")
Therefore, Tornado also have the most greatest damage to economic in 2010.
top10i[which.max(top10i$damage),]$event
## [1] "TORNADO"
top10i[which.max(top10i$damage),]$damage
## [1] 10032.92