Research Report for Data Analysis of the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database - Health and Economic Impacts

Synopsis

This project explores the health and economic consequences of severe weather events in the United States using data from the National Oceanic and Atmospheric Administration (NOAA). It focuses on estimating:

Health Impact: Fatalities and injuries caused by various types of severe weather events. Economic Impact: Property damage and crop damage associated with these events. Data Source: The project utilizes a historical dataset (1950-2011) from NOAA, containing information about major storms and weather events, including:

Data Processing

The following libraries were used in the data analysis and had been pre-loaded to make the analysis easier.

Load dependencies

library(data.table)
## Warning: package 'data.table' was built under R version 4.3.3
library(ggplot2)

library(plyr)
## Warning: package 'plyr' was built under R version 4.3.3
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.3
## 
## 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:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#Read the data
data <- read.csv("repdata_data_StormData.csv", header = TRUE, sep=",")

```

#Inspect dataset

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 ...

#Subset the data

sub_data<- c('EVTYPE', 'FATALITIES', 'INJURIES', 'PROPDMG', 'PROPDMGEXP', 'CROPDMG', 'CROPDMGEXP') 
data <- data[, sub_data]
summary(data)
##     EVTYPE            FATALITIES          INJURIES            PROPDMG       
##  Length:902297      Min.   :  0.0000   Min.   :   0.0000   Min.   :   0.00  
##  Class :character   1st Qu.:  0.0000   1st Qu.:   0.0000   1st Qu.:   0.00  
##  Mode  :character   Median :  0.0000   Median :   0.0000   Median :   0.00  
##                     Mean   :  0.0168   Mean   :   0.1557   Mean   :  12.06  
##                     3rd Qu.:  0.0000   3rd Qu.:   0.0000   3rd Qu.:   0.50  
##                     Max.   :583.0000   Max.   :1700.0000   Max.   :5000.00  
##   PROPDMGEXP           CROPDMG         CROPDMGEXP       
##  Length:902297      Min.   :  0.000   Length:902297     
##  Class :character   1st Qu.:  0.000   Class :character  
##  Mode  :character   Median :  0.000   Mode  :character  
##                     Mean   :  1.527                     
##                     3rd Qu.:  0.000                     
##                     Max.   :990.000

#Check for missing values in the datasets

sum(is.na(data))
## [1] 0

#Group events

sort(table(data$EVTYPE), decreasing = TRUE)[1:10] 
## 
##               HAIL          TSTM WIND  THUNDERSTORM WIND            TORNADO 
##             288661             219940              82563              60652 
##        FLASH FLOOD              FLOOD THUNDERSTORM WINDS          HIGH WIND 
##              54277              25326              20843              20212 
##          LIGHTNING         HEAVY SNOW 
##              15754              15708
data$EVENT <- "DIFF"

#grouping by Event type

data$EVENT[grep("HAIL", data$EVTYPE, ignore.case = TRUE)] <- "HAIL" 
data$EVENT[grep("HEAT", data$EVTYPE, ignore.case = TRUE)] <- "HEAT"
data$EVENT[grep("FLOOD", data$EVTYPE, ignore.case = TRUE)] <- "FLOOD"
data$EVENT[grep("WIND", data$EVTYPE, ignore.case = TRUE)] <- "WIND"
data$EVENT[grep("STORM", data$EVTYPE, ignore.case = TRUE)] <- "STORM"
data$EVENT[grep("SNOW", data$EVTYPE, ignore.case = TRUE)] <- "SNOW"

data$EVENT[grep("TORNADO", data$EVTYPE, ignore.case = TRUE)] <- "TORNADO"
data$EVENT[grep("WINTER", data$EVTYPE, ignore.case = TRUE)] <- "WINTER"
data$EVENT[grep("RAIN", data$EVTYPE, ignore.case = TRUE)] <- "RAIN"

#List changes

sort(table(data$EVENT), decreasing = TRUE)
## 
##    HAIL    WIND   STORM   FLOOD TORNADO    DIFF  WINTER    SNOW    RAIN    HEAT 
##  289270  255362  113156   82686   60700   48970   19604   17660   12241    2648

#Sort issues with the units

data$PROPDMGEXP <- as.character(data$PROPDMGEXP)
data$PROPDMGEXP[is.na(data$PROPDMGEXP)] <- 0 # NA's considered as dollars
data$PROPDMGEXP[!grepl("K|M|B", data$PROPDMGEXP, ignore.case = TRUE)] <- 0 # everything exept K,M,B is dollar
data$PROPDMGEXP[grep("K", data$PROPDMGEXP, ignore.case = TRUE)] <- "3"
data$PROPDMGEXP[grep("M", data$PROPDMGEXP, ignore.case = TRUE)] <- "6"
data$PROPDMGEXP[grep("B", data$PROPDMGEXP, ignore.case = TRUE)] <- "9"
data$PROPDMGEXP <- as.numeric(as.character(data$PROPDMGEXP))
data$property.damage <- data$PROPDMG * 10^data$PROPDMGEXP

#Crop damage

data$CROPDMGEXP <- as.character(data$CROPDMGEXP)
data$CROPDMGEXP[is.na(data$CROPDMGEXP)] <- 0 # NA's considered as dollars
data$CROPDMGEXP[!grepl("K|M|B", data$CROPDMGEXP, ignore.case = TRUE)] <- 0 # everything except K,M,B is dollars
data$CROPDMGEXP[grep("K", data$CROPDMGEXP, ignore.case = TRUE)] <- "3"
data$CROPDMGEXP[grep("M", data$CROPDMGEXP, ignore.case = TRUE)] <- "6"
data$CROPDMGEXP[grep("B", data$CROPDMGEXP, ignore.case = TRUE)] <- "9"
data$CROPDMGEXP <- as.numeric(as.character(data$CROPDMGEXP))
data$crop.damage <- data$CROPDMG * 10^data$CROPDMGEXP

#Analyse #Fatalities and injuries

agg.fatalites.and.injuries <- ddply(data, .(EVENT), summarize, Total = sum(FATALITIES + INJURIES, na.rm = TRUE)) 
agg.fatalites.and.injuries$type <- "fatalities and injuries"

#aggregate FATALITIES by type of EVENT

agg.fatalities <- ddply(data, .(EVENT), summarize, Total = sum(FATALITIES, na.rm = TRUE)) 
agg.fatalities$type <- "fatalities"

#aggregate INJURIES by type of EVENT

agg.injuries <- ddply(data, .(EVENT), summarize, Total = sum(INJURIES, na.rm = TRUE))
agg.injuries$type <- "injuries"

#combine all

agg.health <- rbind(agg.fatalities, agg.injuries)

health.by.event <- join (agg.fatalities, agg.injuries, by="EVENT", type="inner")
health.by.event
##      EVENT Total       type Total     type
## 1     DIFF  2626 fatalities 12224 injuries
## 2    FLOOD  1524 fatalities  8602 injuries
## 3     HAIL    15 fatalities  1371 injuries
## 4     HEAT  3138 fatalities  9224 injuries
## 5     RAIN   114 fatalities   305 injuries
## 6     SNOW   164 fatalities  1164 injuries
## 7    STORM   416 fatalities  5339 injuries
## 8  TORNADO  5661 fatalities 91407 injuries
## 9     WIND  1209 fatalities  9001 injuries
## 10  WINTER   278 fatalities  1891 injuries

#Economic variables

#aggregate PropDamage and CropDamage by type of EVENT

agg.propdmg.and.cropdmg <- ddply(data, .(EVENT), summarize, Total = sum(property.damage + crop.damage, na.rm = TRUE)) 
agg.propdmg.and.cropdmg$type <- "property and crop damage"

#aggregate PropDamage by type of EVENT

agg.prop <- ddply(data, .(EVENT), summarize, Total = sum(property.damage, na.rm = TRUE)) 
agg.prop$type <- "property" #aggregate INJURIES by type of EVENT
agg.crop <- ddply(data, .(EVENT), summarize, Total = sum(crop.damage, na.rm = TRUE)) 
agg.crop$type <- "crop"

#combine all

agg.economic <- rbind(agg.prop, agg.crop)


economic.by.event <- join (agg.prop, agg.crop, by="EVENT", type="inner")
economic.by.event
##      EVENT        Total     type       Total type
## 1     DIFF  97246712337 property 23588880870 crop
## 2    FLOOD 167502193929 property 12266906100 crop
## 3     HAIL  15733043048 property  3046837473 crop
## 4     HEAT     20325750 property   904469280 crop
## 5     RAIN   3270230192 property   919315800 crop
## 6     SNOW   1024169752 property   134683100 crop
## 7    STORM  66304415393 property  6374474888 crop
## 8  TORNADO  58593098029 property   417461520 crop
## 9     WIND  10847166618 property  1403719150 crop
## 10  WINTER   6777295251 property    47444000 crop

Results

Across the United States, which types of events are most harmful with respect to population health?

agg.health$EVENT <- as.factor(agg.health$EVENT)

#plot FATALITIES and INJURIES by EVENT

health_plot <- ggplot(agg.health, aes(x = EVENT, y = Total, fill = type)) + geom_bar(stat = "identity") + coord_flip() + xlab("Event Type") + ylab("Total number of health impact") + ggtitle("Weather event types impact on public health") + theme(plot.title = element_text(hjust = 0.5)) 
print(health_plot)

According to the graph, the most harmful weather event taking injuries and fatalities into consideration is a tornado.

Across the United States, which types of events have the greatest economic consequences?

#transform EVENT to factor variable for economic variables

agg.economic$EVENT <- as.factor(agg.economic$EVENT)

#plot PROPERTY damage and CROP damage by EVENT

economic_plot <- ggplot(agg.economic, aes(x = EVENT, y = Total, fill = type)) + geom_bar(stat = "identity") + coord_flip() + xlab("Event Type") + ylab("Total damage in dollars") + ggtitle("Weather event types impact on property and crop damage") + theme(plot.title = element_text(hjust = 0.5)) 
print(economic_plot)

A flood causes the greatest economic consequences to property and crops because it causes serious damages according to the above graph.