library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
suicide_data <- read_csv("C:/Users/Campo/Downloads/Death_rates_for_suicide__by_sex__race__Hispanic_origin__and_age__United_States.csv")
## Rows: 6390 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): INDICATOR, UNIT, STUB_NAME, STUB_LABEL, AGE, FLAG
## dbl (7): UNIT_NUM, STUB_NAME_NUM, STUB_LABEL_NUM, YEAR, YEAR_NUM, AGE_NUM, E...
##
## ℹ 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.
head(suicide_data)
## # A tibble: 6 × 13
## INDICATOR UNIT UNIT_NUM STUB_NAME STUB_NAME_NUM STUB_LABEL STUB_LABEL_NUM
## <chr> <chr> <dbl> <chr> <dbl> <chr> <dbl>
## 1 Death rates … Deat… 1 Total 0 All perso… 0
## 2 Death rates … Deat… 1 Total 0 All perso… 0
## 3 Death rates … Deat… 1 Total 0 All perso… 0
## 4 Death rates … Deat… 1 Total 0 All perso… 0
## 5 Death rates … Deat… 1 Total 0 All perso… 0
## 6 Death rates … Deat… 1 Total 0 All perso… 0
## # ℹ 6 more variables: YEAR <dbl>, YEAR_NUM <dbl>, AGE <chr>, AGE_NUM <dbl>,
## # ESTIMATE <dbl>, FLAG <chr>
correlation_year_estimate <- cor(suicide_data$YEAR_NUM, suicide_data$ESTIMATE, use = "complete.obs")
print(correlation_year_estimate)
## [1] -0.0632304
pairs(~ YEAR_NUM + ESTIMATE, data = suicide_data, main = "Scatterplot Matrix of Year and Death Rate")

pearson_correlation <- cor(suicide_data$YEAR_NUM, suicide_data$ESTIMATE, method = "pearson", use = "complete.obs")
print(pearson_correlation)
## [1] -0.0632304
correlation_age_estimate <- cor(suicide_data$AGE_NUM, suicide_data$ESTIMATE, use = "complete.obs")
print(correlation_age_estimate)
## [1] 0.3256933
pairs(~ AGE_NUM + ESTIMATE, data = suicide_data, main = "Scatterplot Matrix of Age and Death Rate Estimate")

pearson_correlation_age_estimate <- cor(suicide_data$AGE_NUM, suicide_data$ESTIMATE, method = "pearson", use = "complete.obs")
print(pearson_correlation_age_estimate)
## [1] 0.3256933