This is the results report for Coursera Course, reproducible research, Peer Assignment 2. The goal of this assignment is to explore the NOAA storm Database, Storm Data, and answer some basic questions about severe weather events. The report has analyzed and answered two questions: (1) Across the United States, which types of events ( as indicated in the EVTYPE variable) are most harmful with respect to population health? (2) Across the United States, which types of events have the greatest economic consequences? The analysis was carried out in R Studio Version 0.98.994. The report shows how the data was processed, how the analysis was conducted, and how the conclusions was drew from the analysis.

Data Processing

Load the download the NOAA storm Data from working directory and summarize the data

myData <- read.table("repdata-data-StormData.csv",sep=",",head=TRUE,na.string="NA")
summary(myData)
##     STATE__                  BGN_DATE             BGN_TIME     
##  Min.   : 1.0   5/25/2011 0:00:00:  1202   12:00:00 AM: 10163  
##  1st Qu.:19.0   4/27/2011 0:00:00:  1193   06:00:00 PM:  7350  
##  Median :30.0   6/9/2011 0:00:00 :  1030   04:00:00 PM:  7261  
##  Mean   :31.2   5/30/2004 0:00:00:  1016   05:00:00 PM:  6891  
##  3rd Qu.:45.0   4/4/2011 0:00:00 :  1009   12:00:00 PM:  6703  
##  Max.   :95.0   4/2/2006 0:00:00 :   981   03:00:00 PM:  6700  
##                 (Other)          :895866   (Other)    :857229  
##    TIME_ZONE          COUNTY         COUNTYNAME         STATE       
##  CST    :547493   Min.   :  0   JEFFERSON :  7840   TX     : 83728  
##  EST    :245558   1st Qu.: 31   WASHINGTON:  7603   KS     : 53440  
##  MST    : 68390   Median : 75   JACKSON   :  6660   OK     : 46802  
##  PST    : 28302   Mean   :101   FRANKLIN  :  6256   MO     : 35648  
##  AST    :  6360   3rd Qu.:131   LINCOLN   :  5937   IA     : 31069  
##  HST    :  2563   Max.   :873   MADISON   :  5632   NE     : 30271  
##  (Other):  3631                 (Other)   :862369   (Other):621339  
##                EVTYPE         BGN_RANGE       BGN_AZI      
##  HAIL             :288661   Min.   :   0          :547332  
##  TSTM WIND        :219940   1st Qu.:   0   N      : 86752  
##  THUNDERSTORM WIND: 82563   Median :   0   W      : 38446  
##  TORNADO          : 60652   Mean   :   1   S      : 37558  
##  FLASH FLOOD      : 54277   3rd Qu.:   1   E      : 33178  
##  FLOOD            : 25326   Max.   :3749   NW     : 24041  
##  (Other)          :170878                  (Other):134990  
##          BGN_LOCATI                  END_DATE             END_TIME     
##               :287743                    :243411              :238978  
##  COUNTYWIDE   : 19680   4/27/2011 0:00:00:  1214   06:00:00 PM:  9802  
##  Countywide   :   993   5/25/2011 0:00:00:  1196   05:00:00 PM:  8314  
##  SPRINGFIELD  :   843   6/9/2011 0:00:00 :  1021   04:00:00 PM:  8104  
##  SOUTH PORTION:   810   4/4/2011 0:00:00 :  1007   12:00:00 PM:  7483  
##  NORTH PORTION:   784   5/30/2004 0:00:00:   998   11:59:00 PM:  7184  
##  (Other)      :591444   (Other)          :653450   (Other)    :622432  
##    COUNTY_END COUNTYENDN       END_RANGE      END_AZI      
##  Min.   :0    Mode:logical   Min.   :  0          :724837  
##  1st Qu.:0    NA's:902297    1st Qu.:  0   N      : 28082  
##  Median :0                   Median :  0   S      : 22510  
##  Mean   :0                   Mean   :  1   W      : 20119  
##  3rd Qu.:0                   3rd Qu.:  0   E      : 20047  
##  Max.   :0                   Max.   :925   NE     : 14606  
##                                            (Other): 72096  
##            END_LOCATI         LENGTH           WIDTH            F         
##                 :499225   Min.   :   0.0   Min.   :   0   Min.   :0       
##  COUNTYWIDE     : 19731   1st Qu.:   0.0   1st Qu.:   0   1st Qu.:0       
##  SOUTH PORTION  :   833   Median :   0.0   Median :   0   Median :1       
##  NORTH PORTION  :   780   Mean   :   0.2   Mean   :   8   Mean   :1       
##  CENTRAL PORTION:   617   3rd Qu.:   0.0   3rd Qu.:   0   3rd Qu.:1       
##  SPRINGFIELD    :   575   Max.   :2315.0   Max.   :4400   Max.   :5       
##  (Other)        :380536                                   NA's   :843563  
##       MAG          FATALITIES     INJURIES         PROPDMG    
##  Min.   :    0   Min.   :  0   Min.   :   0.0   Min.   :   0  
##  1st Qu.:    0   1st Qu.:  0   1st Qu.:   0.0   1st Qu.:   0  
##  Median :   50   Median :  0   Median :   0.0   Median :   0  
##  Mean   :   47   Mean   :  0   Mean   :   0.2   Mean   :  12  
##  3rd Qu.:   75   3rd Qu.:  0   3rd Qu.:   0.0   3rd Qu.:   0  
##  Max.   :22000   Max.   :583   Max.   :1700.0   Max.   :5000  
##                                                               
##    PROPDMGEXP        CROPDMG        CROPDMGEXP          WFO        
##         :465934   Min.   :  0.0          :618413          :142069  
##  K      :424665   1st Qu.:  0.0   K      :281832   OUN    : 17393  
##  M      : 11330   Median :  0.0   M      :  1994   JAN    : 13889  
##  0      :   216   Mean   :  1.5   k      :    21   LWX    : 13174  
##  B      :    40   3rd Qu.:  0.0   0      :    19   PHI    : 12551  
##  5      :    28   Max.   :990.0   B      :     9   TSA    : 12483  
##  (Other):    84                   (Other):     9   (Other):690738  
##                                STATEOFFIC    
##                                     :248769  
##  TEXAS, North                       : 12193  
##  ARKANSAS, Central and North Central: 11738  
##  IOWA, Central                      : 11345  
##  KANSAS, Southwest                  : 11212  
##  GEORGIA, North and Central         : 11120  
##  (Other)                            :595920  
##                                                                                                                                                                                                     ZONENAMES     
##                                                                                                                                                                                                          :594029  
##                                                                                                                                                                                                          :205988  
##  GREATER RENO / CARSON CITY / M - GREATER RENO / CARSON CITY / M                                                                                                                                         :   639  
##  GREATER LAKE TAHOE AREA - GREATER LAKE TAHOE AREA                                                                                                                                                       :   592  
##  JEFFERSON - JEFFERSON                                                                                                                                                                                   :   303  
##  MADISON - MADISON                                                                                                                                                                                       :   302  
##  (Other)                                                                                                                                                                                                 :100444  
##     LATITUDE      LONGITUDE        LATITUDE_E     LONGITUDE_    
##  Min.   :   0   Min.   :-14451   Min.   :   0   Min.   :-14455  
##  1st Qu.:2802   1st Qu.:  7247   1st Qu.:   0   1st Qu.:     0  
##  Median :3540   Median :  8707   Median :   0   Median :     0  
##  Mean   :2875   Mean   :  6940   Mean   :1452   Mean   :  3509  
##  3rd Qu.:4019   3rd Qu.:  9605   3rd Qu.:3549   3rd Qu.:  8735  
##  Max.   :9706   Max.   : 17124   Max.   :9706   Max.   :106220  
##  NA's   :47                      NA's   :40                     
##                                            REMARKS           REFNUM      
##                                                :287433   Min.   :     1  
##                                                : 24013   1st Qu.:225575  
##  Trees down.\n                                 :  1110   Median :451149  
##  Several trees were blown down.\n              :   569   Mean   :451149  
##  Trees were downed.\n                          :   446   3rd Qu.:676723  
##  Large trees and power lines were blown down.\n:   432   Max.   :902297  
##  (Other)                                       :588294

