#Synopsis The project Analyses the Storm data from NOAA(National Oceanic and Atmosperic Administration) from 1950 to 2011. The data analysis here adresses the following 2 questions 1.Types of events which are most harmful for the health of the population. Few of the events considered for analaysis like Tornado, Floods, Flash Floods and Heat etc;. 2.Economic losses because of these events i.e. Loss of Property, Loss of agricultural crops etc;.
The impact of these events have been analyzed based on their intensity on the health of citizens like injuries, fatal injuries, death and other effects. Top 10 events affecting the health adversely have been considered.
Similarly the events, which have contributed to the losses in terms of damages to the property and agricultural crops, have been analyzed. Top 10 events responsible fro losses to the property and crops have been analyzed.
#Loading the libraries
library(data.table)
library(ggplot2)
library(reshape)
## Warning: package 'reshape' was built under R version 3.6.1
##
## Attaching package: 'reshape'
## The following object is masked from 'package:data.table':
##
## melt
library(scales)
options(scipen=999)
#Data Processing The data for this assignment come in the form of a CSV file compressed via the bzip2 algorithm to reduce its size. The two files are downloaded. Weatherdata - https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2)
Definitions(https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf )
The data is from NOAA database. The events in the database start in the year 1950 and end in November 2011. Data Fields selected EVTYPE - Event Type FATALITIES - No. of reported fatalities caused by the event. INJURIES - No. of reported injuries caused by the event. PROPDMG/PROPDMGEXP - The USD-$ amt property damage caused by the event. CROPDMG/CROPDMGEXP - The USD -$ amount of crop damage caused by the event.
#download the datafile
zipFileName <- "StormData.csv.bz2"
fileURL <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"
# Checck if the file exists
if (!file.exists(zipFileName)){
download.file(fileURL, zipFileName)
}
if(!"StormData" %in% ls()) {
StromData <- read.csv("StormData.csv.bz2")
StormData <- read.csv(zipFileName, stringsAsFactors = FALSE)
}
Dataframe for Event Type, Fatalities and Injuries to measure impact on health
StormDataclean <- data.frame(StormData$EVTYPE,StormData$FATALITIES, StormData$INJURIES)
colnames(StormDataclean) = c("EVTYPE", "FATALITIES", "INJURIES")
Data Frame for Damages - Property and Crops
damagedataclean <- data.frame(StormData$EVTYPE,StormData$PROPDMG, StormData$PROPDMGEXP, StormData$CROPDMG, StormData$CROPDMGEXP)
colnames(damagedataclean) = c("EVTYPE", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")
Measurment of crop+Property damages in units - thousands, millions and billions i.e. K=1000, M=1000x1000, B=1000x1000x1000
damagedataclean$PROPDMGMult <- ifelse (damagedataclean$PROPDMGEXP == "K", 1000, ifelse (damagedataclean$PROPDMGEXP == "M", 1000000, ifelse (damagedataclean$PROPDMGEXP == "B", 1000000000, 0)))
damagedataclean$PROPDMGAMT <- damagedataclean$PROPDMG*damagedataclean$PROPDMGMult
damagedataclean$CROPDMGMult <- ifelse (damagedataclean$CROPDMGEXP == "K", 1000, ifelse (damagedataclean$CROPDMGEXP == "M", 1000000, ifelse (damagedataclean$CROPDMGEXP == "B", 1000000000, 0)))
damagedataclean$CROPDMGAMT <- damagedataclean$CROPDMG*damagedataclean$CROPDMGMult
damagedataclean$TOTALDMGAMT <- damagedataclean$PROPDMGAMT+damagedataclean$CROPDMGAMT
Results- Assignment Questions Question 1: Across the United States, which type of events (as indicated in EVTYPE variable) are most harmful with repect to population health? #Ans First we will Summarize the top 10 events by “FATALITIES”
weatherfatalities <- aggregate(StormDataclean$FATALITIES, by = list(StormDataclean$EVTYPE), FUN = sum, na.rm = TRUE)
colnames(weatherfatalities) = c("EVTYPE", "FATALITIES")
weatherfatalities <- weatherfatalities[order(-weatherfatalities$FATALITIES),]
topweatherfatalities <- weatherfatalities[1: 10, ]
plot1<- ggplot(topweatherfatalities, aes(x=reorder(EVTYPE, FATALITIES), y=FATALITIES))
plot1+geom_bar(stat = "identity", fill = "blue")+ ggtitle("Top 10 Weather Events by Number of Fatalities")+labs(x = "Event Type", y=" No.of Fatalities") +theme(axis.text.x = element_text(angle=45, hjust=1))
#Results - Most HArmful for People Health as per rankings are 1. Tornados 2. Excessive Heat 3.Flash Floods
Next we will summarize top 10 events by “INJURIES”
weatherinjury <- aggregate(StormDataclean$INJURIES, by = list(StormDataclean$EVTYPE), FUN = sum, na.rm = TRUE)
colnames(weatherinjury) = c("EVTYPE", "INJURIES")
weatherinjury <- weatherinjury[order(-weatherinjury$INJURIES),]
topweatherinjury <- weatherinjury[1: 10, ]
plot2<- ggplot(topweatherinjury, aes(x=reorder(EVTYPE, INJURIES), y=INJURIES))
plot2+geom_bar(stat = "identity", fill = "blue")+ ggtitle("Top 10 Weather Events by Number of Injuries")+labs(x = "Event Type", y="Number of Injuries") +theme(axis.text.x = element_text(angle=45, hjust=1))
Events asuing max Injuries 1. Tornado 2. Wind 3. Floods and so on
Question 2: Across the United States which types of events have the greatest economic consequences? ANS We will analyze the “economic consequence” property and crop losses because of Weather events.
We will summarize the total damages for the top 10 events
TOTALDMGAMT <- aggregate(damagedataclean$TOTALDMGAMT, by = list(damagedataclean$EVTYPE), FUN = sum, na.rm = TRUE)
colnames(TOTALDMGAMT) = c("EVTYPE", "TOTALDMGAMT")
TOTALDMGAMT <- TOTALDMGAMT[order(-TOTALDMGAMT$TOTALDMGAMT),]
TOPTOTALDMGAMT <- TOTALDMGAMT[1: 10, ]
plot3<- ggplot(TOPTOTALDMGAMT, aes(x=reorder(EVTYPE, TOTALDMGAMT/1000000000), y=TOTALDMGAMT/1000000000))
plot3+geom_bar(stat = "identity", fill = "blue")+ ggtitle("Top 10 Weather Events by Total Damage (in $ Billions)")+labs(x = "Event Type", y="Total Damage (in $ Billions)") +theme(axis.text.x = element_text(angle=45, hjust=1))
###RESULTS based on plot1, plot2 and plot3 Greatest impact on economic losses fro Property and Crops 1.Floods 2. Hurricane/Typhoons 3.Tornado
#Conclusion ##Weather events responsible for maximum fatalities are 1. Tornados 2. Excessive Heats 3. Flash Floods ## Weather events responsible for maximum Injuries are 1. Tornado 2. TSTM WInds 3. Floods # For Crop and prpoerty damages the events are 1. Floods 2. Hurricane 3. Tornado
Summarizing the Tornado and Floods are causing both health and economic damages.