The main goal of this report is to analyze the United States National Oceanic and Atmospheric Adminstration’s (NOAA) storm database, which tracks major storm and severe weather events, to address the following questions:
Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
It is observed that high temperatures and tornado are most harmful with respect to population health, while flood, drought, and hurricane/typhoon have the greatest impacts on economy.
Download the file from internet
if(!file.exists('StormData.csv.bz2')){
download.file("http://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2",
destfile='StormData.csv.bz2')
}
Loading Libraries
library(R.utils)
library(plyr)
library(dplyr)
library(ggplot2)
library(graphics)
Uncompress the file and read the CSV file into a data file
if(file.exists('StormData.csv.bz2')){
storm <- read.csv(bzfile('StormData.csv.bz2'), header = TRUE)
}
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/ 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 ...
fatal <- FieldTops(storm$FATALITIES,10,storm)
names(fatal) <- c("EVTYPE","FATALITIES")
fatal
## EVTYPE FATALITIES
## 834 TORNADO 5633
## 130 EXCESSIVE HEAT 1903
## 153 FLASH FLOOD 978
## 275 HEAT 937
## 464 LIGHTNING 816
## 856 TSTM WIND 504
## 170 FLOOD 470
## 585 RIP CURRENT 368
## 359 HIGH WIND 248
## 19 AVALANCHE 224
injury <- FieldTops(storm$INJURIES,10,storm)
names(injury) <- c("EVTYPE","INJURIES")
injury
## EVTYPE INJURIES
## 834 TORNADO 91346
## 856 TSTM WIND 6957
## 170 FLOOD 6789
## 130 EXCESSIVE HEAT 6525
## 464 LIGHTNING 5230
## 275 HEAT 2100
## 427 ICE STORM 1975
## 153 FLASH FLOOD 1777
## 760 THUNDERSTORM WIND 1488
## 244 HAIL 1361
Property and Crop damages impact the US economy. PROPDMGEXP and CROPDMGEXP are factor variables, has to be converted into comparable numerical forms using the definition of the units described in the Code Book.
unique(storm$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 M
storm$PROPDMGEXP <- as.character(storm$PROPDMGEXP)
storm$PROPDMGEXP = gsub("\\-|\\+|\\?","0",storm$PROPDMGEXP)
storm$PROPDMGEXP = gsub("B|b", "9", storm$PROPDMGEXP)
storm$PROPDMGEXP = gsub("M|m", "6", storm$PROPDMGEXP)
storm$PROPDMGEXP = gsub("K|k", "3", storm$PROPDMGEXP)
storm$PROPDMGEXP = gsub("H|h", "2", storm$PROPDMGEXP)
storm$PROPDMGEXP <- as.numeric(storm$PROPDMGEXP)
storm$PROPDMGEXP[is.na(storm$PROPDMGEXP)] = 0
storm$ACTPROPDMG <- storm$PROPDMG * 10^storm$PROPDMGEXP
propertydamage <- FieldTops(storm$ACTPROPDMG,10,storm)
names(propertydamage) <- c("EVTYPE","PROPERTYDAMAGE")
propertydamage
## EVTYPE PROPERTYDAMAGE
## 170 FLOOD 144657709807
## 411 HURRICANE/TYPHOON 69305840000
## 834 TORNADO 56947380677
## 670 STORM SURGE 43323536000
## 153 FLASH FLOOD 16822673979
## 244 HAIL 15735267513
## 402 HURRICANE 11868319010
## 848 TROPICAL STORM 7703890550
## 972 WINTER STORM 6688497251
## 359 HIGH WIND 5270046295
unique(storm$CROPDMGEXP)
## [1] M K m B ? 0 k 2
## Levels: ? 0 2 B k K m M
storm$CROPDMGEXP <- as.character(storm$CROPDMGEXP)
storm$CROPDMGEXP = gsub("\\-|\\+|\\?","0",storm$CROPDMGEXP)
storm$CROPDMGEXP = gsub("B|b", "9", storm$CROPDMGEXP)
storm$CROPDMGEXP = gsub("M|m", "6", storm$CROPDMGEXP)
storm$CROPDMGEXP = gsub("K|k", "3", storm$CROPDMGEXP)
storm$CROPDMGEXP = gsub("H|h", "2", storm$CROPDMGEXP)
storm$CROPDMGEXP <- as.numeric(storm$CROPDMGEXP)
storm$CROPDMGEXP[is.na(storm$CROPDMGEXP)] = 0
storm$ACTCROPDMG <- storm$CROPDMG * 10^storm$CROPDMGEXP
cropdamage <- FieldTops(storm$ACTCROPDMG,10,storm)
names(cropdamage) <- c("EVTYPE","CROPDAMAGE")
cropdamage
## EVTYPE CROPDAMAGE
## 95 DROUGHT 13972566000
## 170 FLOOD 5661968450
## 590 RIVER FLOOD 5029459000
## 427 ICE STORM 5022113500
## 244 HAIL 3025954473
## 402 HURRICANE 2741910000
## 411 HURRICANE/TYPHOON 2607872800
## 153 FLASH FLOOD 1421317100
## 140 EXTREME COLD 1292973000
## 212 FROST/FREEZE 1094086000
The following pair of plots show the top ten total fatalities and total injuries affected by severe weather events in the United States during 1950-2011.
par(mfrow = c(1,2), mar = c(12, 4, 3, 2), cex = 0.9, font = 2, las = 3)
barplot(fatal$FATALITIES, names.arg = fatal$EVTYPE,
main = "Top 10 Fatalities \n caused by severe weather",
ylab = "NUMBER OF FATALITIES", col = "blue")
barplot(injury$INJURIES, names.arg = injury$EVTYPE,
main = "Top 10 Injuries \n caused by severe weather",
ylab = "NUMBER OF INJURIES", col = "blue")
It is evident that TORNADO causes most fatalities and injuries in the United States. TORNADO is the most harmful event with respect to population health.
Top ten property and crop damages in billions ($) are plotted below. Interms of economic consequences, the following plot shows that flood and hurricane/typhoon caused most property damage, whereas, drought and flood are the reasons for crop damage.
par(mfrow = c(1,2), mar = c(12, 4, 3, 2), cex = 0.9, font = 2, las = 3)
barplot(propertydamage$PROPERTYDAMAGE/(10^9), names.arg = propertydamage$EVTYPE,
main = "Top 10 Property Damages \n caused by severe weather",
ylab = "PROPERTY DAMAGES IN BILLIONS ($)", col = "green")
barplot(cropdamage$CROPDAMAGE/(10^9), names.arg = cropdamage$EVTYPE,
main = "Top 10 Crop Damages \n caused by severe weather",
ylab = "CROP DAMAGES IN BILLIONS ($)", col = "green")