1: Synopsis

The goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events.

The basic questions are the following:

  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?

For Question 1, we preprocess and aggregate the data to find the event type which has the most severe impact in heath. This is manifested in injuries and fatalities.

For Question 2, we preprocess and aggregate the data to identify the event types which have the most severe economic impact. This is manifested in dollars.

2: Data Processing

Data loading and main preprocessing

We need to download the raw data from the webpage.

setwd("C:/GIO/PC/Rprojects/5.ReproducibleResearch/week 4")

Url_datafile <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2"

# download only if not downloaded again.
datafile <- str_replace_all("repdata%2Fdata%2FStormData.csv.bz2", "%2F", "_")
if (!file.exists(datafile)) {
        download.file(Url_datafile, datafile, mode = "wb")
}

# We read the .csv file
raw_data <- read.csv(file = datafile, header = TRUE)

We inspect our data in order to identify the relevant headers

head(raw_data)
##   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 BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1         0                                               0         NA
## 2         0                                               0         NA
## 3         0                                               0         NA
## 4         0                                               0         NA
## 5         0                                               0         NA
## 6         0                                               0         NA
##   END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1         0                      14.0   100 3   0          0       15    25.0
## 2         0                       2.0   150 2   0          0        0     2.5
## 3         0                       0.1   123 2   0          0        2    25.0
## 4         0                       0.0   100 2   0          0        2     2.5
## 5         0                       0.0   150 2   0          0        2     2.5
## 6         0                       1.5   177 2   0          0        6     2.5
##   PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1          K       0                                         3040      8812
## 2          K       0                                         3042      8755
## 3          K       0                                         3340      8742
## 4          K       0                                         3458      8626
## 5          K       0                                         3412      8642
## 6          K       0                                         3450      8748
##   LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1       3051       8806              1
## 2          0          0              2
## 3          0          0              3
## 4          0          0              4
## 5          0          0              5
## 6          0          0              6

3: Question 1

3.1: Data Processing Q1

Towards question 1 - impact on public health, we investigate the contents of EVTYPE, INJURIES and FATALITIES. We will first process the data:

# We aggregate injuries and fatalities using event type
injuries <- aggregate(INJURIES ~ EVTYPE, data = raw_data, sum)
fatalities <- aggregate(FATALITIES ~ EVTYPE, data = raw_data, sum)

# We arrange the number of injuries or fatalities in descending order by Event Type
injuries <- arrange(injuries, desc(INJURIES), EVTYPE)[1:10, ]
fatalities <- arrange(fatalities, desc(FATALITIES), EVTYPE)[1:10, ]

3.2: Results Q1

Lets investigate fatalities and injuries:

injuries
##               EVTYPE INJURIES
## 1            TORNADO    91346
## 2          TSTM WIND     6957
## 3              FLOOD     6789
## 4     EXCESSIVE HEAT     6525
## 5          LIGHTNING     5230
## 6               HEAT     2100
## 7          ICE STORM     1975
## 8        FLASH FLOOD     1777
## 9  THUNDERSTORM WIND     1488
## 10              HAIL     1361
fatalities
##            EVTYPE FATALITIES
## 1         TORNADO       5633
## 2  EXCESSIVE HEAT       1903
## 3     FLASH FLOOD        978
## 4            HEAT        937
## 5       LIGHTNING        816
## 6       TSTM WIND        504
## 7           FLOOD        470
## 8     RIP CURRENT        368
## 9       HIGH WIND        248
## 10      AVALANCHE        224

The events with the most severe impact in terms of injuries are TORNADO while the events with the most severe impact in terms of fatalities are TORNADO.

The following plot provides a graphical display of the top 10 events with the maximum impact on public health in terms of injuries and fatalities.

# We create the plots for the events.
ggplotInjuriesOverEvents <- ggplot(injuries, aes(x = EVTYPE, y = INJURIES)) + 
    geom_line(aes(group=1), colour= "red") +  
    geom_point(size=3, colour = "red") +
    xlab("Event Type") + ylab("Injuries") +
    theme(axis.text.x = element_text(angle = 90))

