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.
Here we are trying to find answer on :
Across the United States, which types of events are most harmful with respect to population health?
— Our analysis found that TORNADO is most harful which caused maximum death/fatalties.
Across the United States, which types of events have the greatest economic consequences?
— Our analysis found that FLOOD is caused most economical damages.
Call all required libraries.
library(ggplot2) # required for plotting
library(dplyr) # required for mutate function
## Warning: package 'dplyr' was built under R version 3.4.2
##
## 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
# For this analysis data taken from https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2.
fulldata <- read.csv('repdata_data_StormData.csv.bz2', header = TRUE, sep = ",")
str(fulldata)
## '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 ...
# Take only required columns to make the processing faster
stormdata <- fulldata[,c('EVTYPE', 'FATALITIES', 'INJURIES', 'PROPDMG', 'PROPDMGEXP', 'CROPDMG', 'CROPDMGEXP')]
dim(stormdata)
## [1] 902297 7
head(stormdata)
## EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1 TORNADO 0 15 25.0 K 0
## 2 TORNADO 0 0 2.5 K 0
## 3 TORNADO 0 2 25.0 K 0
## 4 TORNADO 0 2 2.5 K 0
## 5 TORNADO 0 2 2.5 K 0
## 6 TORNADO 0 6 2.5 K 0
The EVTYPE column holds the name of differen Sorm or whether condition which occured across US. The FATALITIES provided count of deaths due to that Event. Also INJURIES provides count of injury due to that Event. We need to find the total death/injury for each events.
# For Fatalities/death aggrigation based on each EVTYPE
fatal_agg <- aggregate(stormdata$FATALITIES, by = list(stormdata$EVTYPE), FUN = "sum", na.rm = TRUE)
# Add a new column as Type to hold casuality type
fatal_agg$type <- "Fatalities"
names(fatal_agg) <- c("EVTYPE", "Counts", "Type")
# For injury aggrigation based on each EVTYPE
injur_agg <- aggregate(stormdata$INJURIES, by = list(stormdata$EVTYPE), FUN = "sum", na.rm = TRUE)
# Add a new column as Type to hold casuality type
injur_agg$type <- "Injuries"
names(injur_agg) <- c("EVTYPE", "Counts", "Type")
dim(fatal_agg)
## [1] 985 3
dim(injur_agg)
## [1] 985 3
# As there are many EVTYPE, we can see top 20 types
fatal_agg <- fatal_agg[order(fatal_agg$Counts, decreasing = TRUE),][1:20,]
injur_agg <- injur_agg[order(injur_agg$Counts, decreasing = TRUE),][1:20,]
affect_agg <- rbind(fatal_agg, injur_agg)
head(fatal_agg)
## EVTYPE Counts Type
## 834 TORNADO 5633 Fatalities
## 130 EXCESSIVE HEAT 1903 Fatalities
## 153 FLASH FLOOD 978 Fatalities
## 275 HEAT 937 Fatalities
## 464 LIGHTNING 816 Fatalities
## 856 TSTM WIND 504 Fatalities
head(injur_agg)
## EVTYPE Counts Type
## 834 TORNADO 91346 Injuries
## 856 TSTM WIND 6957 Injuries
## 170 FLOOD 6789 Injuries
## 130 EXCESSIVE HEAT 6525 Injuries
## 464 LIGHTNING 5230 Injuries
## 275 HEAT 2100 Injuries
# Plot the FATALITIES and INJURIES per EVTYPE
g <- ggplot(data = affect_agg, aes(x = EVTYPE, y = Counts, fill = Type))
g <- g + geom_bar(stat = "identity")
g <- g + theme(legend.position = "bottom")
g <- g + theme(axis.text.x = element_text(angle = 60, hjust = 1))
g <- g + labs(x = "Event Types", y = "Count of Events", title = "Events with maximum Fatalities and Injuries across US")
print(g)
Due to Storm and Other weather condition the Property and Crops damaged. Property damage estimates should be entered as actual dollar amounts, if a reasonably accurate estimate from an insurance company or other qualified individual is available. Within data we have following columns to describe property/crop losses.
PROPDMGEXP = It decribes magnitude of the property loss in Thousand(K), Millions(M), Billions(B)
PROPDMG = The property damage, for actual value (PROPDMG * PROPDMGEXP)
CROPDMGEXP = It decribes magnitude of the crop loss in Thousand(K), Millions(M), Billions(B)
CROPDMG = The crop damage, for actual value (CROPDMG * CROPDMGEXP)
# Get distinct list of PROPDMGEXP and CROPDMGEXP
unique(stormdata$PROPDMGEXP)
## [1] K M B m + 0 5 6 ? 4 2 3 h 7 H - 1 8
## Levels: - ? + 0 1 2 3 4 5 6 7 8 B h H K m M
unique(stormdata$CROPDMGEXP)
## [1] M K m B ? 0 k 2
## Levels: ? 0 2 B k K m M
# Convert lower-case values to upper-case
stormdata$PROPDMGEXP <- toupper(stormdata$PROPDMGEXP)
stormdata$CROPDMGEXP <- toupper(stormdata$CROPDMGEXP)
# Add new column 'Prop_Damage' to hold actual property damage value in USD
stormdata <- mutate(stormdata, Prop_Damage = ifelse(PROPDMGEXP == "K", PROPDMG * 1000, ifelse(PROPDMGEXP == "M", PROPDMG * 1000000, ifelse(PROPDMGEXP == "B", PROPDMG * 1000000000, PROPDMG))))
# Add new column 'Crop_Damage' to hold actual crop damage value in USD
stormdata <- mutate(stormdata, Crop_Damage = ifelse(CROPDMGEXP == "K", CROPDMG * 1000, ifelse(CROPDMGEXP == "M", CROPDMG * 1000000, ifelse(CROPDMGEXP == "B", CROPDMG * 1000000000, CROPDMG))))
head(stormdata)
## EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1 TORNADO 0 15 25.0 K 0
## 2 TORNADO 0 0 2.5 K 0
## 3 TORNADO 0 2 25.0 K 0
## 4 TORNADO 0 2 2.5 K 0
## 5 TORNADO 0 2 2.5 K 0
## 6 TORNADO 0 6 2.5 K 0
## Prop_Damage Crop_Damage
## 1 25000 0
## 2 2500 0
## 3 25000 0
## 4 2500 0
## 5 2500 0
## 6 2500 0
# Aggrigate data to find Property damage (USD) per EVTYPE
prop_agg <- aggregate(stormdata$Prop_Damage, by = list(stormdata$EVTYPE), FUN = "sum", na.rm = TRUE)
prop_agg$type <- "Property Damage"
names(prop_agg) <- c("EVTYPE","USD","Type")
# Aggrigate data to find Crop damage (USD) per EVTYPE
crop_agg <- aggregate(stormdata$Crop_Damage, by = list(stormdata$EVTYPE), FUN = "sum", na.rm = TRUE)
crop_agg$type <- "Crop Damage"
names(crop_agg) <- c("EVTYPE","USD","Type")
# As there are many EVTYPE, we can see top 20 types
prop_agg <- prop_agg[order(prop_agg$USD, decreasing = TRUE),][1:20,]
crop_agg <- crop_agg[order(crop_agg$USD, decreasing = TRUE),][1:20,]
loss_agg <- rbind(prop_agg, crop_agg)
head(prop_agg)
## EVTYPE USD Type
## 170 FLOOD 144657709807 Property Damage
## 411 HURRICANE/TYPHOON 69305840000 Property Damage
## 834 TORNADO 56937160779 Property Damage
## 670 STORM SURGE 43323536000 Property Damage
## 153 FLASH FLOOD 16140812067 Property Damage
## 244 HAIL 15732267048 Property Damage
head(crop_agg)
## EVTYPE USD Type
## 95 DROUGHT 13972566000 Crop Damage
## 170 FLOOD 5661968450 Crop Damage
## 590 RIVER FLOOD 5029459000 Crop Damage
## 427 ICE STORM 5022113500 Crop Damage
## 244 HAIL 3025954473 Crop Damage
## 402 HURRICANE 2741910000 Crop Damage
# Plot the Property Damage (USD) and Crop Damage (USD) per EVTYPE
g <- ggplot(data = loss_agg, aes(x = EVTYPE, y = USD, fill = Type))
g <- g + geom_bar(stat = "identity")
g <- g + theme(legend.position = "bottom")
g <- g + theme(axis.text.x = element_text(angle = 60, hjust = 1))
g <- g + labs(x = "Event Types", y = "Damages in USD", title = "Events with maximum damages across US")
print(g)
The first data plots tells us that TORNADO causes most casualities (Death/Injuries) in US.
The second data plots tells us that FLOOD causes most ecomonical damages (Property/Crop) in US.