title: Project 2, Exploration of NOAA Database for Harmful Events! author: “Phillip”

Synopsis:

This document will depict the results from data analysis of the National Weather Service Database on the most harmful types of events to the U.S. Population. There are many types of weather events that occurs across America, which have devastating and lasting effects upon the lives of people. This document will dive into this question by using the variable “EVTYPE” from the Storms Database to discover a pattern. Additionally, this document will depict the analysis of the various types of events, which have the greatest economic consequences.

My analysis will focus on answering two primary questions: (1.) Across the United States, which types of events are most harmful with respect to population health? (2.) Across the United States, which types of events have the greatest economic consequences? The results will be provided to my Senior Manager who is responsible for preparing for severe weather events and has to prioritize resources for the different types of events.

Data Processing:

• There should be a section titled Data Processing which describes (in words and code) how the data were loaded into R and processed for analysis. In particular, your analysis must start from the raw CSV file containing the data. You cannot do any preprocessing outside the document. If preprocessing is time-consuming you may consider using the cache = TRUE option for certain code chunks.

## Import data

NoSt_1 <- read.csv("repdata_data_StormData.csv")

head(NoSt_1)
##   STATE__           BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE  EVTYPE
## 1       1  4/18/1950 0:00:00     0130       CST     97     MOBILE    AL TORNADO
## 2       1  4/18/1950 0:00:00     0145       CST      3    BALDWIN    AL TORNADO
## 3       1  2/20/1951 0:00:00     1600       CST     57    FAYETTE    AL TORNADO
## 4       1   6/8/1951 0:00:00     0900       CST     89    MADISON    AL TORNADO
## 5       1 11/15/1951 0:00:00     1500       CST     43    CULLMAN    AL TORNADO
## 6       1 11/15/1951 0:00:00     2000       CST     77 LAUDERDALE    AL TORNADO
##   BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END COUNTYENDN
## 1         0                                               0         NA
## 2         0                                               0         NA
## 3         0                                               0         NA
## 4         0                                               0         NA
## 5         0                                               0         NA
## 6         0                                               0         NA
##   END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES INJURIES PROPDMG
## 1         0                      14.0   100 3   0          0       15    25.0
## 2         0                       2.0   150 2   0          0        0     2.5
## 3         0                       0.1   123 2   0          0        2    25.0
## 4         0                       0.0   100 2   0          0        2     2.5
## 5         0                       0.0   150 2   0          0        2     2.5
## 6         0                       1.5   177 2   0          0        6     2.5
##   PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES LATITUDE LONGITUDE
## 1          K       0                                         3040      8812
## 2          K       0                                         3042      8755
## 3          K       0                                         3340      8742
## 4          K       0                                         3458      8626
## 5          K       0                                         3412      8642
## 6          K       0                                         3450      8748
##   LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1       3051       8806              1
## 2          0          0              2
## 3          0          0              3
## 4          0          0              4
## 5          0          0              5
## 6          0          0              6
# libraries
library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.4
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
str(NoSt_1)
## '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 ...

The code below will depict the types of harmful events in the US population.

library(ggplot2)
No_1 <- (c(NoSt_1$EVTYPE, NoSt_1$FATILITIES, data = NoSt_1, na.rm=TRUE))

totalNoSt_1 <- aggregate(NoSt_1$FATALITIES ~ NoSt_1$PROPDMG, NoSt_1, FUN = "mean", na.rm=TRUE)

totalNoSt_2 <- aggregate(NoSt_1$FATALITIES ~ NoSt_1$INJURIES, totalNoSt_1, FUN= "mean", na.rm=FALSE)
head(totalNoSt_2)
##   NoSt_1$INJURIES NoSt_1$FATALITIES
## 1               0       0.008548728
## 2               1       0.101856627
## 3               2       0.144862795
## 4               3       0.164948454
## 5               4       0.191192266
## 6               5       0.299012694
totalNoSt_3 <- aggregate(NoSt_1$PROPDMG  ~ NoSt_1$STATE, totalNoSt_2, FUN = "mean", na.rm=FALSE)

head(totalNoSt_3)
##   NoSt_1$STATE NoSt_1$PROPDMG
## 1           AK     7.74208836
## 2           AL    15.99044197
## 3           AM     3.00894093
## 4           AN     0.09046154
## 5           AR    13.32453620
## 6           AS    11.49610895
plot(totalNoSt_3, NoSt_1$FATALITIES, type = "o", col = "steelblue3", 
     main = expression("TYPE OF HARMFUL EVENTS IN US BY STATES"),
     ylab = expression("EVENT TYPES"), xlab = "STATES") 

png("plot8271.png")


plot(totalNoSt_3, NoSt_1$FATALITIES, type = "o", col = "steelblue3", 
     main = expression("TYPE OF HARMFUL EVENTS IN US BY STATES"),
     ylab = expression("EVENT TYPES"), xlab = "STATES") 

dev.off()
## png 
##   2

Results:

The result depicts the total number of events in the United States and the economic consequences. The code for the data analysis is shown in “Plot877”.

totalNoSt_1 <- aggregate(NoSt_1$FATALITIES ~ NoSt_1$PROPDMG, NoSt_1, FUN = "mean", na.rm=TRUE)

head(totalNoSt_1)
##   NoSt_1$PROPDMG NoSt_1$FATALITIES
## 1           0.00       0.011284483
## 2           0.01       0.003222342
## 3           0.02       0.000000000
## 4           0.03       0.004347826
## 5           0.04       0.000000000
## 6           0.05       0.005102041
PD1 <- mean(na.omit(NoSt_1$PROPDMG))
    
PD2 <- sum(na.omit(NoSt_1$PROPDMG))

mean(NoSt_1$PROPDMG)
## [1] 12.0631
PD <- mean(NoSt_1$PROPDMG)

mean(na.omit(NoSt_1$CROPDMG))
## [1] 1.527022
mean(NoSt_1$CROPDMG)
## [1] 1.527022
CD <- mean(NoSt_1$CROPDMG)

CD2 <- sum(NoSt_1$CROPDMG)

Con_Data2 <- aggregate(CD2 ~ PD2, NoSt_1, FUN = "mean", na.rm=TRUE)
head(Con_Data2)
##        PD2     CD2
## 1 10884500 1377827
plot(NoSt_1$STATE, xlab="EVTYPE", ylab="Economic Consequences (K$)",main="Total Events in US")

png("plot877.png")
plot(NoSt_1$STATE, xlab="EVTYPE", ylab="Economic Consequences (K$)",main="Total Events in US")

dev.off()
## png 
##   2