SYNOPSIS:This project involves using the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database to evaluate tthe impact of extreme weather events on life and property. We seek to answer two mains questions, firstly the weather event most detrimental to human health. The second question seeks to identify weather evens that cause maximum economic damage. Human health in this case is expressed in term of fatalities and injuries. Economic damage is defined in ter of property and crop damage.

DATA PROCESSING: I read in the csv using the read.csv of the base package. I convert column names to lower case for convinience (R is case sensitive). Then I check if some of the requiste columns that I wish to use in Q1 are present or not.

setwd("C:\\Users\\Minerva\\Desktop\\PA2")

storm=read.csv("repdata-data-StormData.csv")
attach(storm)
## The following object is masked from package:base:
## 
##     F
head(storm)
##   STATE__           BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1       1  4/18/1950 0:00:00     0130       CST     97     MOBILE    AL
## 2       1  4/18/1950 0:00:00     0145       CST      3    BALDWIN    AL
## 3       1  2/20/1951 0:00:00     1600       CST     57    FAYETTE    AL
## 4       1   6/8/1951 0:00:00     0900       CST     89    MADISON    AL
## 5       1 11/15/1951 0:00:00     1500       CST     43    CULLMAN    AL
## 6       1 11/15/1951 0:00:00     2000       CST     77 LAUDERDALE    AL
##    EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1 TORNADO         0                                               0
## 2 TORNADO         0                                               0
## 3 TORNADO         0                                               0
## 4 TORNADO         0                                               0
## 5 TORNADO         0                                               0
## 6 TORNADO         0                                               0
##   COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1         NA         0                      14.0   100 3   0          0
## 2         NA         0                       2.0   150 2   0          0
## 3         NA         0                       0.1   123 2   0          0
## 4         NA         0                       0.0   100 2   0          0
## 5         NA         0                       0.0   150 2   0          0
## 6         NA         0                       1.5   177 2   0          0
##   INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1       15    25.0          K       0                                    
## 2        0     2.5          K       0                                    
## 3        2    25.0          K       0                                    
## 4        2     2.5          K       0                                    
## 5        2     2.5          K       0                                    
## 6        6     2.5          K       0                                    
##   LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1     3040      8812       3051       8806              1
## 2     3042      8755          0          0              2
## 3     3340      8742          0          0              3
## 4     3458      8626          0          0              4
## 5     3412      8642          0          0              5
## 6     3450      8748          0          0              6
colnames(storm) <- tolower(colnames(storm))
names(storm)
##  [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"
#check if there is column for fatalities and injuries
"fatalities" %in% names(storm)
## [1] TRUE
"injuries" %in% names(storm)
## [1] TRUE

RESULT: Code+Graphs

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

population health is encapsulated in terms of injuries and fatalities

##Fatalities and Injuries wrt Event

fat=aggregate(storm$fatalities, list(event = storm$evtype), sum)
##aggregate fatalities by event type
colnames(fat)[2]<-"fatalities"

inj=aggregate(storm$injuries, list(event = storm$evtype), sum)
##aggregate fatalities by event type
colnames(inj)[2]<-"injuries"

head(inj)
##                   event injuries
## 1    HIGH SURF ADVISORY        0
## 2         COASTAL FLOOD        0
## 3           FLASH FLOOD        0
## 4             LIGHTNING        0
## 5             TSTM WIND        0
## 6       TSTM WIND (G45)        0
##create a data frame of events and corresponding fatalities and injuries
comb=cbind(fat,inj[,2])
colnames(comb)[3]<-"injuries"

fat_dec = comb[order(comb$fatalities, decreasing = TRUE), ]


inj_dec <- comb[order(comb$injuries, decreasing = TRUE), ]

require(ggplot2)
## Loading required package: ggplot2
#
##fatalities
ggplot(fat_dec[1:10, ], aes(event, fatalities)) + geom_bar(stat = "identity", aes(color = event), size = 3, alpha = 0.2) + ylab("Number of Deaths") + xlab("Event Type") + ggtitle("Top 10 Events Causing Fatalities")

#injuries
ggplot(inj_dec[1:10, ], aes(event, injuries)) + geom_bar(stat = "identity", aes(color = event), size = 3, alpha = 0.2) + ylab("Number of Deaths") + xlab("Event Type") + ggtitle("Top 10 Events Causing Injuries")

Q2) Across the United States, which types of events have the greatest economic consequences? I focus on property and crop damage

property <- aggregate(storm$propdmg,list(event = storm$evtype),sum)
colnames(property) <- c("evtype", "propdmg")
property <- property[order(property$propdmg, decreasing = TRUE), ]


crop <- aggregate(storm$cropdmg ~ storm$evtype, data = storm, FUN = sum)
colnames(crop) <- c("evtype", "cropdmg")
crop <- crop[order(crop$cropdmg, decreasing = TRUE), ]



ggplot(property[1:5, ], aes(evtype, propdmg)) + geom_bar(stat = "identity", aes(color = evtype), size = 2, alpha = 0.1) + ylab("Damages in million dollars") + xlab("Event Type") + ggtitle("Top 5 Events Responsible for Property Damages")

#ggplot(crop[1:5, ], aes(evtype, cropdmg)) + geom_bar(stat = "identity", aes(color = evtype), size = 3, alpha = 0.2) + ylab("Damages in million dollars") + xlab("Event Type") + ggtitle("Top 5 Events Responsible for Crop Damages")