Severe weather can cause both health and economic problems, for example property damage, crop damage, injury and even death. This analysis aims to determine which severe weather types have the greatest economic and health effects. It uses data from the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. The data are in a raw format and, therefore, an initial preprocessing prior to the analysis is done.
Two main questions are adressed in this report:
Across the United States, which types of events are most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
The results of this analysis show that tornados cause the most fatalities, tornados cause the most injuries, and flooding causes the most property damage.
Download data set and load into R.
dataFileName <- "./StormData.csv.bz2"
if (!file.exists(dataFileName))
{
url <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
download.file(url = url, destfile = dataFileName)
}
stormData <- read.csv("StormData.csv.bz2")
Processing data on fatalities. Pare dataset to Event Type and Fatalities columns, and only rows with fatalities. Group by event type and take the 5 events with the most fatalities.
# Fatalities
fatalityData <- (subset(stormData, FATALITIES > 0))[c(8, 23)]
fatalityGroupedData <- aggregate(FATALITIES ~ EVTYPE, data = fatalityData, FUN = "sum", na.rm = TRUE)
fatalityGroupedData <- fatalityGroupedData[order(fatalityGroupedData$FATALITIES, decreasing=TRUE), ]
fatalityGroupedData <- fatalityGroupedData[1:5, ]
fatalityGroupedData$EVTYPE <- factor(fatalityGroupedData$EVTYPE, levels=fatalityGroupedData$EVTYPE)
Processing data on injuries. Pare dataset to Event Type and Injuries columns, and only rows with injuries. Group by event type and take the 5 events with the most injuries.
# Injuries
injuryData <- (subset(stormData, INJURIES > 0))[c(8, 24)]
injuryGroupedData <- aggregate(INJURIES ~ EVTYPE, data = injuryData, FUN = "sum", na.rm = TRUE)
injuryGroupedData <- injuryGroupedData[order(injuryGroupedData$INJURIES, decreasing=TRUE), ]
injuryGroupedData <- injuryGroupedData[1:5, ]
injuryGroupedData$EVTYPE <- factor(injuryGroupedData$EVTYPE, levels=injuryGroupedData$EVTYPE)
Processing data on damages. Add property damage and crop damage to use as a total damage amount. Data set has two columns with an amount and a magnitude code for both property and crop damage. Use a function to convert these two values into a dollar amount.
# Damage Amounts
# Function to compute total damage amount
damageAmount <- function(amount, magnitude)
{
returnAmount <- 0
if (toupper(magnitude)[1]=="K")
{
returnAmount <- (amount * 1000)
}
if (toupper(magnitude)[1]=="M")
{
returnAmount <- (amount * 1000000)
}
if (toupper(magnitude)[1]=="B")
{
returnAmount <- (amount * 1000000000)
}
return(returnAmount)
}
damageData <- (subset(stormData, PROPDMG > 0 | CROPDMG > 0))[c(8, 25, 26, 27, 28)]
damageData$DamageAmount <- ((mapply(damageAmount, damageData$PROPDMG, damageData$PROPDMGEXP)) +
(mapply(damageAmount, damageData$CROPDMG, damageData$CROPDMGEXP)))
damageGroupedData <- aggregate(DamageAmount ~ EVTYPE, data = damageData, FUN = "sum", na.rm = TRUE)
damageGroupedData <- damageGroupedData[order(damageGroupedData$DamageAmount, decreasing=TRUE), ]
damageGroupedData <- damageGroupedData[1:5, ]
damageGroupedData$EVTYPE <- factor(damageGroupedData$EVTYPE, levels=damageGroupedData$EVTYPE)
Plot fatalities
library(ggplot2)
ggplot(fatalityGroupedData, aes(x=EVTYPE, y=FATALITIES)) +
geom_bar(stat="identity") +
xlab("Wheather envent") +
ylab("Fatalities") +
ggtitle("Total Fatalities By Weather Events")
Plot injuries
library(ggplot2)
ggplot(injuryGroupedData, aes(x=EVTYPE, y=INJURIES)) +
geom_bar(stat="identity") +
xlab("Wheather envent") +
ylab("Injuries") +
ggtitle("Total Injuries By Weather Events")
Plot damages
library(ggplot2)
ggplot(damageGroupedData, aes(x=EVTYPE, y=DamageAmount)) +
geom_bar(stat="identity") +
xlab("Wheather envent") +
ylab("Damage Amount (In Dollars)") +
ggtitle("Total Damage Amount By Weather Events")
Findings:
Tornados cause the most fatalities.
Tornados cause the most injuries.
Flooding causes the most property damage.