Michael G Harpole
The basic goal of this assignment is to explore the NOAA Storm Database and answer some basic questions about severe weather events. You must use the database to answer the questions below and show the code for your entire analysis. Your analysis can consist of tables, figures, or other summaries. You may use any R package you want to support your analysis.
Your data analysis must address the following questions:
Has either a (1) valid RPubs URL pointing to a data analysis document for this assignment been submitted; or (2) a complete PDF file presenting the data analysis been uploaded?
Is the document written in English?
Does the analysis include description and justification for any data transformations?
Does the document have a title that briefly summarizes the data analysis?
Does the document have a synopsis that describes and summarizes the data analysis in less than 10 sentences?
Is there a section titled “Data Processing” that describes how the data were loaded into R and processed for analysis?
Is there a section titled “Results” where the main results are presented?
Is there at least one figure in the document that contains a plot?
Are there at most 3 figures in this document?
Does the analysis start from the raw data file (i.e. the original .csv.bz2 file)?
Does the analysis address the question of which types of events are most harmful to population health?
Does the analysis address the question of which types of events have the greatest economic consequences?
Do all the results of the analysis (i.e. figures, tables, numerical summaries) appear to be reproducible?
Do the figure(s) have descriptive captions (i.e. there is a description near the figure of what is happening in the figure)?
As far as you can determine, does it appear that the work submitted for this project is the work of the student who submitted it?
stormData <- read_csv("repdata_data_StormData.csv.bz2")
## Rows: 902297 Columns: 37
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (18): BGN_DATE, BGN_TIME, TIME_ZONE, COUNTYNAME, STATE, EVTYPE, BGN_AZI,...
## dbl (18): STATE__, COUNTY, BGN_RANGE, COUNTY_END, END_RANGE, LENGTH, WIDTH, ...
## lgl (1): COUNTYENDN
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
summary(stormData)
## STATE__ BGN_DATE BGN_TIME TIME_ZONE
## Min. : 1.0 Length:902297 Length:902297 Length:902297
## 1st Qu.:19.0 Class :character Class :character Class :character
## Median :30.0 Mode :character Mode :character Mode :character
## Mean :31.2
## 3rd Qu.:45.0
## Max. :95.0
##
## COUNTY COUNTYNAME STATE EVTYPE
## Min. : 0.0 Length:902297 Length:902297 Length:902297
## 1st Qu.: 31.0 Class :character Class :character Class :character
## Median : 75.0 Mode :character Mode :character Mode :character
## Mean :100.6
## 3rd Qu.:131.0
## Max. :873.0
##
## BGN_RANGE BGN_AZI BGN_LOCATI END_DATE
## Min. : 0.000 Length:902297 Length:902297 Length:902297
## 1st Qu.: 0.000 Class :character Class :character Class :character
## Median : 0.000 Mode :character Mode :character Mode :character
## Mean : 1.484
## 3rd Qu.: 1.000
## Max. :3749.000
##
## END_TIME COUNTY_END COUNTYENDN END_RANGE
## Length:902297 Min. :0 Mode:logical Min. : 0.0000
## Class :character 1st Qu.:0 NA's:902297 1st Qu.: 0.0000
## Mode :character Median :0 Median : 0.0000
## Mean :0 Mean : 0.9862
## 3rd Qu.:0 3rd Qu.: 0.0000
## Max. :0 Max. :925.0000
##
## END_AZI END_LOCATI LENGTH WIDTH
## Length:902297 Length:902297 Min. : 0.0000 Min. : 0.000
## Class :character Class :character 1st Qu.: 0.0000 1st Qu.: 0.000
## Mode :character Mode :character Median : 0.0000 Median : 0.000
## Mean : 0.2301 Mean : 7.503
## 3rd Qu.: 0.0000 3rd Qu.: 0.000
## Max. :2315.0000 Max. :4400.000
##
## F MAG FATALITIES INJURIES
## Min. :0.0 Min. : 0.0 Min. : 0.0000 Min. : 0.0000
## 1st Qu.:0.0 1st Qu.: 0.0 1st Qu.: 0.0000 1st Qu.: 0.0000
## Median :1.0 Median : 50.0 Median : 0.0000 Median : 0.0000
## Mean :0.9 Mean : 46.9 Mean : 0.0168 Mean : 0.1557
## 3rd Qu.:1.0 3rd Qu.: 75.0 3rd Qu.: 0.0000 3rd Qu.: 0.0000
## Max. :5.0 Max. :22000.0 Max. :583.0000 Max. :1700.0000
## NA's :843563
## PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP
## Min. : 0.00 Length:902297 Min. : 0.000 Length:902297
## 1st Qu.: 0.00 Class :character 1st Qu.: 0.000 Class :character
## Median : 0.00 Mode :character Median : 0.000 Mode :character
## Mean : 12.06 Mean : 1.527
## 3rd Qu.: 0.50 3rd Qu.: 0.000
## Max. :5000.00 Max. :990.000
##
## WFO STATEOFFIC ZONENAMES LATITUDE
## Length:902297 Length:902297 Length:902297 Min. : 0
## Class :character Class :character Class :character 1st Qu.:2802
## Mode :character Mode :character Mode :character Median :3540
## Mean :2875
## 3rd Qu.:4019
## Max. :9706
## NA's :47
## LONGITUDE LATITUDE_E LONGITUDE_ REMARKS
## Min. :-14451 Min. : 0 Min. :-14455 Length:902297
## 1st Qu.: 7247 1st Qu.: 0 1st Qu.: 0 Class :character
## Median : 8707 Median : 0 Median : 0 Mode :character
## Mean : 6940 Mean :1452 Mean : 3509
## 3rd Qu.: 9605 3rd Qu.:3549 3rd Qu.: 8735
## Max. : 17124 Max. :9706 Max. :106220
## NA's :40
## REFNUM
## Min. : 1
## 1st Qu.:225575
## Median :451149
## Mean :451149
## 3rd Qu.:676723
## Max. :902297
##
healthImpactData <- stormData %>%
select(`EVENT TYPE` = EVTYPE,FATALITIES,INJURIES) %>%
group_by(`EVENT TYPE`) %>%
summarise(
"Fatalities" = log10(sum(FATALITIES)),
"Injuries" = log10(sum(INJURIES))
) %>%
arrange(desc(`Fatalities`),desc(`Injuries`)) %>%
head(30) %>%
pivot_longer(!`EVENT TYPE`,names_to = "Health Impact", values_to = "Total")
This data is a bit more ambiguous because the values of eceonomic
property damage are stored as strings. The folowing excerpt from the
codebook for the NOAA storm data set explains this.
Damage. Property damage estimates should be entered as actual
dollar amounts, if a reasonably accurate estimate from an insurance
company or other qualified individual is available. If this estimate is
not available, then the preparer has two choices: either check the “no
information available” box, or make an estimate. The exception is for
flood events. The Storm Data preparer must enter monetary damage amounts
for flood events, even if it is a “guesstimate.” The U.S. Army Corps of
Engineers requires the NWS to provide monetary damage amounts (property
and/or crop) resulting from any flood event. The Storm Data preparer is
encouraged to make a good faith attempt to obtain or estimate the
damage. Property damage estimates are very important for many users and
should be obtained if at all possible.
Estimates can be obtained from emergency managers, U.S. Geological Survey, U.S. Army Corps of Engineers, power utility companies, and newspaper articles. If the values provided are rough estimates, then this should be stated as such in the narrative. Estimates should be rounded to three significant digits, followed by an alphabetical character signifying the magnitude of the number, i.e., 1.55B for $1,550,000,000. Alphabetical characters used to signify magnitude include “K” for thousands, “M” for millions, and “B” for billions. If additional precision is available, it may be provided in the narrative part of the entry. When damage is due to more than one element of the storm, indicate, when possible, the amount of damage caused by each element. If the dollar amount of damage is unknown, or not available, check the “no information available” box.
Steps
EconomcImpactData <- stormData %>%
select(EVTYPE,PROPDMG,PROPDMGEXP,CROPDMG,CROPDMGEXP)
ConvertedImpactData <- EconomcImpactData %>%
filter(str_detect(toupper(CROPDMGEXP),"[KMB]")|str_detect(toupper(PROPDMG),"[KMB]")) %>%
mutate(
"Crop Economic Impact" = case_when(
toupper(CROPDMGEXP) == "K"~ CROPDMG*1000,
toupper(CROPDMGEXP) == "M"~ CROPDMG*1000000,
toupper(CROPDMGEXP) == "B"~ CROPDMG*1000000000,
),
"Property Economic Impact"= case_when(
toupper(PROPDMGEXP) == "K"~ PROPDMG*1000,
toupper(PROPDMGEXP) == "M"~ PROPDMG*1000000,
toupper(PROPDMGEXP) == "B"~ PROPDMG*1000000000,
)
) %>%
mutate(
"Total Economic Impact"= case_when(
(!is.na(`Crop Economic Impact`) & !is.na(`Property Economic Impact`))~`Crop Economic Impact`+ `Property Economic Impact`,
!is.na(`Crop Economic Impact`) ~`Crop Economic Impact`,
!is.na(`Property Economic Impact`)~`Property Economic Impact`
)
) %>% rename("Event Type" =EVTYPE)
EconomcImpactSummary <- ConvertedImpactData %>%
group_by(`Event Type`) %>%
summarise(
"Economic Impact By Event Type" = log10(sum(`Total Economic Impact`)
)) %>% arrange(desc(`Economic Impact By Event Type`))
Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health? Steps
healthImpactData %>%
ggplot(aes(y=Total,x=reorder(`EVENT TYPE`,-Total), fill=`Health Impact`))+
xlab("Event Type")+
ylab("log10 Total Number")+
ggtitle("Top 20 Storm Event Types' Impact on Health in USA ")+
geom_bar(stat="identity",position="dodge")+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45,hjust = 1),
legend.position = c(.9,.9))
EconomcImpactSummary %>%
head(20) %>%
ggplot(aes(x=reorder(`Event Type`,-`Economic Impact By Event Type`),y=`Economic Impact By Event Type`, fill=`Event Type`))+
geom_bar(stat="identity")+
xlab("Event Type")+
ylab("Log10 of Dollar Amount of Impact")+
ggtitle("Top 20 Storm Event Types' Economic Impact in USA ")+
theme_minimal()+
theme(axis.text.x = element_text(angle = 45,hjust = 1),
legend.position = "none")
sessionInfo()
## R version 4.2.2 (2022-10-31)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Ventura 13.2.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] scales_1.2.1 lubridate_1.9.0 timechange_0.2.0 forcats_0.5.2
## [5] stringr_1.5.0 dplyr_1.0.10 purrr_1.0.1 readr_2.1.3
## [9] tidyr_1.2.1 tibble_3.1.8 ggplot2_3.4.0 tidyverse_1.3.2
##
## loaded via a namespace (and not attached):
## [1] assertthat_0.2.1 digest_0.6.31 utf8_1.2.2
## [4] R6_2.5.1 cellranger_1.1.0 backports_1.4.1
## [7] reprex_2.0.2 evaluate_0.20 highr_0.10
## [10] httr_1.4.4 pillar_1.8.1 rlang_1.0.6
## [13] googlesheets4_1.0.1 readxl_1.4.1 rstudioapi_0.14
## [16] jquerylib_0.1.4 rmarkdown_2.20 labeling_0.4.2
## [19] googledrive_2.0.0 bit_4.0.5 munsell_0.5.0
## [22] broom_1.0.2 compiler_4.2.2 modelr_0.1.10
## [25] xfun_0.36 pkgconfig_2.0.3 htmltools_0.5.4
## [28] tidyselect_1.2.0 fansi_1.0.3 crayon_1.5.2
## [31] tzdb_0.3.0 dbplyr_2.3.0 withr_2.5.0
## [34] grid_4.2.2 jsonlite_1.8.4 gtable_0.3.1
## [37] lifecycle_1.0.3 DBI_1.1.3 magrittr_2.0.3
## [40] cli_3.6.0 stringi_1.7.12 vroom_1.6.0
## [43] cachem_1.0.6 farver_2.1.1 fs_1.5.2
## [46] xml2_1.3.3 bslib_0.4.2 ellipsis_0.3.2
## [49] generics_0.1.3 vctrs_0.5.1 tools_4.2.2
## [52] bit64_4.0.5 glue_1.6.2 hms_1.1.2
## [55] parallel_4.2.2 fastmap_1.1.0 yaml_2.3.6
## [58] colorspace_2.0-3 gargle_1.2.1 rvest_1.0.3
## [61] knitr_1.41 haven_2.5.1 sass_0.4.4