1. Synopsis:

Storm Data is an official publication of the National Oceanic and Atmospheric Administration (NOAA) which documents the occurrence of storms and other significant weather phenomena having sufficient intensity to cause loss of life, injuries, significant property damage, and/or disruption to commerce.

This report aims to respond to requests from governmental and municipal managers responsible for the preparation of severe weather events to make resource prioritization decisions for different types of events, and it is necessary to answer two questions about harm health and economia.

Through the code and plots it will be showed which type of event is most harmful to the health of the population and which type of event has the greatest impact on the economy.

No specific recommendations will be made in this report, but the information will contribute to prioritizing resources for different types of events and support the gestores.

2. Data Processing

2.1 Cleaning workspace

rm(list = ls())

2.2 Load Libraries

library(plyr)
library(ggplot2)
library(gridExtra)

2.3 Informations about the variables

After reading the codebook, the variables necessary for the analysis and answers to the proposed questions were selected.These variables are listed below:

Variables harmful to the health of the population:

Variables that influence economic impact :

The data for this assignment come in the form of a comma-separated-value (CSV) file compressed via the bzip2 algorithm to reduce its size.

2.4 Reading dataframe.

storm <- tempfile()

download.file("http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", storm)

data <-read.csv(storm)

unlink(storm)

2.5 Checking the variables name

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"

2.6 Analysis Process

As previously informed we will only use the variables that will be part of the analysis to answer the questions:

  1. Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
  2. Across the United States, which types of events have the greatest economic consequences?

2.7 Obtaining a new dataset (df) with only the variables necessary for analysis

2.7.1 Health

df_health <- data[,c("EVTYPE","FATALITIES","INJURIES")]
str(df_health)
## 'data.frame':    902297 obs. of  3 variables:
##  $ EVTYPE    : chr  "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
##  $ FATALITIES: num  0 0 0 0 0 0 0 0 1 0 ...
##  $ INJURIES  : num  15 0 2 2 2 6 1 0 14 0 ...

2.7.2 Economic

df_economic <- data[,c("EVTYPE","PROPDMG","PROPDMGEXP","CROPDMG","CROPDMGEXP")]
str(df_economic)
## 'data.frame':    902297 obs. of  5 variables:
##  $ EVTYPE    : chr  "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
##  $ 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  "" "" "" "" ...
summary(df_health)
##     EVTYPE            FATALITIES          INJURIES        
##  Length:902297      Min.   :  0.0000   Min.   :   0.0000  
##  Class :character   1st Qu.:  0.0000   1st Qu.:   0.0000  
##  Mode  :character   Median :  0.0000   Median :   0.0000  
##                     Mean   :  0.0168   Mean   :   0.1557  
##                     3rd Qu.:  0.0000   3rd Qu.:   0.0000  
##                     Max.   :583.0000   Max.   :1700.0000

2.8 Checking missing values

2.8.1 Health

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

2.8.2 Economics

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

As we can see don’t have missing values in df_health and df_economic

2.9 Analysis of the impact on population health resulting in deaths and injuries

Let’s calculate fatalities and injuries by event type to determine which storms and other weather events are most harmful to public health in the USA Let’s created a column with the total value that will be the adding of fatalities and injuries values

2.9.1 Changing characters to numeric values

df_health$FATALITIES <- as.numeric(df_health$FATALITIES)
df_health$INJURIES <- as.numeric(df_health$INJURIES)
dim(df_health)
## [1] 902297      3

2.9.2 Creating a new dataframe

harm_health <- aggregate(cbind(FATALITIES, INJURIES) ~ EVTYPE, data = df_health, FUN=sum)

2.9.3 Creating a new variable called HARM_HEALTH adding the values of the variables FATALITIES and INJURIES.

harm_health$HARM_HEALTH <- harm_health$FATALITIES + harm_health$INJURIES
dim(harm_health)
## [1] 985   4

2.9.4 Creating a dataframe with the 10 most weather events that have harmed the health of the population

TOP_harm_health <- arrange(harm_health, desc(harm_health$HARM_HEALTH))[1:10,]

2.9.5 Showing the health values in a table

knitr::kable(TOP_harm_health, format = "markdown")
EVTYPE FATALITIES INJURIES HARM_HEALTH
TORNADO 5633 91346 96979
EXCESSIVE HEAT 1903 6525 8428
TSTM WIND 504 6957 7461
FLOOD 470 6789 7259
LIGHTNING 816 5230 6046
HEAT 937 2100 3037
FLASH FLOOD 978 1777 2755
ICE STORM 89 1975 2064
THUNDERSTORM WIND 133 1488 1621
WINTER STORM 206 1321 1527

2.10 Analysis of the economic impact on crop and property

2.10.1 Checking the characters

unique(df_economic$PROPDMGEXP)
##  [1] "K" "M" ""  "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"
unique(df_economic$CROPDMGEXP)
## [1] ""  "M" "K" "m" "B" "?" "0" "k" "2"

2.10.2 Understanding the meaning of the characters and assigning values to them.

We take the information about the caracters values by this web address: Information about the values

