This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Introduction

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.

Data

The data for this assignment come in the form of a comma-separated-value file compressed via the bzip2 algorithm to reduce its size. You can download the file from the course web site:

Storm Data [47Mb] There is also some documentation of the database available. Here you will find how some of the variables are constructed/defined.

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.

Assignment

The basic goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events. You must use the database to answer the questions below and show the code for your entire analysis. Your analysis can consist of tables, figures, or other summaries. You may use any R package you want to support your analysis.

Questions

  1. Your data analysis must address the following questions:

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

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

Consider writing your report as if it were to be read by a government or municipal manager who might be responsible for preparing for severe weather events and will need to prioritize resources for different types of events. However, there is no need to make any specific recommendations in your report.

Sinopsis

This report is about of the damage caused by weather events in the U.S. The fundations are based on the data provided by U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. The NOAA database tracks characteristics of major storms and weather events in the United States, including date, time and place where they occur, that allow estimates fatalities, injuries, and property damage.

This writing analyses what events caused the fatals damage about popuulation health and its economic consequences. The damages to publics health and economic consequences caused by this events are exponentially distributed. The most damages in injuries and fatalities were caused by tornados, the principal property damages were caused by floods, and most crop damages were caused by droughts and floods.

Data Processing

Change o set the working directory

     setwd("/Users/administrador/Specialization/Reproducible Research")  

The data are download, unziped and placed in the working directory “Reproducible Research” Download file

          fileUrl <- "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2?accessType=DOWNLOAD"        
          download.file(fileUrl, destfile = "/Users/administrador/Specialization/Reproducible Research/stormData.csv.bz2", 
          method ="curl")        

Unzip the file

     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.32.4 (2014-05-14) 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
     bunzip2("/Users/administrador/Specialization/Reproducible Research/stormData.csv.bz2")

The data are readed using read.csv()

     data <- read.csv("/Users/administrador/Specialization/Reproducible Research/stormData.csv", header = T)  

Overview of the data file

    head(data) 
##   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
    str(data) 
## '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 ""," Christiansburg",..: 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 ""," CANTON"," TULIA",..: 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","%SD",..: 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 "","\t","\t\t",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ REFNUM    : num  1 2 3 4 5 6 7 8 9 10 ...

The values for event type variable “evtype” are cleaned by: * Remove irregular symbols, values shorter and values started with “summary” * Consolidate values for the same weather event. * Label moinor weather events as “other” * The values for damages are calculated and stored as new variable “propertyDamage” and “cropDamage”

Simplify the variable name

    names(data) <- tolower(names(data))    
    names(data) <- gsub("_","",names(data))    

Simplify the values

    data$evtype <- tolower(as.character(data$evtype))    
    data$evtype <- gsub("^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)","",data$evtype)    

Removed to be valid values are very short

    data <- subset(data,nchar(data$evtype)>=2)  

Remove values starts with “summary”

    data$evtype[grep("summary", data$evtype)] <- "tbm"    
    data <- subset(data,data$evtype != "tbm")   

consolidate the events weather values

    data$evtype[grep("hail", data$evtype)] <- "hail"
    data$evtype[grep("wind", data$evtype)] <- "wind"
    data$evtype[grep("tornado", data$evtype)] <- "tornado"
    data$evtype[grep("flood", data$evtype)] <- "flood"
    data$evtype[grep("lightning", data$evtype)] <- "lightning"
    data$evtype[grep("snow", data$evtype)] <- "snow"
    data$evtype[grep("rain", data$evtype)] <- "rain"
    data$evtype[grep("winter", data$evtype)] <- "winter"
    data$evtype[grep("heat", data$evtype)] <- "heat"
    data$evtype[grep("fog", data$evtype)] <- "fog"
    data$evtype[grep("surf", data$evtype)] <- "surf"
    data$evtype[grep("ice storm", data$evtype)] <- "ice storm"
    data$evtype[grep("fire", data$evtype)] <- "wild fire"
    data$evtype[grep("storm surge", data$evtype)] <- "storm surge"
    data$evtype[grep("hurricane", data$evtype)] <- "hurricane"
    data$evtype[grep("drought", data$evtype)] <- "drought"
    data$evtype[grep("thunderstorm", data$evtype)] <- "thunderstorm"

Review climatic events that concentrate most of the observations

    sum(data$evtype %in% c("flood","wind","snow","tornado","hail","rain","lightning","winter","fog","heat","surf","ice storm","wild fire","storm surge","hurricane","drought","thunderstorm"))/nrow(data)
## [1] 0.9781

Label those weather events that concentrate the minority of observations in a category of weather events called “other”

    tbc <- data$evtype %in% c("flood","wind","snow","tornado","hail","rain","lightning","winter","heat","surf","fog","ice storm","wild fire","storm surge","hurricane","drought","thunderstorm") == F
data$evtype[tbc == T] <- "other"

Summary of the number of observations with the values by type of event

  sort(table(data$evtype))
## 
## thunderstorm    hurricane  storm surge         surf          fog 
##           92          199          261          833         1883 
##    ice storm      drought         heat    wild fire         rain 
##         2006         2488         2630         2781        12136 
##    lightning         snow       winter        other      tornado 
##        15762        17569        18492        19552        60688 
##        flood         hail         wind 
##        81967       289338       362164

