This report presents an analysis of the health and economic costs of severe weather. The source of the data is the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. This database contains data collected between the years 1950 and 2011. The data is categorized by “event type” (abbreviated as “EVTYPE”) in the database. The goal of the analysis is to identify which event types are associated with the greatest economic damage and with the which are associated with the greatest health damage.
First, load the required R libraries required to perform the analysis.
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.3
##
## 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
Next, load the storm database into an R language table.
data<-read.csv("repdata_data_StormData.csv.bz2")
First, calculate the economic cost for each event type in the database. The economic cost is taken to be the sum of the property damage and crop damage.
data$Cost<-data$PROPDMG + data$CROPDMG
Next, group the event type and calculate the total economic cost for each event type.
dataTotalCostByType<-data %>%
group_by(EVTYPE) %>%
summarize(totalCost=sum(Cost))
## `summarise()` ungrouping output (override with `.groups` argument)
Next, sort the grouped data by the total economic cost for each event type.
dataTotalCostByTypeSorted<-dataTotalCostByType[order(dataTotalCostByType$totalCost, decreasing=TRUE),]
This analysis is performed in the same way the economic consequences were analyzed above except the number of injuries per event type is used instead of the economic consequences.
dataTotalInjuriesByType<-data %>%
group_by(EVTYPE) %>%
summarize(totalInjuries=sum(INJURIES))
## `summarise()` ungrouping output (override with `.groups` argument)
orderByTotalInjuries<-order(dataTotalInjuriesByType$totalInjuries, decreasing=TRUE)
dataTotalInjuriesByTypeSorted<-dataTotalInjuriesByType[orderByTotalInjuries,]
dataTotalInjuriesTop10<-dataTotalInjuriesByTypeSorted[1:10,]
This analysis is performed in the same way the economic consequences were analyzed above except the number of deaths per event type is used instead of the economic consequences.
dataTotalFatalitiesByType<-data %>%
group_by(EVTYPE) %>%
summarize(totalFatalities=sum(FATALITIES))
## `summarise()` ungrouping output (override with `.groups` argument)
orderByTotalFatalities<-order(dataTotalFatalitiesByType$totalFatalities, decreasing=TRUE)
dataTotalFatalitiesByTypeSorted<-dataTotalFatalitiesByType[orderByTotalFatalities,]
dataTotalFatalitiesTop10<-dataTotalFatalitiesByTypeSorted[1:10,]
dataCostTop10<-dataTotalCostByTypeSorted[1:10,]
barplot(dataCostTop10$totalCost,
legend=dataCostTop10$EVTYPE,
ylab="Total Economic Cost (Thousands of Dollars)",
col=rainbow(10),
main="Events With Top 10 Economic Consequences")
barplot(dataTotalInjuriesTop10$totalInjuries,
legend=dataTotalInjuriesTop10$EVTYPE,
ylab="Total Injuries",
col=rainbow(10),
main="Events With Top 10 Injuries")
barplot(dataTotalFatalitiesTop10$totalFatalities,
legend=dataTotalFatalitiesTop10$EVTYPE,
ylab="Total Fatalities",
col=rainbow(10),
main="Events With Top 10 Deaths")