This data analysis aims to address the following questions:
1.Across the United States, which types of events are most harmful with respect to
population health?
2.Across the United States, which types of events have the greatest economic consequences?
Using the database from the U.S. National Oceanic and Atmospheric Administration’s (NOAA), the findings of this analysis is as follows:
Tornado causes the most death and injuries among the recorded natural events, at 5600 deaths and 91400 injuries respectively.
Floods cause the most economic damage, with total property and crop damage at 15.78 billion USD.
The criteria of measurement for the extent of the harm is the number of deaths and injuries caused by the natural disasters.
#download the file from source
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2",destfile = "stormData.csv")
#unzip and read the file for use
data<- read.csv("./stormData.csv")
#read in dplyr 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
We first examine the data
head(data)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL
## 4 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL
## 5 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL
## 6 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL
## EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1 TORNADO 0 0
## 2 TORNADO 0 0
## 3 TORNADO 0 0
## 4 TORNADO 0 0
## 5 TORNADO 0 0
## 6 TORNADO 0 0
## COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1 NA 0 14.0 100 3 0 0
## 2 NA 0 2.0 150 2 0 0
## 3 NA 0 0.1 123 2 0 0
## 4 NA 0 0.0 100 2 0 0
## 5 NA 0 0.0 150 2 0 0
## 6 NA 0 1.5 177 2 0 0
## INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1 15 25.0 K 0
## 2 0 2.5 K 0
## 3 2 25.0 K 0
## 4 2 2.5 K 0
## 5 2 2.5 K 0
## 6 6 2.5 K 0
## LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1 3040 8812 3051 8806 1
## 2 3042 8755 0 0 2
## 3 3340 8742 0 0 3
## 4 3458 8626 0 0 4
## 5 3412 8642 0 0 5
## 6 3450 8748 0 0 6
We are interested in only a few of these columns that would be useful for the analysis. “EVTYPE”-type of natural disaster “FATALITIES”-no. of deaths “INJURIES”- no. of injuries “PROPDMG”-incurred property damage “PROPDMGEXP”-order of magnitude for property damage “CROPDMG”-incurred crop damage “CROPDMGEXP”-order of magnitude for crop damage
The sum of fatalities and injuries is grouped by their respective natural causes and in descending order to observe the most damaging natural diasters.
injuries<- aggregate(INJURIES~EVTYPE,data,sum)
injuries<- arrange(injuries,desc(INJURIES))
fatalities<-aggregate(FATALITIES~EVTYPE,data,sum)
fatalities<-arrange(fatalities,desc(FATALITIES))
The number of natural disasters is limited to the top 10 so that the results will not oversaturate the barplots.
injuries<-injuries[1:10,]
fatalities<-fatalities[1:10,]
par(mfrow=c(1,2),mar = c(11, 2, 2, 1), mgp = c(5, 0.5, 0))
barplot(fatalities$FATALITIES,names.arg=fatalities$EVTYPE,las=3,main="Fatalities from Natural Disasters",ylab="No. of Fatalities", col="black")
barplot(injuries$INJURIES,names.arg=injuries$EVTYPE,las=3,main="Injuries from Natural Disasters",ylab="Number of Fatalities",col="red")
In order to calculate the total economic damage, we need to multiply the column values of property and crop damage by their order of magnitude as given by the “PROPDMGEXP” and “CROPDMGEXP” column, with H=10^2, K=10^3, M=10^6 and B=10^9. This gives the actual values of the damage which is stored as new variables: ‘actualprop’ and ‘actualcrop’. An additional column ‘totaldamage’ is created as the sum of both damages.
data$actualprop=0
data[data$PROPDMGEXP=="H",]$actualprop<-data[data$PROPDMGEXP=="H",]$PROPDMG*10^2
data[data$PROPDMGEXP=="K",]$actualprop<-data[data$PROPDMGEXP=="K",]$PROPDMG*10^3
data[data$PROPDMGEXP=="M",]$actualprop<-data[data$PROPDMGEXP=="M",]$PROPDMG*10^6
data[data$PROPDMGEXP=="B",]$actualprop<-data[data$PROPDMGEXP=="B",]$PROPDMG*10^9
data$actualcrop=0
data[data$CROPDMGEXP=="H",]$actualcrop<-data[data$CROPDMGEXP=="H",]$CROPDMG*10^2
data[data$CROPDMGEXP=="K",]$actualcrop<-data[data$CROPDMGEXP=="K",]$CROPDMG*10^3
data[data$CROPDMGEXP=="M",]$actualcrop<-data[data$CROPDMGEXP=="M",]$CROPDMG*10^6
data[data$CROPDMGEXP=="B",]$actualcrop<-data[data$CROPDMGEXP=="B",]$CROPDMG*10^9
data$totaldamage<-data$actualcrop+data$actualprop
The type of damages are aggregated based on the natural disasters.
cropdamage<- aggregate(actualcrop~EVTYPE,data,sum)
cropdamage<- arrange(cropdamage,desc(actualcrop))
propdamage<-aggregate(actualprop~EVTYPE,data,sum)
propdamage<-arrange(propdamage,desc(actualprop))
alldamage<-aggregate(totaldamage~EVTYPE,data,sum)
alldamage<-arrange(alldamage,desc(totaldamage))
The number of natural disasters is limited to the top 10 so that the results will not oversaturate the barplots.
cropdamage<-cropdamage[1:10,]
propdamage<-propdamage[1:10,]
alldamage<-alldamage[1:10,]
par(mfrow=c(1,3),mar = c(15, 4, 3, 2), mgp = c(3, 1, 0))
barplot(cropdamage$actualcrop,names.arg = cropdamage$EVTYPE,las=3, main="Damage to Crops",col="green")
barplot(propdamage$actualprop,names.arg=propdamage$EVTYPE,las=3, main="Damage to Property",col="blue")
barplot(alldamage$totaldamage, names.arg = alldamage$EVTYPE,las=3, main="Total Damage",col="grey")
From the results, we observe that torando inflicts the greatest damage on public health while flood inflicts the biggest economic damage.