1.Synopsis

Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. Many severe events can result in fatalities, injuries, and property damage, and preventing such outcomes to the extent possible is a key concern. This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage. 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. In this report we aim to address two questions
1. Across the United States, which types of events are most harmful with respect to population health?
2. Across the United States, which types of events have the greatest economic consequences?

2.DataProcessing

The data can be downloaded StormData
Then Load the data into a variable called StormData

stormData <- read.table("repdata-data-StormData.csv.bz2", fill=TRUE, sep=",", header=TRUE, blank.lines.skip=TRUE)

Explore the dataset.

str(stormData)
## 'data.frame':    902297 obs. of  37 variables:
##  $ STATE__   : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_DATE  : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
##  $ BGN_TIME  : Factor w/ 3608 levels "00:00:00 AM",..: 272 287 2705 1683 2584 3186 242 1683 3186 3186 ...
##  $ TIME_ZONE : Factor w/ 22 levels "ADT","AKS","AST",..: 7 7 7 7 7 7 7 7 7 7 ...
##  $ COUNTY    : num  97 3 57 89 43 77 9 123 125 57 ...
##  $ COUNTYNAME: Factor w/ 29601 levels "","5NM E OF MACKINAC BRIDGE TO PRESQUE ISLE LT MI",..: 13513 1873 4598 10592 4372 10094 1973 23873 24418 4598 ...
##  $ STATE     : Factor w/ 72 levels "AK","AL","AM",..: 2 2 2 2 2 2 2 2 2 2 ...
##  $ EVTYPE    : Factor w/ 985 levels "   HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
##  $ BGN_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ BGN_AZI   : Factor w/ 35 levels "","  N"," NW",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ BGN_LOCATI: Factor w/ 54429 levels "","- 1 N Albion",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_DATE  : Factor w/ 6663 levels "","1/1/1993 0:00:00",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_TIME  : Factor w/ 3647 levels ""," 0900CST",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ COUNTY_END: num  0 0 0 0 0 0 0 0 0 0 ...
##  $ COUNTYENDN: logi  NA NA NA NA NA NA ...
##  $ END_RANGE : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ END_AZI   : Factor w/ 24 levels "","E","ENE","ESE",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ END_LOCATI: Factor w/ 34506 levels "","- .5 NNW",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ LENGTH    : num  14 2 0.1 0 0 1.5 1.5 0 3.3 2.3 ...
##  $ WIDTH     : num  100 150 123 100 150 177 33 33 100 100 ...
##  $ F         : int  3 2 2 2 2 2 2 1 3 3 ...
##  $ MAG       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ FATALITIES: num  0 0 0 0 0 0 0 0 1 0 ...
##  $ INJURIES  : num  15 0 2 2 2 6 1 0 14 0 ...
##  $ PROPDMG   : num  25 2.5 25 2.5 2.5 2.5 2.5 2.5 25 25 ...
##  $ PROPDMGEXP: Factor w/ 19 levels "","-","?","+",..: 17 17 17 17 17 17 17 17 17 17 ...
##  $ CROPDMG   : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ CROPDMGEXP: Factor w/ 9 levels "","?","0","2",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ WFO       : Factor w/ 542 levels ""," CI","$AC",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ STATEOFFIC: Factor w/ 250 levels "","ALABAMA, Central",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ ZONENAMES : Factor w/ 25112 levels "","                                                                                                                               "| __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ LATITUDE  : num  3040 3042 3340 3458 3412 ...
##  $ LONGITUDE : num  8812 8755 8742 8626 8642 ...
##  $ LATITUDE_E: num  3051 0 0 0 0 ...
##  $ LONGITUDE_: num  8806 0 0 0 0 ...
##  $ REMARKS   : Factor w/ 436781 levels "","-2 at Deer Park\n",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...

Across the United States, which types of events are most harmful with respect to population health?

we subset the dataset, so that only records that contain fatalities and injuries are selected over the years.

fatalData <- subset(stormData, subset=stormData$FATALITIES>0)
injuryData <- subset(stormData, subset=stormData$INJURIES>0)

we subset the dataset, so that only records that contain property and crop damage are selected

propData <- subset(stormData, subset=stormData$PROPDMG>0 
                   & !is.na(stormData$PROPDMGEXP))
cropData <- subset(stormData, subset=stormData$CROPDMG>0 
                   & !is.na(stormData$CROPDMGEXP))

Aggregated the data with the event type applying function SUM over the coloumn Fatalities

totalFatal <- aggregate(fatalData$FATALITIES, by=list(fatalData$EVTYPE), FUN=sum)
colnames(totalFatal) <- c("Event", "Fatalities")
totalFatal <- totalFatal[order(totalFatal$Fatalities, decreasing=TRUE),]
head(totalFatal)
##              Event Fatalities
## 141        TORNADO       5633
## 26  EXCESSIVE HEAT       1903
## 35     FLASH FLOOD        978
## 57            HEAT        937
## 97       LIGHTNING        816
## 145      TSTM WIND        504