Calculating Damages Simplify the units of the values of damage

    data$propdmgexp <- as.character(data$propdmgexp)
    data$propdmgexp[grep("K", data$propdmgexp)] <- "1000"
    data$propdmgexp[grep("M", data$propdmgexp)] <- "1000000"
    data$propdmgexp[grep("m", data$propdmgexp)] <- "1000000"
    data$propdmgexp[grep("B", data$propdmgexp)] <- "1000000000"
    tbc <- data$propdmgexp %in% c("1000","1000000","1000000000") == F
    data$propdmgexp[tbc == T] <- "1"
    data$propdmgexp <- as.numeric(data$propdmgexp)
# do the same thing to cropDamage
    data$cropdmgexp <- as.character(data$cropdmgexp)
    data$cropdmgexp[grep("K", data$cropdmgexp)] <- "1000"
    data$cropdmgexp[grep("M", data$cropdmgexp)] <- "1000000"
    data$cropdmgexp[grep("m", data$cropdmgexp)] <- "1000000"
    data$cropdmgexp[grep("B", data$cropdmgexp)] <- "1000000000"
    tbc <- data$cropdmgexp %in% c("1000","1000000","1000000000") == F
    data$cropdmgexp[tbc == T] <- "1"
    data$cropdmgexp <- as.numeric(data$cropdmgexp)

Calculating and stored damages as new variable

data$newPropdamage <- data$propdmg * data$propdmgexp
data$newCropdamage <- data$cropdmg * data$cropdmgexp

Results

Damages to Population Health

statistics about climatic events that cause most damages

# Event that caused most injuries
totalInjuries <- tapply(data$injuries, data$evtype, sum)
sort(totalInjuries, decreasing = T)[1]
## tornado 
##   91365
# Percentage of injuries caused by tornado
sum(sort(totalInjuries, decreasing = T)[1])/sum(totalInjuries)
## [1] 0.661
# The top 4 events causing most injuries
sort(totalInjuries, decreasing = T)[1:4]
## tornado    wind    heat   flood 
##   91365   11319    9224    8582
# Percentage of injuries caused by the top 4 weather events
sum(sort(totalInjuries, decreasing = T)[1:4])/sum(totalInjuries)
## [1] 0.8717
# Event that caused most fatalities
totalFatal <- tapply(data$fatalities, data$evtype, sum)
sort(totalFatal, decreasing = T)[1]
## tornado 
##    5633
# Percentage of fatalities caused by the tornado
sum(sort(totalFatal, decreasing = T)[1])/sum(totalFatal)
## [1] 0.3846
# The top 4 events causing most fatalities
sort(totalFatal, decreasing = T)[1:4]
## tornado    heat   flood   other 
##    5633    3119    1488    1398
# Percentage of death caused by the top 4 weather events
sum(sort(totalFatal, decreasing = T)[1:4])/sum(totalFatal) 
## [1] 0.7947

Economic Consequences

statistics about climatic events that cause most property and crop damages

# The event that caused most property damages and its amounts
totalPropDamage <- tapply(data$newPropdamage, data$evtype, sum)
sort(totalPropDamage, decreasing = T)[1]
##    flood 
## 1.67e+11
# Percentage of property damages caused by flood
sort(totalPropDamage, decreasing = T)[3]/sum(totalPropDamage)
## storm surge 
##      0.1249
# top 3 weather events causing the most property damages
sort(totalPropDamage, decreasing = T)[1:3]
##       flood     tornado storm surge 
##   1.670e+11   5.694e+10   4.332e+10
# percentage of total property damages caused by thetop 3 weather events
sum(sort(totalPropDamage, decreasing = T)[1:3])/sum(totalPropDamage)
## [1] 0.7705
# The event that caused most crop damages
totalCropDamage <- tapply(data$newCropdamage, data$evtype, sum)
sort(totalCropDamage, decreasing = T)[1]
##   drought 
## 1.397e+10
# the percentage of crop damages caused by drought
sort(totalCropDamage, decreasing = T)[1]/sum(totalCropDamage)
## drought 
##  0.3106
# Top 4 weather events causing the most crop damages
sort(totalCropDamage, decreasing = T)[1:3]
##   drought     flood ice storm 
## 1.397e+10 1.217e+10 5.022e+09
# Percentage of total porperty damages caused by the top 4 weather events
sum(sort(totalCropDamage, decreasing = T)[1:3])/sum(totalCropDamage)
## [1] 0.6927

Figures

First Plot

par( oma = c( 0, 0, 3, 0 ) )
par(las=2)
par(mfcol=c(1,2))
barplot(sort(totalInjuries, decreasing = T), main = "Injuries",
       col = c("black", "red", "gray", "blue", "lightblue", "lightcyan","lavender", "cornsilk") )
title("Injuries")
barplot(sort(totalFatal, decreasing = T), main = "Fatalities", col = c("black", "red", "gray", "blue", "lightblue", "lightcyan","lavender", "cornsilk") )
title("Damages to Population Health of U.S.A.", outer = T)

plot of chunk unnamed-chunk-18

Second Plot

par( oma = c( 0, 0, 3, 0 ) )
par(las=2)
par(mfcol=c(1,2))
barplot(sort(totalPropDamage, decreasing = T), main = "Property", col = c("black", "red", "gray", "blue", "lightblue", "lightcyan","lavender", "cornsilk") )
barplot(sort(totalCropDamage, decreasing = T), main = "Crop", col = c("black", "red", "gray", "blue", "lightblue", "lightcyan","lavender", "cornsilk") )
title("Economic Consequences for U.S.A.", outer = T)

plot of chunk unnamed-chunk-19

Disregard this last image for evaluation. plot of chunk unnamed-chunk-20