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 basic goal of this project is to explore the NOAA Storm Database and answer some basic questions about severe weather events. This Storm Data provides descriptions of weather events including number of deaths and injuries as well as estimates of the costs of property and crop damage. The data covers the years 1950 through 2011. Our analysis found that tornadoes cause the most bodily harm, and flooding causes the most property damage.
The data analysis addresses the following questions:
library(plyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(ggplot2)
library(lattice)
library(stringr)
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", "storm_data.bz2")
storm_data <- read.csv(".//storm_data.bz2", sep = ",", header = TRUE)
str(storm_data)
## 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
## $ BGN_TIME : Factor w/ 3608 levels "00:00:00 AM",..: 272 287 2705 1683 2584 3186 242 1683 3186 3186 ...
## $ TIME_ZONE : Factor w/ 22 levels "ADT","AKS","AST",..: 7 7 7 7 7 7 7 7 7 7 ...
## $ COUNTY : num 97 3 57 89 43 77 9 123 125 57 ...
## $ COUNTYNAME: Factor w/ 29601 levels "","5NM E OF MACKINAC BRIDGE TO PRESQUE ISLE LT MI",..: 13513 1873 4598 10592 4372 10094 1973 23873 24418 4598 ...
## $ STATE : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
## $ EVTYPE : Factor w/ 985 levels " HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
## $ BGN_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ BGN_AZI : Factor w/ 35 levels ""," N"," NW",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_LOCATI: Factor w/ 54429 levels "","- 1 N Albion",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_DATE : Factor w/ 6663 levels "","1/1/1993 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_TIME : Factor w/ 3647 levels ""," 0900CST",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ COUNTY_END: num 0 0 0 0 0 0 0 0 0 0 ...
## $ COUNTYENDN: logi NA NA NA NA NA NA ...
## $ END_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ END_AZI : Factor w/ 24 levels "","E","ENE","ESE",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ END_LOCATI: Factor w/ 34506 levels "","- .5 NNW",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ LENGTH : num 14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
## $ WIDTH : num 100 150 123 100 150 177 33 33 100 100 ...
## $ F : int 3 2 2 2 2 2 2 1 3 3 ...
## $ MAG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ FATALITIES: num 0 0 0 0 0 0 0 0 1 0 ...
## $ INJURIES : num 15 0 2 2 2 6 1 0 14 0 ...
## $ PROPDMG : num 25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
## $ PROPDMGEXP: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ WFO : Factor w/ 542 levels ""," CI","$AC",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ STATEOFFIC: Factor w/ 250 levels "","ALABAMA, Central",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ ZONENAMES : Factor w/ 25112 levels ""," "| __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
## $ LATITUDE : num 3040 3042 3340 3458 3412 ...
## $ LONGITUDE : num 8812 8755 8742 8626 8642 ...
## $ LATITUDE_E: num 3051 0 0 0 0 ...
## $ LONGITUDE_: num 8806 0 0 0 0 ...
## $ REMARKS : Factor w/ 436781 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
The dataset consists of 902297 observations and 37 attributes. For this project, the required attributes are mainly “EVTYPE”,“FATALITIES”, “INJURIES”, “PROPDMG”, “PROPDMGEXP”, “CROPDMG”, “CROPDMGEXP”.
The “EVTYPE” variable will be used to see which event is the most harmful respect to population health.
## Subsetting the data that consists of only the attributes required in this data analysis.
stormdata <- storm_data[,c("EVTYPE","FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
Harmful <- aggregate(FATALITIES ~ EVTYPE, stormdata, sum)
names(Harmful) <- c("EVTYPE","SUM_EVENTS")
## Ordering the dataset in decreasing order of first 10 weather events
Harmful_data <- Harmful[order(Harmful$SUM_EVENTS,decreasing = TRUE),][1:10,]
## Plotting the number of fatalities by top 10 weather events
library(ggplot2)
ggplot(Harmful_data, aes(EVTYPE,SUM_EVENTS)) +
geom_bar(stat = "identity", fill = "red") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event Type") + ylab("Fatalities") + ggtitle("Number of fatalities")
From the above chart, we see tornadoes are most harmful with respect to the number of fatalities.
Harmful1 <- aggregate(INJURIES ~ EVTYPE, stormdata, sum)
names(Harmful1) <- c("EVTYPE","SUM_EVENTS")
## Ordering the dataset in decreasing order of first 10 weather events
Harmful_data1 <- Harmful1[order(Harmful1$SUM_EVENTS,decreasing = TRUE),][1:10,]
## Plotting the number of fatalities by top 10 weather events
library(ggplot2)
ggplot(Harmful_data1, aes(EVTYPE,SUM_EVENTS)) +
geom_bar(stat = "identity", fill = "red") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event Type") + ylab("INJURIES") + ggtitle("Number of INJURIES")
From the above chart, we see tornadoes are most harmful with respect to the number of injuries.
Therefore, The major weather events that is harmful for human health are Tornadoes.
## Tidying the "PROPDMGEXP" and "CROPDMGEXP" stormdata
## NOAA advises that K means $1000, M means $1,000,000, and B means $1,000,000,000
## H I am taking as a typo and they meant K. It is either that or it means 0.
## The symbols were taken to be 0s and the numbers were taken to be powers of 10. This is probably wrong, since it leads to damage estimates less than 100 dollars for some events, which do not seem worth recording.
stormdata$PROPDMGEXP <- as.numeric(mapvalues(stormdata$PROPDMGEXP, from=levels(stormdata$PROPDMGEXP), to=c("0", "0", "0", "0", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "3", "3", "3", "6", "6")))
stormdata$CROPDMGEXP <- as.numeric(mapvalues(stormdata$CROPDMGEXP, from=levels(stormdata$CROPDMGEXP), to=c("0", "0", "0", "2", "9", "3", "3", "6", "6")))
stormdata$PROPDMG <- stormdata$PROPDMG * 10^stormdata$PROPDMGEXP
stormdata$CROPDMG <- stormdata$CROPDMG * 10^stormdata$CROPDMGEXP
# plot number of damages with the most harmful event type
damages <- aggregate((PROPDMG * PROPDMGEXP) + (CROPDMG * CROPDMGEXP) ~ factor(EVTYPE), stormdata, sum)
names(damages) = c("EVTYPE", "TOTAL_DAMAGE")
damages <- damages[order(-damages$TOTAL_DAMAGE), ][1:10, ]
ggplot(damages, aes(EVTYPE, TOTAL_DAMAGE)) +
geom_bar(stat = "identity", fill = "blue") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
xlab("Event Type") + ylab("Damages ($)") + ggtitle("Property & Crop Damages by top 10 Weather Events")
From the above chart, we see Floods cause most economic damage.