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.
The procedures for this report starts with download of raw data and load in a data.frame format. The second step included the analysis of all data, that included some few procedures like check: summary, strings, classes and check the categories of events.
After was analysed the fatalities, injuries and damages of the worst events since 1950 make the sum of this three contents. The results include two graphs thats summarized the worst events in history of U.S.
library(downloader)
library(reshape2)
library(dplyr)
library(plyr)
download("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", dest="dataset.zip", mode="wb")
dataset <- read.csv("storm.csv.bz2", header = TRUE, sep = ",")
dataset <- read.csv("storm.csv.bz2", header = TRUE, sep = ",")
date <- format(as.POSIXct(dataset$BGN_DATE,
format='%m/%d/%Y %H:%M:%S'),
format='%Y')
event <- dataset$EVTYPE
state <- dataset$STATE
fatalities <- dataset$FATALITIES
injuries <- dataset$INJURIES
damage <- dataset$PROPDMG ### To be use at damage analysis
extra.damage <- dataset$PROPDMGEXP ### to be use at damage analysis
df <- data.frame(date, event, state, fatalities, injuries)
### str(df)
### names(df)
### head(df)
### cor(df$fatalities, df$injuries)
##CHECK THE FATALITIES VARIABLE
###order data by fatalities
fatal.order <- df[
order
(df$fatalities,
df$event, decreasing = TRUE), ]
h.fatal <- head(fatal.order, n=10)
###create a subset with isolate the 0 ocurrences of fatalities
fatal.subset <- subset(fatal.order, fatalities > 0)
###analise this subset Just Checking
# boxplot(fatal.subset$fatalities)
###Create a group data by type of Event
group.event.fatalities <- aggregate(fatalities ~ event, fatal.subset, sum)
group.event.fatalities <- group.event.fatalities[
order
(group.event.fatalities$fatalities,
group.event.fatalities$event, decreasing = TRUE), ]
group.event.fatalities <- head(group.event.fatalities, n=5)
##CHECK THE INJURIES VARIABLE
###order data by injuries
injuries.order <- df[
order
(df$injuries,
df$event, decreasing = TRUE), ]
h.injuri <- head(injuries.order, n=10)
###create a subset with isolate the 0 ocurrences of injuries
injuri.subset <- subset(injuries.order, injuries > 0)
###analise this subset - Just Checking
#boxplot(injuri.subset$injuries)
###Create a group data by type of Event -INJURIES
group.event.injuries <- aggregate(injuries ~ event, injuri.subset, sum)
group.event.injuries <- group.event.injuries[
order
(group.event.injuries$injuries,
group.event.injuries$event, decreasing = TRUE), ]
group.event.injuries <- head(group.event.injuries, n=5)
###TORNADO FATALITIES
filtertornado <- filter(df, event == "TORNADO")
filtertornado <- aggregate(fatalities ~ date, filtertornado, sum)
filtertornado <- filtertornado[-c(1:45), ]
###EXCESSIVE HEAT FATALITIES
filterexheat <- filter(df, event == "EXCESSIVE HEAT")
filterexheat <- aggregate(fatalities ~ date, filterexheat, sum)
filterexheat <- filterexheat[-c(1), ]
###FLASH FLOOD FATALITIES
filterflash <- filter(df, event == "FLASH FLOOD")
filterflash <- aggregate(fatalities ~ date, filterflash, sum)
filterflash <- filterflash[-c(1:2), ]
###HEAT FATALITIES
#filterheat <- filter(df, event == "HEAT")
#filterheat <- aggregate(fatalities ~ date, filterheat, sum)
#filterheat <- filter(filterheat, date %in% c("1995", "1996", "1997",
###LIGHTINING FATALITIES
filterlight <- filter(df, event == "LIGHTNING")
filterlight <- aggregate(fatalities ~ date, filterlight, sum)
filterlight <- filterlight[-c(1:2), ]
date1 <- c('1995', '1996', '1997', '1998', '1999', '2000', '2001', '2002', '2003', '2004', '2005','2006', '2007', '2008', '2009', '2010', '2011')
df.temporal <- data.frame(date = date1, Tornado = filtertornado$fatalities,
Excessiveheat = filterexheat$fatalities, flash = filterflash$fatalities,
Lightning = filterlight$fatalities)
df.damage <- data.frame(date, event, state, fatalities, injuries, damage, extra.damage)
###order damages
damage.order <- df.damage[
order
(df.damage$damage, decreasing = TRUE), ]
damage.test <- head(damage.order, n=10)
###create a subset with isolate the 0 ocurrences of damages
damage.subset <- subset(damage.test, damage > 0)
###analise this subset
#boxplot(damage.subset$damage)
###Create a group data by type of Event
group.event.damage <- aggregate(damage ~ event, damage.subset, sum)
group.event.damage <- group.event.damage[
order
(group.event.damage$damage,
group.event.damage$event, decreasing = TRUE), ]
group.event.damage <- head(group.event.damage, n=5)
teste <- df.temporal[ ,-1]
teste <- as.data.frame(teste)
my_vector=c(5633, 1903, 978, 937, 816)
names(my_vector)=c("Tornado", "Excessive Heat", "Flash Flood", "Heat", "Lightining")
barplot(my_vector, col=c("blue", "red", "black", "brown","darkgreen"),
xlab="Type of Events",
ylab="Fatalities",
main="Total of Fatalities by 5 worst type of events (1950 - 2011)",
ylim=c(0,6000),
border = "black",
cex.names = 0.8,
cex.axis = 0.7)
According this graph Tornado has a big impact in number of Fatalities during the period.
boxplot(teste, ylim=c(1, 200), col = c("blue", "red", "black", "darkgreen"))
title(main="Average of Fatalities by worst type of Events", col.main="black", font.main=4)
title(xlab="Type of Events")
title(ylab="Average of Fatalities by Year")
my_vector=c(11700, 10000, 5000, 4800, 4410)
names(my_vector)=c("Thunderstorm", "Flash Flood", "Waterspout", "landslide", "Tornado")
barplot(my_vector,
col=c(1,2,3,4,5),
xlab="Type of Events",
ylab="USD Amount(Millions)",
main="Worst damage type of events",
ylim=c(0,12000),
border = "black",
cex.names = 0.8,
cex.axis = 0.7)