These are possible values of CROPDMGEXP and PROPDMGEXP:

  • H,h,K,k,M,m,B,b,+,-,?,0,1,2,3,4,5,6,7,8, and blank-character

  • H,h = hundreds = 100

  • K,k = kilos = thousands = 1,000

  • M,m = millions = 1,000,000

  • B,b = billions = 1,000,000,000

  • (+) = 1

  • (-) = 0

  • (?) = 0

  • black/empty character = 0

  • numeric 0…8 = 10

2.10.3 Normalization and Standardization

First of all we need to transform the values so that they are standardized and normalized to that can be manipulated

# Chaning lowercase to uppercase
df_economic$PROPDMGEXP <- toupper(df_economic$PROPDMGEXP)
df_economic$CROPDMGEXP <- toupper(df_economic$CROPDMGEXP)
# Let's multiply the propery and crop damage values by thier respective exponents.
df_economic$PROPDMGEXP <- gsub("[H]", "2", df_economic$PROPDMGEXP)
df_economic$PROPDMGEXP <- gsub("[K]", "3", df_economic$PROPDMGEXP)
df_economic$PROPDMGEXP <- gsub("[M]", "6", df_economic$PROPDMGEXP)
df_economic$PROPDMGEXP <- gsub("[B]", "9", df_economic$PROPDMGEXP)
df_economic$PROPDMGEXP <- gsub("\\+", "1", df_economic$PROPDMGEXP)
df_economic$PROPDMGEXP <- gsub("\\?|\\-|\\ ", "0",  df_economic$PROPDMGEXP)
df_economic$CROPDMGEXP <- gsub("[H]", "2", df_economic$CROPDMGEXP)
df_economic$CROPDMGEXP <- gsub("[K]", "3", df_economic$CROPDMGEXP)
df_economic$CROPDMGEXP <- gsub("[M]", "6", df_economic$CROPDMGEXP)
df_economic$CROPDMGEXP <- gsub("[B]", "9", df_economic$CROPDMGEXP)
df_economic$CROPDMGEXP <- gsub("\\+", "1", df_economic$CROPDMGEXP)
df_economic$CROPDMGEXP <- gsub("\\-|\\?|\\ ", "0", df_economic$CROPDMGEXP)

# changing characters to numbers
df_economic$PROPDMGEXP <- as.numeric(df_economic$PROPDMGEXP)
df_economic$CROPDMGEXP <- as.numeric(df_economic$CROPDMGEXP)

# filling in the missing values with zero
df_economic$PROPDMGEXP[is.na(df_economic$PROPDMGEXP)] <- 0
df_economic$CROPDMGEXP[is.na(df_economic$CROPDMGEXP)] <- 0
# using millions as standard

df_economic <- mutate(df_economic,
                      PROPDMG_T = (PROPDMG*(10^PROPDMGEXP))/1000000,
                      CROPDMG_T = (CROPDMG * (10 ^ CROPDMGEXP))/1000000)

2.10.4 Creating of a dataframe with the 10 events that most caused damage to crops and properties

economic_loss <- aggregate(cbind(PROPDMG_T, CROPDMG_T) ~ EVTYPE, data = df_economic, FUN=sum)

2.10.5 new column

economic_loss$ECONOMIC_LOSS <- economic_loss$PROPDMG_T + economic_loss$CROPDMG_T

2.10.6 In this next step, we will choose at the 10 storms and weather events that have done the most serious damage to properties and crop.

TOP_economic_loss <- arrange(economic_loss, desc(economic_loss$ECONOMIC_LOSS))[1:10,]

2.10.7 Showing the economic values in a table

knitr::kable(TOP_economic_loss, format = "markdown")
EVTYPE PROPDMG_T CROPDMG_T ECONOMIC_LOSS
FLOOD 144657.710 5661.9685 150319.678
HURRICANE/TYPHOON 69305.840 2607.8728 71913.713
TORNADO 56947.381 414.9533 57362.334
STORM SURGE 43323.536 0.0050 43323.541
HAIL 15735.268 3025.9545 18761.222
FLASH FLOOD 16822.674 1421.3171 18243.991
DROUGHT 1046.106 13972.5660 15018.672
HURRICANE 11868.319 2741.9100 14610.229
RIVER FLOOD 5118.945 5029.4590 10148.405
ICE STORM 3944.928 5022.1135 8967.041

3. Results

Now, let’s plot the results.

3.1 Health Impact

Bar graphs showing the ten most damaging events for the health of the population causing injuries and fatalities.

plot1<- ggplot(TOP_harm_health,aes(x=reorder(EVTYPE,HARM_HEALTH),
                                  y = HARM_HEALTH, fill = HARM_HEALTH)) + 
    geom_bar(stat='identity',colour='white')+ 
    ggtitle('The 10 most harmful people in the population')+
    xlab('Type of Event')+
    coord_flip()+
    ylab('Total Fatality Plus Injury')
plot1

3.2 Economic Impact

Bar charts showing the ten most damaging events that impact the economy

plot3<- ggplot(TOP_economic_loss,aes(x=reorder(EVTYPE,ECONOMIC_LOSS),
                                  y = ECONOMIC_LOSS, fill = ECONOMIC_LOSS)) + 
    geom_bar(stat='identity',colour='white')+ 
    ggtitle('The 10 Most Damaging Weather Events')+
    xlab('Type of Event')+
    coord_flip()+
    ylab('Economic Loss in Millions US$, Crop Plus Property')
plot3