Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. In this project, we have run an analysis on the available data from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. The 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. We will answer two following questions:
Q1. Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
Q2. Across the United States, which types of events have the greatest economic consequences?
According to the results of our analysis the answers to the above two questions are as follwos: A1. Tornados are the most harmfull weather events on population health in terms of the number of fatalities and injuries A2. Among all weather events floods cause the highest economic damage.
echo = TRUE cache= TRUE
Dowloading data file if it is not available in the folder and loading data:
if(!file.exists("repdata_data_StormData.csv.bz2")) {
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2",
destfile = "repdata_data_StormData.csv.bz2")
zipfile<- bzfile("repdata_data_StormData.csv.bz2")
}
NOAA_data <- read.csv("repdata_data_StormData.csv", header= TRUE, sep=",")
Calculating the property damage based on H, K, M, B units
NOAA_data[NOAA_data$PROPDMGEXP == "H", ]$PROPDMG = NOAA_data[NOAA_data$PROPDMGEXP == "H", ]$PROPDMG * 10^2
NOAA_data[NOAA_data$PROPDMGEXP == "K", ]$PROPDMG = NOAA_data[NOAA_data$PROPDMGEXP == "K", ]$PROPDMG * 10^3
NOAA_data[NOAA_data$PROPDMGEXP == "M", ]$PROPDMG = NOAA_data[NOAA_data$PROPDMGEXP == "M", ]$PROPDMG * 10^6
NOAA_data[NOAA_data$PROPDMGEXP == "B", ]$PROPDMG = NOAA_data[NOAA_data$PROPDMGEXP == "B", ]$PROPDMG * 10^9
Calculating the crop damage based on H, K, M, B units
NOAA_data[NOAA_data$CROPDMGEXP == "H", ]$CROPDMG = NOAA_data[NOAA_data$CROPDMGEXP == "H", ]$CROPDMG * 10^2
NOAA_data[NOAA_data$CROPDMGEXP == "K", ]$CROPDMG = NOAA_data[NOAA_data$CROPDMGEXP == "K", ]$CROPDMG * 10^3
NOAA_data[NOAA_data$CROPDMGEXP == "M", ]$CROPDMG = NOAA_data[NOAA_data$CROPDMGEXP == "M", ]$CROPDMG * 10^6
NOAA_data[NOAA_data$CROPDMGEXP == "B", ]$CROPDMG = NOAA_data[NOAA_data$CROPDMGEXP == "B", ]$CROPDMG * 10^9
Calculting the number of fatality for each event and ordering the five most harmful events events based on the descending number of fatalities
fatalities <- aggregate(FATALITIES ~ EVTYPE, data=NOAA_data, sum)
fatalities <- fatalities[order(-fatalities$FATALITIES), ][1:5, ]
fatalities$EVTYPE <- factor(fatalities$EVTYPE, levels = fatalities$EVTYPE)
Calculting the number of injury for each event and ordering the five most harmful events based on the descending number of injuries
injuries <- aggregate(INJURIES ~ EVTYPE, data= NOAA_data, sum)
injuries <- injuries[order(-injuries$INJURIES), ][1:5, ]
injuries$EVTYPE <- factor(injuries$EVTYPE, levels = injuries$EVTYPE)
Calculating the total economical damage including property and crop damages and ordering the events based on the descending amount
damages <- aggregate(PROPDMG + CROPDMG ~ EVTYPE, data=NOAA_data, sum)
names(damages) = c("EVTYPE", "TOTDAMAGE")
damages <- damages[order(-damages$TOTDAMAGE), ][1:5, ]
damages$EVTYPE <- factor(damages$EVTYPE, levels = damages$EVTYPE)
Ploting the graph displaying the five most harmful weather events causing fatalities and injuries ** According to the graphs, Tornado cause the highest fatalities and injuries over the united states. **
barplot(fatalities$FATALITIES, names.arg= fatalities$EVTYPE, col= "red",
xlab = "Weather Event", ylab = "Fatalities (no.)",
main = "The Number of fatalities for the five most harmful weather events")
barplot(injuries$INJURIES, names.arg= injuries$EVTYPE, col= "yellow",
xlab = "Weather Event", ylab = "Injuries (no.)",
main = "The Number of injuries for the five most harmful weather events")
Ploting the graph displaying the five most harmful weather events causing the highest economical damage ** The graph shows that the flood results in the highest monetary damage among all weather events. **
barplot(damages$TOTDAMAGE, names.arg= damages$EVTYPE, col= "brown",
xlab = "Weather Event", ylab = "Total Damage $",
main = "The total property and crops damage for the five most harmful events")