ggplotFatalitiesOverEvents <- ggplot(fatalities, aes(x = EVTYPE, y = FATALITIES)) + 
    geom_line(aes(group=1), colour= "blue") +  
    geom_point(size=3, colour = "blue") +
    xlab("Event Type") + ylab("Fatalities") +
    theme(axis.text.x = element_text(angle = 90))

# we create/display a panel plot (2 columns)
grid.arrange(ggplotInjuriesOverEvents, ggplotFatalitiesOverEvents, ncol = 2, nrow = 1,
              top = textGrob("Events with maximum impact on public health in terms of injuries and fatalities", 
              gp = gpar(fontsize = 14)))

The peak in the graphic plot indicates the events (TORNADO causing most injuries and TORNADO causing most fatalities) from the most severe impact in public health.

4: Question 2

4.1: Data Processing Q2

Towards question 2 - greatest economic impact, we investigate the content of CROPDMG (Crop damage) and CROPDMGEXP (corresponding exponent) as well as PROPDMG (Property damage) and PROPDMGEXP (corresponding exponent).

We will need to fuse the information of both variables in order to have a single value for the damage. This is performed by factoring the exponent value into the magnitude value. We will create a further variable TOTALDMG_VAL with the total damage as the sum of both types of damage.

# We factor the exponent value into the magintude value
raw_data$CROPDMG_VAL[raw_data$CROPDMG==0] <- 0 
raw_data$PROPDMG_VAL[raw_data$PROPDMG==0] <- 0  

raw_data$CROPDMG_VAL[raw_data$CROPDMGEXP=="H"| raw_data$CROPDMGEXP=="h"] <- raw_data$CROPDMG[raw_data$CROPDMGEXP=="H"|raw_data$CROPDMGEXP=="h"]*1e2
raw_data$PROPDMG_VAL[raw_data$PROPDMGEXP=="H"| raw_data$PROPDMGEXP=="h"] <- raw_data$PROPDMG[raw_data$PROPDMGEXP=="H"|raw_data$PROPDMGEXP=="h"]*1e2

raw_data$CROPDMG_VAL[raw_data$CROPDMGEXP=="K"| raw_data$CROPDMGEXP=="k"] <- raw_data$CROPDMG[raw_data$CROPDMGEXP=="K"|raw_data$CROPDMGEXP=="k"]*1e3
raw_data$PROPDMG_VAL[raw_data$PROPDMGEXP=="K"| raw_data$PROPDMGEXP=="k"] <- raw_data$PROPDMG[raw_data$PROPDMGEXP=="K"|raw_data$PROPDMGEXP=="k"]*1e3

raw_data$CROPDMG_VAL[raw_data$CROPDMGEXP=="M"| raw_data$CROPDMGEXP=="m"] <- raw_data$CROPDMG[raw_data$CROPDMGEXP=="M"|raw_data$CROPDMGEXP=="m"]*1e6
raw_data$PROPDMG_VAL[raw_data$PROPDMGEXP=="M"| raw_data$PROPDMGEXP=="m"] <- raw_data$PROPDMG[raw_data$PROPDMGEXP=="M"|raw_data$PROPDMGEXP=="m"]*1e6

raw_data$CROPDMG_VAL[raw_data$CROPDMGEXP=="B"| raw_data$CROPDMGEXP=="b"] <- raw_data$CROPDMG[raw_data$CROPDMGEXP=="B"|raw_data$CROPDMGEXP=="b"]*1e9
raw_data$PROPDMG_VAL[raw_data$PROPDMGEXP=="B"| raw_data$PROPDMGEXP=="b"] <- raw_data$PROPDMG[raw_data$PROPDMGEXP=="B"|raw_data$PROPDMGEXP=="b"]*1e9

# We create a total damage variable
raw_data$TOTALDMG_VAL <- raw_data$CROPDMG_VAL + raw_data$PROPDMG_VAL

Now we will aggregate the new variables CROPDMG_VAL, PROPDMG_VAL and TOTALDMG_VAL with the full range values along the events.

# We aggregate the damages by event type
cropdmg <- aggregate(CROPDMG_VAL ~ EVTYPE, data = raw_data, sum, na.rm = TRUE)
propdmg <- aggregate(PROPDMG_VAL ~ EVTYPE, data = raw_data, sum, na.rm = TRUE)

