Synopsis

This report we aim to provide some insights about severe weather events for a government or municipal manager who might be responsible for preparing for severe weather events whom will need to prioritize resources for different types of events. Specifically, this reports will try to identify which types of events are the most harmful to population health and the most costly to the economy. Recommendations are provided at the end of the report.

Data Processing

Loading necessary libraries and set options

library(knitr)
library(data.table)
library(xtable)
library(ggplot2)
library(R.utils)
## Loading required package: R.oo
## Loading required package: R.methodsS3
## R.methodsS3 v1.6.1 (2014-01-04) successfully loaded. See ?R.methodsS3 for help.
## R.oo v1.18.0 (2014-02-22) successfully loaded. See ?R.oo for help.
## 
## Attaching package: 'R.oo'
## 
## The following objects are masked from 'package:methods':
## 
##     getClasses, getMethods
## 
## The following objects are masked from 'package:base':
## 
##     attach, detach, gc, load, save
## 
## R.utils v1.34.0 (2014-10-07) successfully loaded. See ?R.utils for help.
## 
## Attaching package: 'R.utils'
## 
## The following object is masked from 'package:utils':
## 
##     timestamp
## 
## The following objects are masked from 'package:base':
## 
##     cat, commandArgs, getOption, inherits, isOpen, parse, warnings
library(gridExtra)
## Loading required package: grid
library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:data.table':
## 
##     between, last
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## The following object is masked from 'package:data.table':
## 
##     last
## 
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
opts_chunk$set(echo = TRUE, results = 'hold')
options(digits = 7)
opts_chunk$set(fig.width=10)

Download , Load and preprocessing the data

  1. Download the file
#download.file("http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", destfile="repdata-data-StormData.csv.bz2")
  1. Unzip and read the data
#bunzip2("repdata-data-StormData.csv.bz2", overwrite=T, remove=F)
stormactivity <- read.csv("repdata-data-StormData.csv",sep=",",quote="\"",
                         header=TRUE,  na.strings="NA")
  1. Preprocess the data , clean and convert to the proper format
#Filtering down to the data that has value more than 0
     filterStormData <-subset(stormactivity, FATALITIES >0 | INJURIES >0 | PROPDMG > 0 | CROPDMG > 0) 

#The events in the database start in the year 1950 and end in November 2011. In the earlier years of the database there are generally fewer events recorded, most likely due to a lack of good records. More recent years should be considered more complete. We that , we only analysis data from the last 10 years withhas a more complete set of data.

    filterStormData$year <- as.numeric(format(as.Date(filterStormData$BGN_DATE, format="%m/%d/%Y %H:%M:%S"), "%Y"))

    filterStormData <- filterStormData[filterStormData$year >=2001,]


#Convert event type to upper case 
    filterStormData[,c("EVTYPE")] <- toupper(filterStormData[,c("EVTYPE")])

