In this report we aim to describe types of events that are most harmful with respect to population health and economic consequences.The basic goalto explore the NOAA Storm Database and answer two basic questions about severe weather events.We use the database to answer the questions below and show the code for your entire analysis. My analysis can consist of tables, figures, or other summaries.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.
From the Storm Data we obtain the data on the types of events, fatalities, injuries, property damage and crop damage. We are addressing 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?
Fetching reading from the data
repdata-data-StormData.csv is read using read.csv command
data <- read.csv("repdata-data-StormData.csv")
To address the question: Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health? I read number of fatalities and injured people to evaluate the population health
fatal <- data$FATALITIES
injured <- data$INJURIES
health <- fatal + injured
Checking the that there are no NA term in the health data
for (i in 1:length(health)) {
if (is.na(health[i])) {
print("yes")
}
}
Calculating the total health effect due to type of events
effect <- tapply(health, data$EVTYPE, sum)
Sorting the values of health effect in decreasing order to see which types of events are most harmful with respect to population health
top <- head(sort(effect, decreasing = TRUE))
To answer the question: Across the United States, which types of events have the greatest economic consequences? I have calculated the total amount of property damage by taking product od property damage and have interpreted the property damage exponent and to calculate crop damage by taking product of crop damage and interpreted the propert damage exponent. I have assumed the value of 0 of “”, ? etc.
total <- numeric()
for (i in 1:length(data$PROPDMGEXP)) {
if (data$PROPDMGEXP[i] == "K") {
total[i] <- data$PROPDMG[i] * 1000
} else if (data$PROPDMGEXP[i] == "M") {
total[i] <- data$PROPDMG[i] * 1e+06
} else if (data$PROPDMGEXP[i] == "B") {
total[i] <- data$PROPDMG[i] * 1e+09
} else {
total[i] <- 0
}
if (data$CROPDMGEXP[i] == "K") {
total[i] <- total[i] + data$CROPDMG[i] * 1000
} else if (data$CROPDMGEXP[i] == "M") {
total[i] <- total[i] + data$CROPDMG[i] * 1e+06
} else if (data$CROPDMGEXP[i] == "B") {
total[i] <- total[i] + data$CROPDMG[i] * 1e+09
} else {
total[i] <- total[i] + 0
}
}
Calculating the total economic effect due to type of events
eco_effect <- tapply(total, data$EVTYPE, sum)
Sorting the values of economic effect in decreasing order to see which types of events have the greatest economic consequences
eco_top <- head(sort(eco_effect, decreasing = TRUE))
In order to answer which types of events are most harmful with respect to population health we are making pie chart and showing the results I am printing the head of the types of events but i have put pie chart command of whole data set in comment
head(top)
## TORNADO EXCESSIVE HEAT TSTM WIND FLOOD LIGHTNING
## 96979 8428 7461 7259 6046
## HEAT
## 3037
pie(top, names(top), main = "Health effect of events")
# pie(effect,names(effect))
From the pie chart we can clearly see that TORNADO has the greatest economic consequences and then the orders follow which can be seen in head(top) command
In order to answer which types of events have the greatest economic consequences we are making pie chart and showing the results I am printing the head of the types of events but i have put pie chart command of whole data set in comment
head(eco_top)
## FLOOD HURRICANE/TYPHOON TORNADO STORM SURGE
## 1.503e+11 7.191e+10 5.734e+10 4.332e+10
## HAIL FLASH FLOOD
## 1.875e+10 1.756e+10
pie(eco_top, names(eco_top), main = "Economic consequences of events")
# pie(eco_effect,names(eco_effect))
From the pie chart we can clearly see that FLOOD has the greatest economic consequences and then the orders follow which can be seen in head(eco_top) command