The purpose of data analysis is to determine the impact of NOAA weather events on the health of the population and economic losses. The analysis showed that the greatest impact on the health and economic losses generate tornadoes and flash flood and thunderstorm wind. The data used in the analysis come from the years 1950-2011. Analysis suggests that the severity of the impact on health and economic losses increases from the 90s of the twentieth century. However, this is likely to result from the fact that in previous years were not collected as accurately as current data on weather phenomena.
First we need load two R packages (dplyr and ggplot2) which I will use in my analisys.
library("dplyr")
##
## 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
library("ggplot2")
Downlading data Storm data from working directory
download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", destfile="stormData.csv.bz2", method="curl")
## Warning: uruchomione polecenie 'curl "https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2" -o "stormData.csv.bz2"' otrzymało status 127
## Warning: download had nonzero exit status
data <- read.table("storm1.csv", header=T, sep = ",")
Creating a data frame from the selected variables, which will be used for analysis The new data frame will contain the variables: BGN_DATE, EVTYPE, FATALITIES, INJURIES, PROPDMG, CROPDMG
data.selected <- select(data, BGN_DATE, EVTYPE,FATALITIES, INJURIES, PROPDMG,CROPDMG)
BGN_DATE variable must be converted to Dates class. This is done by replacing BGN_DATE using as.character and then with the function strptime to POSIXlt. At the end I create a new variable Year from BGN_DATE variable
data.selected$BGN_DATE <- strptime(as.character(data.selected$BGN_DATE),"%m/%d/%Y")
data.selected$YEAR <- format(data.selected$BGN_DATE,"%Y")
data.selected$BGN_DATE <- as.Date(data.selected$BGN_DATE)
Let look at the number of weather events in different years
hist(as.numeric(data.selected$YEAR), xlab="Year", main="Number of weather events per year")
Variable EVTYPE requires little cleaning. First of all, I delete the values in which the’re is a string “Summaries.”
remove.summary <- grep("Summary.", data.selected[, "EVTYPE"], ignore.case=TRUE)
data.selected <- data.selected[-remove.summary, ]
Summarise of health and economic impact data. We summarise two health related variables: FATALITIES and INJURIES and economic variables: PROPDMG and CROPDMG.
data.selected<-mutate(data.selected, HEALTH.HARMFUL=FATALITIES+INJURIES)
data.selected<-mutate(data.selected, ECONOMIC.DAMAGES=PROPDMG+CROPDMG)
Group data by Weather events type and by year
data.selected.by.EVTYPE <- group_by(data.selected, EVTYPE)
data.selected.by.YEAR <- group_by(data.selected,YEAR)
Summarise variables by weather events.
data.selected.sum <- summarise(data.selected.by.EVTYPE, count=n(), injuries=sum(INJURIES),
fatalities=sum(FATALITIES),prop.damages=sum(PROPDMG),crop.damages=sum(CROPDMG),
health=sum(HEALTH.HARMFUL), economic.damages=sum(ECONOMIC.DAMAGES))
data.selected.sum.by.YEAR <- summarise(data.selected.by.YEAR, count=n(), injuries=sum(INJURIES),
fatalities=sum(FATALITIES),prop.damages=sum(PROPDMG),crop.damages=sum(CROPDMG),
health=sum(HEALTH.HARMFUL), economic.damages=sum(ECONOMIC.DAMAGES))
Creating health impact ranking
data.selected.ranking.health <- arrange(data.selected.sum, desc(health))
First ten highest public health impact
data.selected.ranking.health[1:10,c("EVTYPE","health","injuries","fatalities")]
## Source: local data frame [10 x 4]
##
## EVTYPE health injuries fatalities
## 1 TORNADO 96979 91346 5633
## 2 EXCESSIVE HEAT 8428 6525 1903
## 3 TSTM WIND 7461 6957 504
## 4 FLOOD 7259 6789 470
## 5 LIGHTNING 6046 5230 816
## 6 HEAT 3037 2100 937
## 7 FLASH FLOOD 2755 1777 978
## 8 ICE STORM 2064 1975 89
## 9 THUNDERSTORM WIND 1621 1488 133
## 10 WINTER STORM 1527 1321 206
It’s clear, that most public health impact is from tornadoes.
Look how it was health impact year by year
plot(data.selected.sum.by.YEAR$YEAR, data.selected.sum.by.YEAR$health, xlab="Year", ylab="Health impact", main="Yearly health impact from weather events")
Creating economic damages ranking
data.selected.ranking.economic <- arrange(data.selected.sum, desc(economic.damages))
First ten highest economic damages
data.selected.ranking.economic[1:10,c("EVTYPE","economic.damages","prop.damages","crop.damages")]
## Source: local data frame [10 x 4]
##
## EVTYPE economic.damages prop.damages crop.damages
## 1 TORNADO 3312277 3212258 100019
## 2 FLASH FLOOD 1599325 1420125 179200
## 3 TSTM WIND 1445168 1335966 109203
## 4 HAIL 1268290 688693 579596
## 5 FLOOD 1067976 899938 168038
## 6 THUNDERSTORM WIND 943636 876844 66791
## 7 LIGHTNING 606932 603352 3581
## 8 THUNDERSTORM WINDS 464978 446293 18685
## 9 HIGH WIND 342015 324732 17283
## 10 WINTER STORM 134700 132721 1979
Tornadoes has also a bigest ecomomic impact.
Look at economic damages year by year
plot(data.selected.sum.by.YEAR$YEAR, data.selected.sum.by.YEAR$economic.damages, xlab="Year", ylab="Economic damages", main="Yearly economic damages from weather events")