totaldmg <- aggregate(TOTALDMG_VAL ~ EVTYPE, data = raw_data, sum, na.rm = TRUE)

# We arrange the damage value on crop, property and in total in descending order by Event Type 
cropdmg <- arrange(cropdmg, desc(CROPDMG_VAL), EVTYPE)[1:10, ]
propdmg <- arrange(propdmg, desc(PROPDMG_VAL), EVTYPE)[1:10, ]
totaldmg <- arrange(totaldmg, desc(TOTALDMG_VAL), EVTYPE)[1:10, ]

4.2: Results Q2

Now lets investigate the damages by event type.

cropdmg 
##               EVTYPE CROPDMG_VAL
## 1            DROUGHT 13972566000
## 2              FLOOD  5661968450
## 3        RIVER FLOOD  5029459000
## 4          ICE STORM  5022113500
## 5               HAIL  3025954450
## 6          HURRICANE  2741910000
## 7  HURRICANE/TYPHOON  2607872800
## 8        FLASH FLOOD  1421317100
## 9       EXTREME COLD  1292973000
## 10      FROST/FREEZE  1094086000
propdmg 
##               EVTYPE  PROPDMG_VAL
## 1              FLOOD 144657709800
## 2  HURRICANE/TYPHOON  69305840000
## 3            TORNADO  56937160480
## 4        STORM SURGE  43323536000
## 5        FLASH FLOOD  16140811510
## 6               HAIL  15732267220
## 7          HURRICANE  11868319010
## 8     TROPICAL STORM   7703890550
## 9       WINTER STORM   6688497250
## 10         HIGH WIND   5270046260
totaldmg 
##               EVTYPE TOTALDMG_VAL
## 1              FLOOD 150319678250
## 2  HURRICANE/TYPHOON  71913712800
## 3            TORNADO  57301940590
## 4        STORM SURGE  43323541000
## 5               HAIL  18733211670
## 6        FLASH FLOOD  17561528610
## 7            DROUGHT  15018672000
## 8          HURRICANE  14610229010
## 9        RIVER FLOOD  10148404500
## 10         ICE STORM   8967037810

The events with the most severe economic impact are DROUGHT on crop damage, FLOOD on property damage and, FLOOD in total damage.

The following plot provides a graphical display of the top 10 events with the maximum economic impact.

# We create the plots for the events.
ggplotCropDmgOverEvents <- ggplot(cropdmg, aes(x = EVTYPE, y = CROPDMG_VAL/1e9)) + 
    geom_line(aes(group=1), colour= "red") +  
    geom_point(size=3, colour = "red") +
    xlab("Event Type") + ylab("Crop Damage [Billions $]") +
    theme(axis.text.x = element_text(angle = 90))

ggplotPropDmgOverEvents <- ggplot(propdmg, aes(x = EVTYPE, y = PROPDMG_VAL/1e9)) + 
    geom_line(aes(group=1), colour= "blue") +  
    geom_point(size=3, colour = "blue") +
    xlab("Event Type") + ylab("Property Damage [Billions $]") +
    theme(axis.text.x = element_text(angle = 90))

ggplotTotalDmgOverEvents <- ggplot(totaldmg, aes(x = EVTYPE, y = TOTALDMG_VAL/1e9)) + 
    geom_line(aes(group=1), colour= "black") +  
    geom_point(size=3, colour = "black") +
    xlab("Event Type") + ylab("Total Damage [Billions $]") +
    theme(axis.text.x = element_text(angle = 90))

# We create/display a panel plot (3 columns)
grid.arrange(ggplotCropDmgOverEvents, ggplotPropDmgOverEvents, ggplotTotalDmgOverEvents, ncol = 3, nrow = 1,
              top = textGrob("Events with maximum economic impact on crop, property and in total", 
              gp = gpar(fontsize = 14)))

The peaks in the graphic plots indicate the events with the most severe economic impact (DROUGHT on crop damage, FLOOD on property damage and, FLOOD in total damage).

Conclusions

Q1: The events with the most severe impact in terms of injuries are TORNADO while the events with the most severe impact in terms of fatalities are TORNADO.

Q2: The events with the most severe economic impact are DROUGHT on crop damage, FLOOD on property damage and, FLOOD in total damage.