Synopsis

This is an analysis in the framework of the course: Reproduceable Research. The analysis aims to answer the following questions:

  1. Across the United States, which types of events (as indicated in the EVTYPE 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 uses storm-dataand presents results in graphical figures backed up with comments.

Importing and summarizing data

#installing packages setting working directory and importing data
knitr::opts_chunk$set(echo = TRUE)
setwd("H:/Mina dokument_filer/Kurser/R programming/C2")
data <- read.csv("repdata_data_StormData.csv")
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
head(data)
##   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

Data Processing

#creating index for population health effects
data$POPHEALTH = data$INJURIES + (data$FATALITIES * 3)

#fixing units for economic indicators
data$PROPDMGEXP[data$PROPDMGEXP == "K"] <- "1000"
data$PROPDMGEXP[data$PROPDMGEXP == "M"] <- "1000000"
data$PROPDMGEXP[data$PROPDMGEXP == "B"] <- "1000000000"

data$PROPDMG <- data$PROPDMG * as.numeric(data$PROPDMGEXP)
## Warning: NAs introduced by coercion
data$CROPDMGEXP[data$CROPDMGEXP == "K"] <- "1000"
data$CROPDMGEXP[data$CROPDMGEXP == "M"] <- "1000000"
data$CROPDMGEXP[data$CROPDMGEXP == "B"] <- "1000000000"

data$CROPDMG <- data$CROPDMG * as.numeric(data$CROPDMGEXP)
## Warning: NAs introduced by coercion
#creating index for economic consequences
data$ECOCON <- data$CROPDMG + data$PROPDMG
#dropping NAs
clean_data <- data[!is.na(data$ECOCON), ]
#Formatting date
clean_data$BGN_DATE <- as.Date(sub(" .*", "", clean_data$BGN_DATE), format = "%m/%d/%Y")

#Very high value in economic consequences. Thus looking at Economic consequences across time
plot(clean_data$BGN_DATE, clean_data$ECOCON, type = "l")

# Checking remarks.
Max_ecocon <- clean_data[clean_data$ECOCON == max(clean_data$ECOCON, na.rm = TRUE), ]
Remark_ECOCON <- Max_ecocon$REMARKS
print(Remark_ECOCON)
## [1] "Major flooding continued into the early hours of January 1st, before the Napa River finally fell below flood stage and the water receeded. Flooding was severe in Downtown Napa from the Napa Creek and the City and Parks Department was hit with $6 million in damage alone. The City of Napa had 600 homes with moderate damage, 150 damaged businesses with costs of at least $70 million."
#Seems to be correct and thus should be included. 

#No major outliers.

Results

Extreme events affects on human health

#Aggregaing
aggregated <- aggregate(POPHEALTH ~ EVTYPE , data = clean_data, FUN = sum)

# Filtering top 10 largest
Top10 <- head(aggregated[order(-aggregated$POPHEALTH), ], 10)

ggplot(data = Top10, aes(y = POPHEALTH, x = EVTYPE)) +
  geom_bar(stat = "identity") +
      theme_minimal() +
      theme(axis.text.x = element_text(angle = 45, hjust = 1))

The X-axis shows the index created which is assigned 1 for each injury and 3 for each fataility. The figure shows that Tornado is the single worst event for human health in the dataset.

Extreme events affect on economic aspects

#Aggregating
aggregated_E <- aggregate(ECOCON ~ EVTYPE , data = clean_data, FUN = sum)

# Filtering top 10 largest
Top10_E <- head(aggregated_E[order(-aggregated_E$ECOCON), ], 10)

#converting to billions
Top10_E$ECOCON <- Top10_E$ECOCON /1000000000
  
ggplot(data = Top10_E, aes(y = ECOCON, x = EVTYPE)) +
  geom_bar(stat = "identity")  +
      theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

The X-axis shows economic consequences as a sum of property and Flood is the single most harmful event on economic aspects.