In this project, the storm database from the US National Weather service was analyzed with the goal of determining which event had done the most harm to population health and the economy. Our analysis on Fatalities and Injuries, collated as Heath statistics, conclude that the Tornado is the most harmful event in respect to population health. While, based on Property and Crop damages, the data showed that Floods had the greatest economic impact, with total damage costs reaching billions of dollars.
The data was first extracted from a zip file into csv format.
The csv file is then loaded into Rstudio from a preset working
directory.
setwd("/Users/DrEmmanuelMeribole/Desktop/Coursera")
StormData1<-read.csv("repdata_data_StormData.csv", stringsAsFactors = T)
summary(StormData1)
## STATE__ BGN_DATE BGN_TIME
## Min. : 1.0 5/25/2011 0:00:00: 1202 12:00:00 AM: 10163
## 1st Qu.:19.0 4/27/2011 0:00:00: 1193 06:00:00 PM: 7350
## Median :30.0 6/9/2011 0:00:00 : 1030 04:00:00 PM: 7261
## Mean :31.2 5/30/2004 0:00:00: 1016 05:00:00 PM: 6891
## 3rd Qu.:45.0 4/4/2011 0:00:00 : 1009 12:00:00 PM: 6703
## Max. :95.0 4/2/2006 0:00:00 : 981 03:00:00 PM: 6700
## (Other) :895866 (Other) :857229
## TIME_ZONE COUNTY COUNTYNAME STATE
## CST :547493 Min. : 0.0 JEFFERSON : 7840 TX : 83728
## EST :245558 1st Qu.: 31.0 WASHINGTON: 7603 KS : 53440
## MST : 68390 Median : 75.0 JACKSON : 6660 OK : 46802
## PST : 28302 Mean :100.6 FRANKLIN : 6256 MO : 35648
## AST : 6360 3rd Qu.:131.0 LINCOLN : 5937 IA : 31069
## HST : 2563 Max. :873.0 MADISON : 5632 NE : 30271
## (Other): 3631 (Other) :862369 (Other):621339
## EVTYPE BGN_RANGE BGN_AZI
## HAIL :288661 Min. : 0.000 :547332
## TSTM WIND :219940 1st Qu.: 0.000 N : 86752
## THUNDERSTORM WIND: 82563 Median : 0.000 W : 38446
## TORNADO : 60652 Mean : 1.484 S : 37558
## FLASH FLOOD : 54277 3rd Qu.: 1.000 E : 33178
## FLOOD : 25326 Max. :3749.000 NW : 24041
## (Other) :170878 (Other):134990
## BGN_LOCATI END_DATE END_TIME
## :287743 :243411 :238978
## COUNTYWIDE : 19680 4/27/2011 0:00:00: 1214 06:00:00 PM: 9802
## Countywide : 993 5/25/2011 0:00:00: 1196 05:00:00 PM: 8314
## SPRINGFIELD : 843 6/9/2011 0:00:00 : 1021 04:00:00 PM: 8104
## SOUTH PORTION: 810 4/4/2011 0:00:00 : 1007 12:00:00 PM: 7483
## NORTH PORTION: 784 5/30/2004 0:00:00: 998 11:59:00 PM: 7184
## (Other) :591444 (Other) :653450 (Other) :622432
## COUNTY_END COUNTYENDN END_RANGE END_AZI
## Min. :0 Mode:logical Min. : 0.0000 :724837
## 1st Qu.:0 NA's:902297 1st Qu.: 0.0000 N : 28082
## Median :0 Median : 0.0000 S : 22510
## Mean :0 Mean : 0.9862 W : 20119
## 3rd Qu.:0 3rd Qu.: 0.0000 E : 20047
## Max. :0 Max. :925.0000 NE : 14606
## (Other): 72096
## END_LOCATI LENGTH WIDTH
## :499225 Min. : 0.0000 Min. : 0.000
## COUNTYWIDE : 19731 1st Qu.: 0.0000 1st Qu.: 0.000
## SOUTH PORTION : 833 Median : 0.0000 Median : 0.000
## NORTH PORTION : 780 Mean : 0.2301 Mean : 7.503
## CENTRAL PORTION: 617 3rd Qu.: 0.0000 3rd Qu.: 0.000
## SPRINGFIELD : 575 Max. :2315.0000 Max. :4400.000
## (Other) :380536
## F MAG FATALITIES INJURIES
## Min. :0.0 Min. : 0.0 Min. : 0.0000 Min. : 0.0000
## 1st Qu.:0.0 1st Qu.: 0.0 1st Qu.: 0.0000 1st Qu.: 0.0000
## Median :1.0 Median : 50.0 Median : 0.0000 Median : 0.0000
## Mean :0.9 Mean : 46.9 Mean : 0.0168 Mean : 0.1557
## 3rd Qu.:1.0 3rd Qu.: 75.0 3rd Qu.: 0.0000 3rd Qu.: 0.0000
## Max. :5.0 Max. :22000.0 Max. :583.0000 Max. :1700.0000
## NA's :843563
## PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## Min. : 0.00 :465934 Min. : 0.000 :618413
## 1st Qu.: 0.00 K :424665 1st Qu.: 0.000 K :281832
## Median : 0.00 M : 11330 Median : 0.000 M : 1994
## Mean : 12.06 0 : 216 Mean : 1.527 k : 21
## 3rd Qu.: 0.50 B : 40 3rd Qu.: 0.000 0 : 19
## Max. :5000.00 5 : 28 Max. :990.000 B : 9
## (Other): 84 (Other): 9
## WFO STATEOFFIC
## :142069 :248769
## OUN : 17393 TEXAS, North : 12193
## JAN : 13889 ARKANSAS, Central and North Central: 11738
## LWX : 13174 IOWA, Central : 11345
## PHI : 12551 KANSAS, Southwest : 11212
## TSA : 12483 GEORGIA, North and Central : 11120
## (Other):690738 (Other) :595920
## ZONENAMES
## :594029
## :205988
## GREATER RENO / CARSON CITY / M - GREATER RENO / CARSON CITY / M : 639
## GREATER LAKE TAHOE AREA - GREATER LAKE TAHOE AREA : 592
## JEFFERSON - JEFFERSON : 303
## MADISON - MADISON : 302
## (Other) :100444
## LATITUDE LONGITUDE LATITUDE_E LONGITUDE_
## Min. : 0 Min. :-14451 Min. : 0 Min. :-14455
## 1st Qu.:2802 1st Qu.: 7247 1st Qu.: 0 1st Qu.: 0
## Median :3540 Median : 8707 Median : 0 Median : 0
## Mean :2875 Mean : 6940 Mean :1452 Mean : 3509
## 3rd Qu.:4019 3rd Qu.: 9605 3rd Qu.:3549 3rd Qu.: 8735
## Max. :9706 Max. : 17124 Max. :9706 Max. :106220
## NA's :47 NA's :40
## REMARKS REFNUM
## :287433 Min. : 1
## : 24013 1st Qu.:225575
## Trees down.\n : 1110 Median :451149
## Several trees were blown down.\n : 568 Mean :451149
## Trees were downed.\n : 446 3rd Qu.:676723
## Large trees and power lines were blown down.\n: 432 Max. :902297
## (Other) :588295
1. Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
The parameter used to describe harm to the health of the population
would be the sum of the fatalities and Injuries. This involves the
creation of a new column, called Health Statistics.
That is, HealthStats= Fatalities + Injuries
StormData1$HealthStats<- StormData1$FATALITIES + StormData1$INJURIES
Summarize HealthStats by EVTYPE
Since we’re interested in the “most” harmful, the focus would be on the health statistics related to the event type. A Data frame will be generated displaying the total health impact by event. Then we will get the Top 10 events with the most harm to population health.
# Total health impact by event
library(dplyr)
##
## 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
EVhealthStats<- StormData1 %>% group_by(EVTYPE) %>%
summarise( HealthStats = sum(HealthStats, na.rm = TRUE))
EVhealthStats <- arrange(EVhealthStats, desc(HealthStats))
Top10health<- head(EVhealthStats, 10)
print(Top10health)
## # A tibble: 10 × 2
## EVTYPE HealthStats
## <fct> <dbl>
## 1 TORNADO 96979
## 2 EXCESSIVE HEAT 8428
## 3 TSTM WIND 7461
## 4 FLOOD 7259
## 5 LIGHTNING 6046
## 6 HEAT 3037
## 7 FLASH FLOOD 2755
## 8 ICE STORM 2064
## 9 THUNDERSTORM WIND 1621
## 10 WINTER STORM 1527
The Top10health data frame above shows the top 10 event types with the highest impact on population health.
2. Across the United States, which types of events have the
greatest economic consequences? .
The economic consequences of the storm events can be summarized by the
property damage and crop damage columns, i.e: PROPDMG and CROPDMG.
These columns have multipliers called PROPDMGEXP and CROPDMGEXP, with
variables like “K”, “M”, and “B” translating to a multiple of a
thousand, a million and a billion respectively.
These multipliers would be applied to the property and crop damage
columns, for a complete view of the cost of damages.
library(stringr)
#Property Damage
StormData1$PROPDMGEXP <- str_replace(StormData1$PROPDMGEXP, "K", "1000")
StormData1$PROPDMGEXP <- str_replace(StormData1$PROPDMGEXP, "M", "1000000")
StormData1$PROPDMGEXP <- str_replace(StormData1$PROPDMGEXP, "B", "1000000000")
#applying the multipliers
StormData1$PROPDMG <- StormData1$PROPDMG * as.numeric(StormData1$PROPDMGEXP)
## Warning: NAs introduced by coercion
# Crop damage
StormData1$CROPDMGEXP <- str_replace(StormData1$CROPDMGEXP, "k", "1000")
StormData1$CROPDMGEXP <- str_replace(StormData1$CROPDMGEXP, "K", "1000")
StormData1$CROPDMGEXP <- str_replace(StormData1$CROPDMGEXP, "m", "1000000")
StormData1$CROPDMGEXP <- str_replace(StormData1$CROPDMGEXP, "M", "1000000")
StormData1$CROPDMGEXP <- str_replace(StormData1$CROPDMGEXP, "B", "1000000000")
#applying the multipliers
StormData1$CROPDMG<- StormData1$CROPDMG * as.numeric(StormData1$CROPDMGEXP)
## Warning: NAs introduced by coercion
Total economic impact would now be the sum of property and crop damage, and this sum(Economic Impact, aka EconImpact) would be grouped according to the event type.
StormData1$EconImpact<- StormData1$PROPDMG + StormData1$CROPDMG
EVEconImpact<- StormData1 %>% group_by(EVTYPE) %>%
summarise( EconImpact = sum(EconImpact, na.rm = TRUE))
EVEconImpact <- arrange(EVEconImpact, desc(EconImpact))
Top10Econ<- head(EVEconImpact, 10)
print(Top10Econ)
## # A tibble: 10 × 2
## EVTYPE EconImpact
## <fct> <dbl>
## 1 FLOOD 138007444500
## 2 HURRICANE/TYPHOON 29348167800
## 3 TORNADO 16570326150
## 4 HURRICANE 12405268000
## 5 RIVER FLOOD 10108369000
## 6 HAIL 10045596740
## 7 FLASH FLOOD 8715885162
## 8 ICE STORM 5925150800
## 9 STORM SURGE/TIDE 4641493000
## 10 THUNDERSTORM WIND 3813647990
The Top10Econ data frame above shows the top 10 event types with the highest economic impact.
1. Answer to Question 1: Events that are most harmful with respect to population health
To answer this,The top 10 harmful events will be visually represented on a bar chart.
library(ggplot2)
ggplot(Top10health, aes(EVTYPE, HealthStats)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 45, hjust=1)) +
xlab("") +
ylab("population health stats") +
ggtitle("Top 10 events impacting population health")
From the bar chart above, we can see the events that have caused the most harm to the population and can infer that the most impactful event is the Tornado.
2. Answer to Question 2: Events that have the greatest economic consequences
library(ggplot2)
ggplot(Top10Econ, aes(EVTYPE, y=EconImpact/1e9)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 45, hjust=1)) +
xlab("") +
ylab("Damage Costs(in billion USD)") +
ggtitle("Top 10 events with highest economic impact")
From the chart above, we can infer that the highest economic impact is dealt by floods.