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.
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.
## [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"
As previously informed we will only use the variables that will be part of the analysis to answer the questions:
## '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 ...
## '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 "" "" "" "" ...
## 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
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
df_health$FATALITIES <- as.numeric(df_health$FATALITIES)
df_health$INJURIES <- as.numeric(df_health$INJURIES)
dim(df_health)## [1] 902297 3
## [1] 985 4
| 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 |
## [1] "K" "M" "" "B" "m" "+" "0" "5" "6" "?" "4" "2" "3" "h" "7" "H" "-" "1" "8"
## [1] "" "M" "K" "m" "B" "?" "0" "k" "2"
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
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| 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 |
Now, let’s plot the results.
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')
plot1Bar 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