Data Analyzing

From the summary of the data and the information provided by the database website. The data supplys the number of fatalites and the number of injuries for each recorders from 1950 to November 2011. So, we can tell the total number of fataliteis and injuries for each type of events, then we can show which type of events have the greatest economic consequences.

  1. Calculated the total number of fatalities and injures for each types of events.
library(sqldf)
## Loading required package: gsubfn
## Loading required package: proto
## Loading required package: RSQLite
## Loading required package: DBI
## Loading required package: RSQLite.extfuns
TotalTable <- sqldf("select EVTYPE as Event_Type, sum(FATALITIES) as Total_Fatality, sum(INJURIES) as Total_Injure from myData group by EVTYPE")
## Loading required package: tcltk
  1. Plot the total falities of the top 10 events based on the total fatilities and injures
library(ggplot2)
top10_F <- data.frame(head(TotalTable[order(-TotalTable[,2]),],10))
top10_I <- data.frame(head(TotalTable[order(-TotalTable[,3]),],10))
ggplot(top10_F, aes(x=Event_Type, y=Total_Fatality))+geom_bar(stat="identity")+coord_flip()+ggtitle("Total fatalities of the top 10 most harmful events")

plot of chunk unnamed-chunk-4

ggplot(top10_I, aes(x=Event_Type, y=Total_Injure))+geom_bar(stat="identity")+coord_flip()+ggtitle("Total fatalities of the top 10 most harmful events")

plot of chunk unnamed-chunk-4

  1. Calculate total number of proporty loss and crop loss for each types of events

First, we need to convert the expense to corresponding unit (we are using damage in Million Dollor).

DamageTable <- sqldf("select EVTYPE, PROPDMGEXP, PROPDMG, CASE WHEN PROPDMGEXP = 'M' THEN 1 WHEN PROPDMGEXP = 'K' THEN 0.001 WHEN PROPDMGEXP = 'B' THEN 1000 ELSE 0 END as PROPUNI,CROPDMGEXP, CROPDMG, CASE WHEN CROPDMGEXP = 'M' THEN 1 WHEN CROPDMGEXP = 'K' THEN 0.001 WHEN CROPDMGEXP = 'B' THEN 1000 ELSE 0 END as CROPUNI from myData")

Then, we can calculate the total damage cost of each recorder, and get the total damage cost for each type of event

DamageTable$Cost <- DamageTable$PROPDMG*DamageTable$PROPUNI+DamageTable$CROPDMG*DamageTable$CROPUNI
DamageTotal <- sqldf("select EVTYPE as Event_Type, sum(Cost) as Total_Cost from DamageTable group by EVTYPE")

Finaly, we selecto the top 10 events based on the total damage cost (property and crop damage), and plot the results.

top10_D <- data.frame(head(DamageTotal[order(-DamageTotal[,2]),],10))
ggplot(top10_D, aes(x=Event_Type, y=Total_Cost))+geom_bar(stat="identity")+coord_flip()+ggtitle("Total damage cost (in Million) of the top 10 \n most harmful events")

plot of chunk unnamed-chunk-7

Results

Based on the analysis we have done, we could answer the two questions