This project analyzes the impact of different weather events across the United States. The data is collected from the NOAA Storm Events Database. The main objective is to identify which weather events cause the greatest harm to human health and economic conditions. Fatalities and injuries are used to measure the impact on population health. Property damage and crop damage are used to measure economic consequences. The dataset is processed using R programming. Different statistical calculations are performed to compare weather events. Graphs are created to present the results clearly. This analysis helps identify the weather events with the greatest overall impact.
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
storm_data <- read.csv("~/repdata_data_StormData.csv/repdata_data_StormData.csv",
stringsAsFactors = FALSE)
dim(storm_data)
## [1] 902297 37
names(storm_data)
## [1] "STATE__" "BGN_DATE" "BGN_TIME" "TIME_ZONE" "COUNTY"
## [6] "COUNTYNAME" "STATE" "EVTYPE" "BGN_RANGE" "BGN_AZI"
## [11] "BGN_LOCATI" "END_DATE" "END_TIME" "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE" "END_AZI" "END_LOCATI" "LENGTH" "WIDTH"
## [21] "F" "MAG" "FATALITIES" "INJURIES" "PROPDMG"
## [26] "PROPDMGEXP" "CROPDMG" "CROPDMGEXP" "WFO" "STATEOFFIC"
## [31] "ZONENAMES" "LATITUDE" "LONGITUDE" "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS" "REFNUM"
str(storm_data)
## 'data.frame': 902297 obs. of 37 variables:
## $ STATE__ : num 1 1 1 1 1 1 1 1 1 1 ...
## $ BGN_DATE : chr "4/18/1950 0:00:00" "4/18/1950 0:00:00" "2/20/1951 0:00:00" "6/8/1951 0:00:00" ...
## $ BGN_TIME : chr "0130" "0145" "1600" "0900" ...
## $ TIME_ZONE : chr "CST" "CST" "CST" "CST" ...
## $ COUNTY : num 97 3 57 89 43 77 9 123 125 57 ...
## $ COUNTYNAME: chr "MOBILE" "BALDWIN" "FAYETTE" "MADISON" ...
## $ STATE : chr "AL" "AL" "AL" "AL" ...
## $ EVTYPE : chr "TORNADO" "TORNADO" "TORNADO" "TORNADO" ...
## $ BGN_RANGE : num 0 0 0 0 0 0 0 0 0 0 ...
## $ BGN_AZI : chr "" "" "" "" ...
## $ BGN_LOCATI: chr "" "" "" "" ...
## $ END_DATE : chr "" "" "" "" ...
## $ END_TIME : chr "" "" "" "" ...
## $ 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 : chr "" "" "" "" ...
## $ END_LOCATI: chr "" "" "" "" ...
## $ 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: chr "K" "K" "K" "K" ...
## $ CROPDMG : num 0 0 0 0 0 0 0 0 0 0 ...
## $ CROPDMGEXP: chr "" "" "" "" ...
## $ WFO : chr "" "" "" "" ...
## $ STATEOFFIC: chr "" "" "" "" ...
## $ ZONENAMES : chr "" "" "" "" ...
## $ 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 : chr "" "" "" "" ...
## $ REFNUM : num 1 2 3 4 5 6 7 8 9 10 ...
summary(storm_data[, c("EVTYPE",
"FATALITIES",
"INJURIES",
"PROPDMG",
"CROPDMG")])
## EVTYPE FATALITIES INJURIES PROPDMG
## Length:902297 Min. : 0.00000 Min. : 0.0000 Min. : 0.00
## Class :character 1st Qu.: 0.00000 1st Qu.: 0.0000 1st Qu.: 0.00
## Mode :character Median : 0.00000 Median : 0.0000 Median : 0.00
## Mean : 0.01678 Mean : 0.1557 Mean : 12.06
## 3rd Qu.: 0.00000 3rd Qu.: 0.0000 3rd Qu.: 0.50
## Max. :583.00000 Max. :1700.0000 Max. :5000.00
## CROPDMG
## Min. : 0.000
## 1st Qu.: 0.000
## Median : 0.000
## Mean : 1.527
## 3rd Qu.: 0.000
## Max. :990.000
fatalities <- aggregate(FATALITIES ~ EVTYPE,
data = storm_data,
FUN = sum)
fatalities <- fatalities[
order(-fatalities$FATALITIES), ]
injuries <- aggregate(INJURIES ~ EVTYPE,
data = storm_data,
FUN = sum)
injuries <- injuries[
order(-injuries$INJURIES), ]
head(fatalities, 10)
## EVTYPE FATALITIES
## 834 TORNADO 5633
## 130 EXCESSIVE HEAT 1903
## 153 FLASH FLOOD 978
## 275 HEAT 937
## 464 LIGHTNING 816
## 856 TSTM WIND 504
## 170 FLOOD 470
## 585 RIP CURRENT 368
## 359 HIGH WIND 248
## 19 AVALANCHE 224
head(injuries, 10)
## EVTYPE INJURIES
## 834 TORNADO 91346
## 856 TSTM WIND 6957
## 170 FLOOD 6789
## 130 EXCESSIVE HEAT 6525
## 464 LIGHTNING 5230
## 275 HEAT 2100
## 427 ICE STORM 1975
## 153 FLASH FLOOD 1777
## 760 THUNDERSTORM WIND 1488
## 244 HAIL 1361
# Function to convert damage multipliers
get_multiplier <- function(exp) {
exp <- toupper(trimws(as.character(exp)))
if (is.na(exp) || exp == "") {
return(0)
}
if (exp == "H") return(100)
if (exp == "K") return(1000)
if (exp == "M") return(1000000)
if (exp == "B") return(1000000000)
if (grepl("^[0-8]$", exp)) {
return(10^as.numeric(exp))
}
return(0)
}
# Calculate property damage
storm_data$PROP_MULT <- sapply(
storm_data$PROPDMGEXP,
get_multiplier
)
storm_data$PROPERTY_DAMAGE <-
storm_data$PROPDMG * storm_data$PROP_MULT
# Calculate crop damage
storm_data$CROP_MULT <- sapply(
storm_data$CROPDMGEXP,
get_multiplier
)
storm_data$CROP_DAMAGE <-
storm_data$CROPDMG * storm_data$CROP_MULT
property_damage <- aggregate(
PROPERTY_DAMAGE ~ EVTYPE,
data = storm_data,
FUN = sum
)
property_damage <- property_damage[
order(-property_damage$PROPERTY_DAMAGE), ]
head(property_damage, 10)
## EVTYPE PROPERTY_DAMAGE
## 170 FLOOD 144657709800
## 411 HURRICANE/TYPHOON 69305840000
## 834 TORNADO 56947380614
## 670 STORM SURGE 43323536000
## 153 FLASH FLOOD 16822673772
## 244 HAIL 15735267456
## 402 HURRICANE 11868319010
## 848 TROPICAL STORM 7703890550
## 972 WINTER STORM 6688497251
## 359 HIGH WIND 5270046260
crop_damage <- aggregate(
CROP_DAMAGE ~ EVTYPE,
data = storm_data,
FUN = sum
)
crop_damage <- crop_damage[
order(-crop_damage$CROP_DAMAGE), ]
head(crop_damage, 10)
## EVTYPE CROP_DAMAGE
## 95 DROUGHT 13972566000
## 170 FLOOD 5661968450
## 590 RIVER FLOOD 5029459000
## 427 ICE STORM 5022113500
## 244 HAIL 3025954470
## 402 HURRICANE 2741910000
## 411 HURRICANE/TYPHOON 2607872800
## 153 FLASH FLOOD 1421317100
## 140 EXTREME COLD 1292973000
## 212 FROST/FREEZE 1094086000
top_fatalities <- head(fatalities, 10)
ggplot(top_fatalities,
aes(x = reorder(EVTYPE, FATALITIES),
y = FATALITIES)) +
geom_bar(stat = "identity", fill = "red") +
coord_flip() +
labs(title = "Top 10 Weather Events Causing Fatalities",
x = "Weather Event",
y = "Total Fatalities") +
theme_minimal()
top_injuries <- head(injuries, 10)
ggplot(top_injuries, aes(x = reorder(EVTYPE, INJURIES), y = INJURIES)) + geom_bar(stat = “identity”, fill = “blue”) + coord_flip() + labs(title = “Top 10 Weather Events Causing Injuries”, x = “Weather Event”, y = “Total Injuries”) + theme_minimal()
economic_data <- data.frame( Damage_Type = c(“Property Damage”, “Crop Damage”), Total_Damage = c( sum(storm_data\(PROPERTY_DAMAGE), sum(storm_data\)CROP_DAMAGE) ) )
ggplot(economic_data, aes(x = Damage_Type, y = Total_Damage / 1000000000, fill = Damage_Type)) + geom_bar(stat = “identity”) + labs(title = “Total Economic Damage”, x = “Damage Type”, y = “Damage (Billion Dollars)”) + theme_minimal()
The analysis shows that different weather events have different effects on population health and economic conditions. Some events cause more fatalities and injuries, while others result in greater property and crop damage. The results help identify the most harmful weather events in the United States. This information can be useful for understanding the impact of severe weather and improving disaster preparedness.