Synopsis
In this report we try to find which are the most damaging climatic events for the population and which are the ones that produce the greatest economic losses. For this we will use the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database.
Load libraries and dataset
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.5
##
## 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
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.0.5
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
data<-read.csv("C://Users/dario/Desktop/repdata_data_StormData.csv")
Data analysis
Now let’s explore the dataset.
dim(data)
## [1] 902297 37
str(data)
## 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : chr "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
## $ BGN_TIME : chr "0130" "0145" "1600" "0900" ...
## $ TIME_ZONE : chr "CST" "CST" "CST" "CST" ...
## $ COUNTY : num 97 3 57 89 43 77 9 123 125 57 ...
## $ COUNTYNAME: chr "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
## $ STATE : chr "AL" "AL" "AL" "AL" ...
## $ EVTYPE : chr "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
## $ BGN_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ BGN_AZI : chr "" "" "" "" ...
## $ BGN_LOCATI: chr "" "" "" "" ...
## $ END_DATE : chr "" "" "" "" ...
## $ END_TIME : chr "" "" "" "" ...
## $ 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 : chr "" "" "" "" ...
## $ END_LOCATI: chr "" "" "" "" ...
## $ 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: chr "K" "K" "K" "K" ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: chr "" "" "" "" ...
## $ WFO : chr "" "" "" "" ...
## $ STATEOFFIC: chr "" "" "" "" ...
## $ ZONENAMES : chr "" "" "" "" ...
## $ 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 : chr "" "" "" "" ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
names(data)
## [1] "STATE__" "BGN_DATE" "BGN_TIME" "TIME_ZONE" "COUNTY"
## [6] "COUNTYNAME" "STATE" "EVTYPE" "BGN_RANGE" "BGN_AZI"
## [11] "BGN_LOCATI" "END_DATE" "END_TIME" "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE" "END_AZI" "END_LOCATI" "LENGTH" "WIDTH"
## [21] "F" "MAG" "FATALITIES" "INJURIES" "PROPDMG"
## [26] "PROPDMGEXP" "CROPDMG" "CROPDMGEXP" "WFO" "STATEOFFIC"
## [31] "ZONENAMES" "LATITUDE" "LONGITUDE" "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS" "REFNUM"
head(data[,1:10])
## STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE
## 1 1 4/18/1950 0:00:00 0130 CST 97 MOBILE AL TORNADO
## 2 1 4/18/1950 0:00:00 0145 CST 3 BALDWIN AL TORNADO
## 3 1 2/20/1951 0:00:00 1600 CST 57 FAYETTE AL TORNADO
## 4 1 6/8/1951 0:00:00 0900 CST 89 MADISON AL TORNADO
## 5 1 11/15/1951 0:00:00 1500 CST 43 CULLMAN AL TORNADO
## 6 1 11/15/1951 0:00:00 2000 CST 77 LAUDERDALE AL TORNADO
## BGN_RANGE BGN_AZI
## 1 0
## 2 0
## 3 0
## 4 0
## 5 0
## 6 0
We reduced the dataset to the variables BGN_DATE, STATE, EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP. We rename and adapt them.We choose only the year in BGN_DATE since we will not analyze the distribution of events during the year.
data<-data[,c(2,7,8,23:28)]
data[,1]<-as.character(data[,1])
data[,1]<-as.Date(data$BGN_DATE,"%m/%d/%Y %H:%M:%S")
data[,1]<-year(data[,1])
names(data)[1]<-"YEAR"
head(data)
## YEAR STATE EVTYPE FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## 1 1950 AL TORNADO 0 15 25.0 K 0
## 2 1950 AL TORNADO 0 0 2.5 K 0
## 3 1951 AL TORNADO 0 2 25.0 K 0
## 4 1951 AL TORNADO 0 2 2.5 K 0
## 5 1951 AL TORNADO 0 2 2.5 K 0
## 6 1951 AL TORNADO 0 6 2.5 K 0
When we look at the types of registered events we see several ones with “Summary”, which were eliminated.
s<-grep("Summary",data$EVTYPE)
data<-data[-s,]
We analyze the number of events per year.
A<-data %>% group_by(YEAR) %>% summarize(EVENTS=n())
ggplot(A) + geom_point(aes(EVENTS,YEAR)) +
labs(title ="Number of registered events per year") +
xlab(label="Number of events") +
ylab(label="Year")
We will take for the analysis the years that present more than 20,000 registered events (plateau area).
A[A[,2]>=20000,1][1,1]
## # A tibble: 1 x 1
## YEAR
## <dbl>
## 1 1994
## Year 1994
data<-data[data$YEAR>1994,]
sum(is.na(data))
## [1] 0
List of 5 types of events most harmful with respect to population health.
data$EVTYPE<-toupper(data$EVTYPE)
B<-data %>% mutate(HARMFUL_HEALTH=FATALITIES+INJURIES) %>%
select(EVTYPE,HARMFUL_HEALTH) %>% group_by(EVTYPE) %>%
summarize(SUM = sum(HARMFUL_HEALTH)) %>% filter(SUM >0) %>%
arrange(-SUM)
TOP_1<-top_n(B,5,SUM)
Now let’s look at the damage columns. First we must modify the numbers according to “… EXP”
data$PROPDMGEXP<-toupper(data$PROPDMGEXP)
data$CROPDMGEXP<-toupper(data$CROPDMGEXP)
C<-data %>% group_by(EVTYPE) %>%
mutate(PROPDMG = ifelse(PROPDMGEXP == "B", PROPDMG*1000000,
ifelse(PROPDMGEXP == "M", PROPDMG*1000,
PROPDMG)),
CROPDMG = ifelse(CROPDMGEXP == "B", CROPDMG*1000000,
ifelse(CROPDMGEXP == "M", CROPDMG*1000,
CROPDMG))) %>%
mutate(DAMAGE=PROPDMG+CROPDMG) %>%
summarize(DAMAGE=sum(DAMAGE)) %>%
filter(DAMAGE>0) %>% arrange(-DAMAGE)
TOP_2<-top_n(C,5,DAMAGE)
RESULTS
Below is a table and a graph with the most damaging events for human health.
TOP_1
## # A tibble: 5 x 2
## EVTYPE SUM
## <chr> <dbl>
## 1 TORNADO 23310
## 2 EXCESSIVE HEAT 8428
## 3 FLOOD 7192
## 4 LIGHTNING 5360
## 5 TSTM WIND 3871
ggplot(data=TOP_1,aes(x=EVTYPE,y=SUM)) +
geom_bar(stat="identity") +
labs(title ="Events most harmful with respect to population health") +
xlab(label="Event") +
ylab(label="Number of fatalities/injuries")
Below is a table and a graph with the most damaging events for the economy.
TOP_2
## # A tibble: 5 x 2
## EVTYPE DAMAGE
## <chr> <dbl>
## 1 FLOOD 149444854.
## 2 HURRICANE/TYPHOON 71913713.
## 3 STORM SURGE 43193541
## 4 TORNADO 25222662.
## 5 HAIL 17660186.
ggplot(data=TOP_2,aes(x=EVTYPE,y=DAMAGE)) +
geom_bar(stat="identity") +
labs(title ="Events most harmful with respect to economic damage") +
xlab(label="Event") +
ylab(label="Total damage (in thousands of dollars)")