#Combine and Standardize the events to a main event type
    filterStormData[filterStormData$EVTYPE=="AVALANCE",c("EVTYPE")] <- "AVALANCHE"

    filterStormData[grep("BLIZZARD*",filterStormData$EVTYPE),c("EVTYPE")] <- "BLIZZARD"

    filterStormData[grep("HAIL*",filterStormData$EVTYPE),c("EVTYPE")] <- "HAIL"

    filterStormData[grep("HEAVY RAIN*",filterStormData$EVTYPE),c("EVTYPE")] <- "HEAVY RAIN"

    filterStormData[grep("WATERSPOUT*",filterStormData$EVTYPE),c("EVTYPE")] <-"WATERSPOUT"

    filterStormData[grep("HURRICANE*",filterStormData$EVTYPE),c("EVTYPE")] <-"HURRICANE"

    filterStormData[grep("THUNDERSTORM*|TUNDERSTORM WIND*|TSTM WIND*|THUDERSTORM WINDS*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("THUNDEERSTORM WINDS*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("THUNDERESTORM WINDS*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("THUNDERTORM WINDS*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("THUNERSTORM WINDS*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("THUNDERSTROM WIND*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("THUNDERSTROM WIND*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("TSTMW*",filterStormData$EVTYPE),c("EVTYPE")] <-"THUNDERSTORM WIND"

    filterStormData[grep("TORNADO*",filterStormData$EVTYPE),c("EVTYPE")] <-"TORNADO"

    filterStormData[grep("TORNDAO*",filterStormData$EVTYPE),c("EVTYPE")] <-"TORNADO"

    filterStormData[grep("RIP CURRENT*",filterStormData$EVTYPE),c("EVTYPE")] <-"RIP CURRENT"

    filterStormData[grep("STRONG WIND*",filterStormData$EVTYPE),c("EVTYPE")] <-"STRONG WIND"

    filterStormData[grep("LIGHTNING*",filterStormData$EVTYPE),c("EVTYPE")] <-"LIGHTNING"

    filterStormData[grep("LIGHTING*|LIGNTNING*",filterStormData$EVTYPE),c("EVTYPE")] <-"LIGHTNING"       

    filterStormData[grep("FLASH FLOOD*",filterStormData$EVTYPE),c("EVTYPE")] <-"FLASH FLOOD" 

    filterStormData[grep("WINTER WEATHER*",filterStormData$EVTYPE),c("EVTYPE")] <-"WINTER WEATHER"

    filterStormData[grep("WINTER STORM*",filterStormData$EVTYPE),c("EVTYPE")] <-"WINTER STORM"

    filterStormData[grep("TROPICAL STORM*",filterStormData$EVTYPE),c("EVTYPE")] <-"TROPICAL STORM"

    filterStormData[grep("HEAVY SNOW*",filterStormData$EVTYPE),c("EVTYPE")] <-"HEAVY SNOW"

    filterStormData[grep("HEAVY RAIN*|HVY RAIN*",filterStormData$EVTYPE),c("EVTYPE")] <-"HEAVY RAIN"

    filterStormData[grep("FLOOD/FLASH*|FLOOD FLASH*",filterStormData$EVTYPE),c("EVTYPE")] <-"FLASH FLOOD"

    filterStormData[grep("FLOODING|FLOOD/RIVER FLOOD|FLOODS|FLOOD/RAIN/WINDS",filterStormData$EVTYPE),c("EVTYPE")] <-"FLOOD"

    filterStormData[grep("WILDFIRES*|WILD FIRES*|WILDFIRE*|WILD/FOREST*",filterStormData$EVTYPE),c("EVTYPE")] <-"WILDFIRE"

    filterStormData[grep("HURRICANE*|TYPHOON*",filterStormData$EVTYPE),c("EVTYPE")] <-"HURRICANE (TYPHOON)"   

#Convert the Property and Crop Damage to the correct units as per in the codebook (National Climatic Data Center's record layout document, which is referenced on the Investigative Reporers & Editors web site.)

    filterStormData$PROPDMGEXP = as.character(filterStormData$PROPDMGEXP)
    filterStormData$PROPDMGEXP[toupper(filterStormData$PROPDMGEXP) == 'B'] = "9"
    filterStormData$PROPDMGEXP[toupper(filterStormData$PROPDMGEXP) == 'M'] = "6"
    filterStormData$PROPDMGEXP[toupper(filterStormData$PROPDMGEXP) == 'K'] = "3"
    filterStormData$PROPDMGEXP[toupper(filterStormData$PROPDMGEXP) == 'H'] = "2"
    filterStormData$PROPDMGEXP = as.numeric(filterStormData$PROPDMGEXP)
    filterStormData$PROPDMGEXP[is.na(filterStormData$PROPDMGEXP)] = 0
    filterStormData$PropertyDamage = filterStormData$PROPDMG * 10^filterStormData$PROPDMGEXP

    filterStormData$CROPDMGEXP = as.character(filterStormData$CROPDMGEXP)
    filterStormData$CROPDMGEXP[toupper(filterStormData$CROPDMGEXP) == 'B'] = "9"
    filterStormData$CROPDMGEXP[toupper(filterStormData$CROPDMGEXP) == 'M'] = "6"
    filterStormData$CROPDMGEXP[toupper(filterStormData$CROPDMGEXP) == 'K'] = "3"
    filterStormData$CROPDMGEXP[toupper(filterStormData$CROPDMGEXP) == 'H'] = "2"
    filterStormData$CROPDMGEXP = as.numeric(filterStormData$CROPDMGEXP)
    filterStormData$CROPDMGEXP[is.na(filterStormData$CROPDMGEXP)] = 0
    filterStormData$CropDamage = filterStormData$PROPDMG * 10^filterStormData$CROPDMGEXP
  1. Preview the data read
        head(filterStormData,n=10)
##        STATE__          BGN_DATE    BGN_TIME TIME_ZONE COUNTY COUNTYNAME
## 413286       1 2/25/2001 0:00:00 01:00:00 AM       CST    133    WINSTON
## 413287       1 2/25/2001 0:00:00 01:15:00 AM       CST     91    MARENGO
## 413289       1 2/27/2001 0:00:00 04:45:00 PM       CST     99     MONROE
## 413290       1 2/27/2001 0:00:00 04:50:00 PM       CST     35    CONECUH
## 413291       1  3/2/2001 0:00:00 03:15:00 PM       CST     23    CHOCTAW
## 413292       1  3/2/2001 0:00:00 04:55:00 PM       CST     47     DALLAS
## 413293       1  3/2/2001 0:00:00 06:29:00 PM       CST    101 MONTGOMERY
## 413294       1  3/2/2001 0:00:00 09:18:00 PM       CST      5    BARBOUR
## 413295       1  3/3/2001 0:00:00 02:30:00 AM       CST     23    CHOCTAW
## 413296       1  7/5/2001 0:00:00 02:00:00 PM       CST    127     WALKER
##        STATE            EVTYPE BGN_RANGE BGN_AZI  BGN_LOCATI
## 413286    AL THUNDERSTORM WIND         0             ADDISON
## 413287    AL THUNDERSTORM WIND         0         SWEET WATER
## 413289    AL THUNDERSTORM WIND         7      NE    PETERMAN
## 413290    AL THUNDERSTORM WIND         0            NICHBURG
## 413291    AL THUNDERSTORM WIND         0               TOXEY
## 413292    AL THUNDERSTORM WIND         0          COUNTYWIDE
## 413293    AL           TORNADO         0          MONTGOMERY
## 413294    AL THUNDERSTORM WIND         0          LOUISVILLE
## 413295    AL       FLASH FLOOD         0          COUNTYWIDE
## 413296    AL       FLASH FLOOD         0             CORDOVA
##                 END_DATE    END_TIME COUNTY_END COUNTYENDN END_RANGE
## 413286 2/25/2001 0:00:00 01:00:00 AM          0         NA         0
## 413287 2/25/2001 0:00:00 01:20:00 AM          0         NA         0
## 413289 2/27/2001 0:00:00 04:50:00 PM          0         NA         7
## 413290 2/27/2001 0:00:00 04:55:00 PM          0         NA         0
## 413291  3/2/2001 0:00:00 03:20:00 PM          0         NA         0
## 413292  3/2/2001 0:00:00 05:25:00 PM          0         NA         0
## 413293  3/2/2001 0:00:00 06:33:00 PM          0         NA         0
## 413294  3/2/2001 0:00:00 09:18:00 PM          0         NA         0
## 413295  3/3/2001 0:00:00 06:30:00 PM          0         NA         0
## 413296  7/5/2001 0:00:00 03:00:00 PM          0         NA         0
##        END_AZI  END_LOCATI LENGTH WIDTH  F MAG FATALITIES INJURIES PROPDMG
## 413286             ADDISON    0.0     0 NA  50          0        0       2
## 413287         SWEET WATER    0.0     0 NA  75          0        0      15
## 413289      NE    PETERMAN    0.0     0 NA  55          0        0       5
## 413290            NICHBURG    0.0     0 NA  55          0        0       5
## 413291               TOXEY    0.0     0 NA  55          0        0       3
## 413292          COUNTYWIDE    0.0     0 NA  50          0        0       4
## 413293          MONTGOMERY    2.2   100  1   0          0        0     125
## 413294          LOUISVILLE    0.0     0 NA  50          0        0       6
## 413295          COUNTYWIDE    0.0     0 NA   0          0        0      10
## 413296             CORDOVA    0.0     0 NA   0          0        0       3
##        PROPDMGEXP CROPDMG CROPDMGEXP WFO         STATEOFFIC ZONENAMES
## 413286          3       0          3 BMX   ALABAMA, Central          
## 413287          3       0          0 MOB ALABAMA, Southwest          
## 413289          3       0          0 MOB ALABAMA, Southwest          
## 413290          3       0          0 MOB ALABAMA, Southwest          
## 413291          3       0          0 MOB ALABAMA, Southwest          
## 413292          3       0          3 BMX   ALABAMA, Central          
## 413293          3       0          3 BMX   ALABAMA, Central          
## 413294          3       0          3 BMX   ALABAMA, Central          
## 413295          3       0          0 MOB ALABAMA, Southwest          
## 413296          3       0          3 BMX   ALABAMA, Central          
##        LATITUDE LONGITUDE LATITUDE_E LONGITUDE_
## 413286     3412      8711       3412       8711
## 413287     3206      8752       3206       8752
## 413289     3139      8711       3139       8711
## 413290     3129      8708       3129       8708
## 413291     3154      8818       3154       8818
## 413292     3220      8708       3220       8708
## 413293     3223      8618       3223       8618
## 413294     3147      8534       3147       8534
## 413295        0         0          0          0
## 413296        0         0          0          0
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               REMARKS
## 413286                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            A few trees were blown down in the northeast part of Winston County near Addison.\n
## 413287                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               Strong thunderstorm winds completely removed the roof  of a mobile home.  Trees that were blown down by the storm produced damage to two other nearby homes.  \n
## 413289                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Thunderstorm winds blew down trees near Grey's Store, which is about 7 miles northeast of Peterman.  \n
## 413290                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Trees were blown down by strong thunderstorms north of the community.  Most of the downed trees were located between Pine Orchard and Ramah.   \n
## 413291                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Wind damage reported in the community as a thunderstorm moved through. \n
## 413292                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Several trees were blown down across the entire county.  The Selma Police Department reported most of the trees were blown down in rural areas.\n
## 413293 The tornado began in the Woodmere area where a number of houses sustained roof damage primarily in the form of lost shingles, fences were downed, and small trees were uprooted. The tornado moved northeast and tracked through the Beauvoir Lake subdivision where one house under construction was flattened and another house was partially deroofed with serious damage to the upper level. \n\nFrom Beauvoir Lake subdivision the tornado downed trees and removed shingles from house roofs in the Halcyon area. The tornado crossed Interstate 85 just west of the Taylor Road exit snapping off numerous pine trees in the interstate median. The tornado apparently ended at Taylor Road on the north side of the interstate. \n\nThe tornado was rated at F1 based on structural damage in the Beauvoir Lake area. Much of the damage along the track was in the F0 category.  The tornado track was 2.2 miles in length and estimated to be about 100 yards wide at it's widest point. The tornado began at 6:29 PM and ended at 6:33 PM. No injuries or deaths were reported with this storm.\n\n
## 413294                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Several trees were blown down and one barn was destroyed in Louisville.\n
## 413295                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Heavy rains across the counties caused many secondary roads to washout.  Several of the roads were closed throughout the day due to high water.  Radar estimated three to five inches of rain fell across the area.
## 413296                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Several roads were covered with water and temporarily impassable in and around the city of Cordova.\n
##        REFNUM year PropertyDamage CropDamage
## 413286 413687 2001           2000       2000
## 413287 413688 2001          15000         15
## 413289 413690 2001           5000          5
## 413290 413691 2001           5000          5
## 413291 413692 2001           3000          3
## 413292 413693 2001           4000       4000
## 413293 413694 2001         125000     125000
## 413294 413695 2001           6000       6000
## 413295 413696 2001          10000         10
## 413296 414083 2001           3000       3000
  1. Show data summary
xt <- xtable(summary(stormactivity))
print(xt, type = "html")
STATE__ BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
1 Min. : 1.0 5/25/2011 0:00:00: 1202 12:00:00 AM: 10163 CST :547493 Min. : 0.0 JEFFERSON : 7840 TX : 83728 HAIL :288661 Min. : 0.000 :547332 :287743 :243411 :238978 Min. :0 Mode:logical Min. : 0.0000 :724837 :499225 Min. : 0.0000 Min. : 0.000 Min. :0.0 Min. : 0.0 Min. : 0.0000 Min. : 0.0000 Min. : 0.00 :465934 Min. : 0.000 :618413 :142069 :248769 :594029 Min. : 0 Min. :-14451 Min. : 0 Min. :-14455 :287433 Min. : 1
2 1st Qu.:19.0 4/27/2011 0:00:00: 1193 06:00:00 PM: 7350 EST :245558 1st Qu.: 31.0 WASHINGTON: 7603 KS : 53440 TSTM WIND :219940 1st Qu.: 0.000 N : 86752 COUNTYWIDE : 19680 4/27/2011 0:00:00: 1214 06:00:00 PM: 9802 1st Qu.:0 NA’s:902297 1st Qu.: 0.0000 N : 28082 COUNTYWIDE : 19731 1st Qu.: 0.0000 1st Qu.: 0.000 1st Qu.:0.0 1st Qu.: 0.0 1st Qu.: 0.0000 1st Qu.: 0.0000 1st Qu.: 0.00 K :424665 1st Qu.: 0.000 K :281832 OUN : 17393 TEXAS, North : 12193 :205988 1st Qu.:2802 1st Qu.: 7247 1st Qu.: 0 1st Qu.: 0 : 24013 1st Qu.:225575
3 Median :30.0 6/9/2011 0:00:00 : 1030 04:00:00 PM: 7261 MST : 68390 Median : 75.0 JACKSON : 6660 OK : 46802 THUNDERSTORM WIND: 82563 Median : 0.000 W : 38446 Countywide : 993 5/25/2011 0:00:00: 1196 05:00:00 PM: 8314 Median :0 Median : 0.0000 S : 22510 SOUTH PORTION : 833 Median : 0.0000 Median : 0.000 Median :1.0 Median : 50.0 Median : 0.0000 Median : 0.0000 Median : 0.00 M : 11330 Median : 0.000 M : 1994 JAN : 13889 ARKANSAS, Central and North Central: 11738 GREATER RENO / CARSON CITY / M - GREATER RENO / CARSON CITY / M : 639 Median :3540 Median : 8707 Median : 0 Median : 0 Trees down. : 1110 Median :451149
4 Mean :31.2 5/30/2004 0:00:00: 1016 05:00:00 PM: 6891 PST : 28302 Mean :100.6 FRANKLIN : 6256 MO : 35648 TORNADO : 60652 Mean : 1.484 S : 37558 SPRINGFIELD : 843 6/9/2011 0:00:00 : 1021 04:00:00 PM: 8104 Mean :0 Mean : 0.9862 W : 20119 NORTH PORTION : 780 Mean : 0.2301 Mean : 7.503 Mean :0.9 Mean : 46.9 Mean : 0.0168 Mean : 0.1557 Mean : 12.06 0 : 216 Mean : 1.527 k : 21 LWX : 13174 IOWA, Central : 11345 GREATER LAKE TAHOE AREA - GREATER LAKE TAHOE AREA : 592 Mean :2875 Mean : 6940 Mean :1452 Mean : 3509 Several trees were blown down. : 569 Mean :451149
5 3rd Qu.:45.0 4/4/2011 0:00:00 : 1009 12:00:00 PM: 6703 AST : 6360 3rd Qu.:131.0 LINCOLN : 5937 IA : 31069 FLASH FLOOD : 54277 3rd Qu.: 1.000 E : 33178 SOUTH PORTION: 810 4/4/2011 0:00:00 : 1007 12:00:00 PM: 7483 3rd Qu.:0 3rd Qu.: 0.0000 E : 20047 CENTRAL PORTION: 617 3rd Qu.: 0.0000 3rd Qu.: 0.000 3rd Qu.:1.0 3rd Qu.: 75.0 3rd Qu.: 0.0000 3rd Qu.: 0.0000 3rd Qu.: 0.50 B : 40 3rd Qu.: 0.000 0 : 19 PHI : 12551 KANSAS, Southwest : 11212 JEFFERSON - JEFFERSON : 303 3rd Qu.:4019 3rd Qu.: 9605 3rd Qu.:3549 3rd Qu.: 8735 Trees were downed. : 446 3rd Qu.:676723
6 Max. :95.0 4/2/2006 0:00:00 : 981 03:00:00 PM: 6700 HST : 2563 Max. :873.0 MADISON : 5632 NE : 30271 FLOOD : 25326 Max. :3749.000 NW : 24041 NORTH PORTION: 784 5/30/2004 0:00:00: 998 11:59:00 PM: 7184 Max. :0 Max. :925.0000 NE : 14606 SPRINGFIELD : 575 Max. :2315.0000 Max. :4400.000 Max. :5.0 Max. :22000.0 Max. :583.0000 Max. :1700.0000 Max. :5000.00 5 : 28 Max. :990.000 B : 9 TSA : 12483 GEORGIA, North and Central : 11120 MADISON - MADISON : 302 Max. :9706 Max. : 17124 Max. :9706 Max. :106220
Large trees and power lines were blown down.
432
Max. :902297
7 (Other) :895866 (Other) :857229 (Other): 3631 (Other) :862369 (Other):621339 (Other) :170878 (Other):134990 (Other) :591444 (Other) :653450 (Other) :622432 (Other): 72096 (Other) :380536 NA’s :843563 (Other): 84 (Other): 9 (Other):690738 (Other) :595920 (Other) :100444 NA’s :47 NA’s :40 (Other) :588294

Calculating the total damages and casualties for each event type

filterStormData$TotalDamage = filterStormData$PropertyDamage + filterStormData$CropDamage

filterStormData$TotalCasualty = as.numeric(filterStormData$FATALITIES) + as.numeric(filterStormData$INJURIES)

OrderedEventByCasualties <- as.data.frame.table(sort(tapply(filterStormData$TotalCasualty, filterStormData$EVTYPE, sum)))
OrderedEventByDamages <- as.data.frame.table(sort(tapply(filterStormData$TotalDamage, filterStormData$EVTYPE, sum)))

Results

Data Analysis

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

##Get the  Top 20 Events by Casualities
OrderedEventByCasualties <-tail (OrderedEventByCasualties,n=20)
colnames(OrderedEventByCasualties) = c("EventType", "TotalCasualties")
p1 = ggplot(data=OrderedEventByCasualties, aes(x=EventType, y=TotalCasualties)) +
  theme(plot.margin=unit(c(1,1,-0.2,.91), "cm")) +
  geom_bar(stat="identity") +
  labs(x="", y="# People Killed/Injured")
p2 = p1 + scale_y_log10() +
  theme(plot.margin=unit(c(-0.2,1,1,1), "cm")) +
  theme(axis.text.x = element_text(angle = 60, hjust = 1)) +
  labs(y=expression(paste("(", log[10], ")"))) +
  xlab("Weather Events")
p1 = p1 + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
grid.arrange(p1, p2, nrow=2, main="Top 20 Harmful Event Types")

From the graph , we can see that TORNADO is the most harmful with respect to the population health.

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

##Get Top 20 Events by Damages

OrderedEventByDamages <-tail (OrderedEventByDamages,n=20)
colnames(OrderedEventByDamages) = c("EventType", "TotalDamages")
OrderedEventByDamages$TotalDamages <- OrderedEventByDamages$TotalDamages / 10^9

p3 = ggplot(data=OrderedEventByDamages, aes(x=EventType, y=TotalDamages)) +
  theme(plot.margin=unit(c(1,1,-0.2,.91), "cm")) +
  geom_bar(stat="identity") +
  labs(x="", y="Cost of Prop/Crop Damages (in Bilions)")
p4 = p3 + scale_y_log10() +
  theme(plot.margin=unit(c(-0.2,1,1,1), "cm")) +
  theme(axis.text.x = element_text(angle = 60, hjust = 1)) +
  labs(y=expression(paste("(", log[10], ")"))) +
  xlab("Weather Events")
p3 = p3 + theme(axis.text.x = element_blank(), axis.ticks.x = element_blank())
grid.arrange(p3, p4, nrow=2, main="Top 20 Costly Event Types")
## Warning: Stacking not well defined when ymin != 0

From the graph , we can see that FLOOD have the greatest economic consequences.

3.Looking further, we can analyze the impact with respect to both Casualties and Damages

#Filter down to the Top 10 of each category
top10Casualties = tail(sort(tapply(filterStormData$TotalCasualty, filterStormData$EVTYPE, sum)), n = 10)
top10Damages = tail(sort(tapply(filterStormData$TotalDamage, filterStormData$EVTYPE, sum)), n = 10)
#Mash the top 10 of each and get the unique events
impactfulEvTypes = unique(c(names(top10Casualties), names(top10Damages)))

#Plot scatter chart and label only those most impactful in terms of damages and casualties
impact = filterStormData %>% 
  group_by(EVTYPE) %>%
  summarize(TotalDamages = sum(TotalDamage) / 10^9 , TotalCasualties = sum(TotalCasualty))
impact[!(impact$EVTYPE %in% impactfulEvTypes), "EVTYPE"] = ''
ggplot(impact) +
  aes(y=TotalCasualties, x=TotalDamages, label=EVTYPE) +
  geom_point() +
  ggtitle("Dangerous & Costly Event Types") +
  labs(y=expression(paste("No. of People Killed/Injured")),
       x=expression(paste("Property/Crop damage (in Billions)"))) +
  geom_text(angle=45, vjust=0, hjust=0, size=3) +
  ylim(0, 25000)

Conclusion

In the graph above, we can see that the most severe event is either most costly in terms of damages or most damaging to the population in terms of casualties but not both at the same time.

Recommendations

For events that results in more casualities, i.e. Tornados; more medical resources should prepared for that and for events that results in more monetary damages, i.e. floods ; more humanitarian resources such as tents , foods, etc… should be prepared for that.