R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

title: “NOAA Storm Data Analysis” author: “Your Name” date: “2025-02-13” output: html_document —

Synopsis

This analysis explores the NOAA Storm Database to determine which types of weather events are most harmful to human health and which cause the greatest economic damage. We use data from 1950 to 2011, focusing on fatalities, injuries, and property damage.

Load required libraries

library(ggplot2) library(dplyr) library(tidyr) ## Read the compressed CSV file storm_data <- read.csv(“repdata_data_StormData.csv.bz2”, stringsAsFactors = FALSE)

Select relevant columns

storm_data <- storm_data %>% select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)

Convert damage exponents to numeric multipliers

convert_exp <- function(exp) { exp <- toupper(exp) if (exp == “K”) return(1000) if (exp == “M”) return(1e6) if (exp == “B”) return(1e9) return(1) # Default for missing or unknown multipliers }

storm_data\(PROPDMGEXP <- sapply(storm_data\)PROPDMGEXP, convert_exp) storm_data\(CROPDMGEXP <- sapply(storm_data\)CROPDMGEXP, convert_exp)

Calculate total damage

storm_data\(PROPDMG <- storm_data\)PROPDMG * storm_data\(PROPDMGEXP storm_data\)CROPDMG <- storm_data\(CROPDMG * storm_data\)CROPDMGEXP

Group by event type and sum fatalities & injuries

health_impact <- storm_data %>% group_by(EVTYPE) %>% summarise(Fatalities = sum(FATALITIES), Injuries = sum(INJURIES)) %>% arrange(desc(Fatalities))

Plot the top 10 deadliest storm events

ggplot(health_impact[1:10, ], aes(x = reorder(EVTYPE, -Fatalities), y = Fatalities)) + geom_bar(stat = “identity”, fill = “red”) + coord_flip() + xlab(“Event Type”) + ylab(“Total Fatalities”) + ggtitle(“Top 10 Deadliest Storm Events in the U.S. (1950-2011)”) ## Group by event type and sum economic damage economic_impact <- storm_data %>% group_by(EVTYPE) %>% summarise(Total_Damage = sum(PROPDMG + CROPDMG)) %>% arrange(desc(Total_Damage))

Plot the top 10 costliest storm events

ggplot(economic_impact[1:10, ], aes(x = reorder(EVTYPE, -Total_Damage), y = Total_Damage/1e9)) + geom_bar(stat = “identity”, fill = “blue”) + coord_flip() + xlab(“Event Type”) + ylab(“Total Damage (Billions USD)”) + ggtitle(“Top 10 Costliest Storm Events in the U.S. (1950-2011)”) ## Results The analysis indicates: