Weather Event Damage Analysis

Synopsis

Based on NOAA data from 1950 to 2011, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health and which types of events have the greatest economic consequences?

Data Processing

Loading the data

Data was read in using read.csv. Only columns of interest were loaded, nameley event type, fatalities,injuries,property damage, property damage order of magnitude,crop damage and crop damage order of magnitude.

#Load data from csv
noaa<-read.csv('repdata-data-StormData.csv')[,c(8,23:28)]

Processing

A function was used to map character representations of order of magnitude to scientific notation. Data is then aggregated and sorted on columns of interest. The top 10 for each of health (as measured by total fatalities and injuries) and economic (as measured in total dollars of damage) impact were selected for the final output.

library(plyr)
#Function for converting dollar codes (k,M,B) into numeric dollar values
code.to.dollars<-function(d.value,multiplier){
    m.value<-numeric()
    switch(multiplier,
           "B"={m.value<-10^9},
           "M"={m.value<-10^6},
           "m"={m.value<-10^6},
           "k"={m.value<-10^3},
           "K"={m.value<-10^3},
           "NONE"={m.value<-1},
           "+"={m.value<-1},
           "-"={m.value<-1},
           "?"={m.value<-1},
           "0"={m.value<-1},
           "1"={m.value<-10^1},
           "2"={m.value<-10^2},
           "3"={m.value<-10^3},
           "4"={m.value<-10^4},
           "5"={m.value<-10^5},
           "6"={m.value<-10^6},
           "7"={m.value<-10^7},
           "8"={m.value<-10^8},
           "?"={m.value<-1},
           "h"={m.value<-10^2},
           "H"={m.value<-10^2},
           stop
    )
    if(is.na(d.value))d.value<-0
    if(is.na(m.value))m.value<-0
     ret.val<-as.numeric(d.value)*as.numeric(m.value)
    ret.val
}
#Aggregate  by fatalities and injuries
health.effects<-noaa$FATALITIES+noaa$INJURIES
noaa<-cbind(health.effects,noaa)
health.total<-aggregate.data.frame(noaa$health.effects,FUN=sum,by=list(noaa$EVTYPE))
health.total<-head(arrange(health.total,desc(x)),10)

#Aggregate by economic impact
#Set column class to character for event type and damage exponents
noaa[,c(2,6,8)] = apply(noaa[,c(2,6,8)], 2, function(x) as.character(x))
noaa[,c(3,4,5,7)] = apply(noaa[,c(3,4,5,7)], 2, function(x) as.numeric(x))
#When no exponent is given use character string NONE
noaa[which(noaa$CROPDMGEXP==""),8]<-'NONE'
noaa[which(noaa$PROPDMGEXP==""),6]<-'NONE'
total.damage<-numeric()
for(i in 1:nrow(noaa)){
    prop.damage<-code.to.dollars(noaa[i,5],noaa[i,6])
    crop.damage<-code.to.dollars(noaa[i,7],noaa[i,8])
    total.damage[i]<-prop.damage+crop.damage
    }
noaa<-cbind(total.damage,noaa)
damage.total<-aggregate.data.frame(noaa$total.damage,FUN=sum,by=list(noaa$EVTYPE))
damage.total<-head(arrange(damage.total,desc(x)),10)

Results

Health Effects

The total fatalities and injuries were combined as a sum total of health effects during processing. Tornado events had the largest effect as a matter of public health by a large margin.

#Add extra space below barplot
par(mar=c(15,3,1,1))
#plot total fatalities and injuries
barplot(health.total$x,names=as.character(health.total$Group.1),las=3,
        main="Total Fatalities and Injuries by Event")

plot of chunk unnamed-chunk-3

Economic Effects

Property and crop damage in dollars were combined as a sum total of economic data. Flood events had the largest economic impact.

#Add extra space below barplot
par(mar=c(15,3,1,1))
#plot total fatalities and injuries
barplot((damage.total$x/10^9),names=as.character(damage.total$Group.1),las=3,
        main="Economic Impact by Event in Billions of Dollars")

plot of chunk unnamed-chunk-4