Sypnosis
Storms and other severe weather events have the potential to cause injuries or more severe outcomes to people, as well as a significant effect on livestock, crops and economic infraestructure. It can disrupt the normal lives of communities and impact from small to vast regions all accross the country. 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.
library("lubridate")
library("plyr")## 
## Attaching package: 'plyr'## The following object is masked from 'package:lubridate':
## 
##     herelibrary("dplyr")## 
## Attaching package: 'dplyr'## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize## The following objects are masked from 'package:lubridate':
## 
##     intersect, setdiff, union## The following objects are masked from 'package:stats':
## 
##     filter, lag## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, unionlibrary("ggplot2")
library("lattice")
library("data.table")## 
## Attaching package: 'data.table'## The following objects are masked from 'package:dplyr':
## 
##     between, last## The following objects are masked from 'package:lubridate':
## 
##     hour, mday, month, quarter, wday, week, yday, yearlibrary("knitr")
library("rmarkdown")
library("markdown")Data processing:
As of March 2016, the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database is located at the following URL:
https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2
Data was downloaded ad extracted into a local direcotory. The steps taken after teh download process are described next.
setwd("~/R/RR week 4")
storm<- read.csv(file="repdata-data-StormData.csv", header=TRUE, sep=",")
str(storm)## '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/ 436774 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 ...storm_r is a reduced dataset, (a sibset of fields derived from the original NOASS (storm data set)) retaining only the fields of interest:
storm_r <- storm[ , c("EVTYPE", "BGN_DATE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
str(storm_r)## 'data.frame':    902297 obs. of  8 variables:
##  $ EVTYPE    : Factor w/ 985 levels "   HIGH SURF ADVISORY",..: 834 834 834 834 834 834 834 834 834 834 ...
##  $ BGN_DATE  : Factor w/ 16335 levels "1/1/1966 0:00:00",..: 6523 6523 4242 11116 2224 2224 2260 383 3980 3980 ...
##  $ 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 ...understanding the structure fo the “EXP” fields
unique(storm_r$PROPDMGEXP)##  [1] K M   B m + 0 5 6 ? 4 2 3 h 7 H - 1 8
## Levels:  - ? + 0 1 2 3 4 5 6 7 8 B h H K m Munique(storm_r$CROPDMGEXP)## [1]   M K m B ? 0 k 2
## Levels:  ? 0 2 B k K m MTransforming damage (“DMG”) fields into values according to categories in “DMGEXP” fields and computing the total amounts of property damage.
mapvPROPDMG <- mapvalues(storm_r$PROPDMGEXP,
c("K","M","", "B","m","+","0","5","6","?","4","2","3","h","7","H","-","1","8"), 
c(1e3,1e6, 1, 1e9,1e6,  1,  1,1e5,1e6,  1,1e4,1e2,1e3,  1,1e7,1e2,  1, 10,1e8))
mapvCROPDMG <- mapvalues(storm_r$CROPDMGEXP,
c("","M","K","m","B","?","0","k","2"),
c( 1,1e6,1e3,1e6,1e9,  1,  1,1e3,1e2) )
storm_r$PROPTOTALDMG <- as.numeric(mapvPROPDMG) * storm_r$PROPDMG
storm_r$CROPTOTALDMG <- as.numeric(mapvCROPDMG) * storm_r$CROPDMG
storm_r$TOTALDMG <- storm_r$PROPTOTALDMG + storm_r$CROPTOTALDMGReduced data set is summarized by event type for the personal and material type of damage.
stormAgg <- ddply(storm_r, ~EVTYPE, summarise, FATALITIES = sum(FATALITIES),     INJURIES = sum(INJURIES), PROPDMG = sum(PROPTOTALDMG), CROPDMG = sum(CROPTOTALDMG), TOTALPDMG = sum(TOTALDMG))
fatal <- stormAgg[order(stormAgg$FATALITIES, decreasing = T), c("EVTYPE", 
    "FATALITIES")][1:12, ]
injur <- stormAgg[order(stormAgg$INJURIES, decreasing = T), c("EVTYPE", 
    "INJURIES")][1:12, ]
propdmg <- stormAgg[order(stormAgg$PROPDMG, decreasing = T), c("EVTYPE", 
    "PROPDMG")][1:12, ]
cropdmg <- stormAgg[order(stormAgg$CROPDMG, decreasing = T), c("EVTYPE", 
    "CROPDMG")][1:12, ]
totaldmg <- stormAgg[order(stormAgg$TOTALPDMG, decreasing = T), c("EVTYPE",     "TOTALPDMG")][1:12, ]First question: Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
ggplot(fatal, aes(x = EVTYPE, y = FATALITIES)) + 
    geom_bar(stat = "identity", fill = "blue" ) + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
    xlab("Event Type") + ylab("Fatalities") + 
    ggtitle("Number of fatalities by top 12 Weather Events")ggplot(injur, aes(x = EVTYPE, y = INJURIES)) + 
    geom_bar(stat = "identity", fill = "blue" ) + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
    xlab("Event Type") + ylab("Injuries") + 
    ggtitle("Number of Injuries  by top 12 Weather Events") Answer to question 1: The data indicates that tornados have the most impact on people health. Both fatalities and injuries are severily inpacted by this tyoe of event.
Question 2: Across the United States, which types of events have the greatest economic consequences?
ggplot(totaldmg, aes(x = EVTYPE, y = TOTALPDMG)) + 
    geom_bar(stat = "identity", fill = "blue" ) + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
    xlab("Event Type") + ylab("Economic Losses $") + 
    ggtitle("Economic Impact ($ losses) by top 12 Weather Events")For property and material damage, the type of event causing the largest amount of damages are tornados. No other category gets closer to the significant amount of damage caused by twisters.
Published: March 2016