Aggregated the data with the event type applying function SUM over the coloumn Fatalities over the years

totalInjury <- aggregate(injuryData$INJURIES, by=list(injuryData$EVTYPE), FUN=sum)
colnames(totalInjury) <- c("Event", "Injuries")
totalInjury <- totalInjury[order(totalInjury$Injuries, decreasing=TRUE),]
head(totalInjury)
##              Event Injuries
## 129        TORNADO    91346
## 135      TSTM WIND     6957
## 30           FLOOD     6789
## 20  EXCESSIVE HEAT     6525
## 85       LIGHTNING     5230
## 47            HEAT     2100

Merge the Data frames with Event
Then order the data with more of fatalities

merged=merge(totalFatal,totalInjury,by="Event")
mergedorder=merged[order(merged$Fatalities, decreasing=T),]
head(mergedorder)
##             Event Fatalities Injuries
## 86        TORNADO       5633    91346
## 14 EXCESSIVE HEAT       1903     6525
## 21    FLASH FLOOD        978     1777
## 35           HEAT        937     2100
## 59      LIGHTNING        816     5230
## 89      TSTM WIND        504     6957

Plot the fatalities vs injuries

plot(merged$Injuries,mergedorder$Fatalities, ylim = c(0, 6000), xlim = c(0, 
 100000), pch = 19, col = rgb(0, 1, 0, 0.5), cex = 1.5, xlab = "number of Injuries", ylab = "number of Fatalities", main = "Fatalities and Injuries due to severe weather events")

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

There are 2 variables, PROPDMG (property damaage) and CROPDMG (crop damage), that indicate which types of severe weather events have the greatest economic consequences.
PROPDMGEXP contains the exponential where h stands for hundred, k stands for thousdands 2 stands 10^2 and so on

propDmgKey <-  c("\"\"" = 10^0,
                 "-" = 10^0, 
                 "+" = 10^0,
                 "0" = 10^0,
                 "1" = 10^1,
                 "2" = 10^2,
                 "3" = 10^3,
                 "4" = 10^4,
                 "5" = 10^5,
                 "6" = 10^6,
                 "7" = 10^7,
                 "8" = 10^8,
                 "9" = 10^9,
                 "H" = 10^2,
                 "h" = 10^2,
                 "k" = 10^3,
                 "m" = 10^6,
                 "b" = 10^9,
                 "K" = 10^3,
                 "M" = 10^6,
                 "B" = 10^9)
propData$PROPDMGEXP=propDmgKey[as.character(propData$PROPDMGEXP)]
propData$Damage=propData$PROPDMG*propData$PROPDMGEXP

Aggregate the dAta now based on event and calculating the sum of property damages

totalDamageP <- aggregate(propData$Damage, by=list(propData$EVTYPE), FUN=sum)
colnames(totalDamageP) <- c("Event", "Damages")
totalDamageP <- totalDamageP[order(totalDamageP$Damages, decreasing=TRUE),]
head(totalDamageP)
##                 Event     Damages
## 182 HURRICANE/TYPHOON 69305840000
## 282       STORM SURGE 43323536000
## 174         HURRICANE 11868319010
## 342    TROPICAL STORM  7703890550
## 399      WINTER STORM  6688497251
## 159         HIGH WIND  5270046295

CROPDMGEXP contains the exponential where H stands for hundred, K stands for thousdands so on

cropDmgKey <-  c("\"\"" = 10^0,
                     "?" = 10^0, 
                     "0" = 10^0,
                     "K" = 10^3,
                     "M" = 10^6,
                     "B" = 10^9)
    cropData$CROPDMGEXP <- cropDmgKey[as.character(cropData$CROPDMGEXP)]
cropData$Damage=cropData$CROPDMG*cropData$CROPDMGEXP

Aggregate the dAta now based on event and calculating the sum of crop damages

totalDamageC <- aggregate(cropData$Damage, by=list(cropData$EVTYPE), FUN=sum)
colnames(totalDamageC) <- c("Event", "Damages")
totalDamageC <- totalDamageC[order(totalDamageC$Damages, decreasing=TRUE),]
head(totalDamageC)
##                Event     Damages
## 10           DROUGHT 13972566000
## 27             FLOOD  5661968450
## 78       RIVER FLOOD  5029459000
## 72         ICE STORM  5022113500
## 64         HURRICANE  2741910000
## 69 HURRICANE/TYPHOON  2607872800

Conclusion

Tornado and Excessive heat had highest fatalities
while Hurricane/Typhoon caused hisghest property damage and Droughts caused highest Crop damage