library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.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
library(dplyr)
library(readxl)
load("NSDUH_2023.Rdata")
cordata<-data%>%select(IRAMDEYR,BNGDRMDAYS,AGE3) %>% drop_na(IRAMDEYR,BNGDRMDAYS,AGE3)
cor(cordata)
##               IRAMDEYR  BNGDRMDAYS        AGE3
## IRAMDEYR    1.00000000 -0.02039946 -0.14357527
## BNGDRMDAYS -0.02039946  1.00000000  0.07372612
## AGE3       -0.14357527  0.07372612  1.00000000
pairs(~BNGDRMDAYS+IRAMDEYR+AGE3,data = cordata)

cor.test(cordata$IRAMDEYR, cordata$AGE3,method = "kendall")
## 
##  Kendall's rank correlation tau
## 
## data:  cordata$IRAMDEYR and cordata$AGE3
## z = -30.948, p-value < 2.2e-16
## alternative hypothesis: true tau is not equal to 0
## sample estimates:
##       tau 
## -0.127265
cor.test(cordata$IRAMDEYR, cordata$BNGDRMDAYS, method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  cordata$IRAMDEYR and cordata$BNGDRMDAYS
## t = -4.3346, df = 45131, p-value = 1.464e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.02961967 -0.01117579
## sample estimates:
##         cor 
## -0.02039946
cor.test(cordata$IRAMDEYR, cordata$BNGDRMDAYS, method = "spearman")
## Warning in cor.test.default(cordata$IRAMDEYR, cordata$BNGDRMDAYS, method =
## "spearman"): cannot compute exact p-value with ties
## 
##  Spearman's rank correlation rho
## 
## data:  cordata$IRAMDEYR and cordata$BNGDRMDAYS
## S = 1.5727e+13, p-value = 2.043e-08
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##         rho 
## -0.02639522

Using the NSDUH 2023 dataset, I selected three variables age category (AGE3), mental health (IRAMDEYR), and binge drinking days. I used the correlation command to examine potential correlation and the pairs command to visually inspect the relationship between the variables. Kendall’s tau was used to examine the relationship between age and mental health, revealing a weak a weak negative association. Peason’s and Spearman’s correlations were used to examine mental health and binge drinking days, both showing extemely weak negative associations.