The National Survey on Drug Use and Health (NSDUH) conducted a study within individual states collecting data regarding substance abuse in relation to age. The drugs involved in the dataset are: cigarettes, marijuana, cocaine, and alcohol.
Notes:
I will be examining yearly data and the cigarette values only pertain to monthly data; therefore I will not be using it.
Substance and Drug can be used interchangeably.
There are 53 variables: state, age group population (12-17, 18-25, 26+), total substance abuse for each drug and age group in the past year, rates of each substance abuse for each drug and age group in the past year, total substance abuse for each drug and age group in the past month, and rates of each substance abuse for each drug and age group in the past month.
Research Question:
Is there a statistically significant relationship between age group and the specific substance abused (alcohol, cocaine, and marijuana)?
Load Libraries
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
Attaching package: 'psych'
The following objects are masked from 'package:ggplot2':
%+%, alpha
Load the Dataset
drugs =read_csv("~/Downloads/drugs.csv")
Rows: 867 Columns: 53
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): State
dbl (52): Year, Population.12-17, Population.18-25, Population.26+, Totals.A...
ℹ 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.
Exploring the Dataset
names(drugs)
[1] "State"
[2] "Year"
[3] "Population.12-17"
[4] "Population.18-25"
[5] "Population.26+"
[6] "Totals.Alcohol.Use Disorder Past Year.12-17"
[7] "Totals.Alcohol.Use Disorder Past Year.18-25"
[8] "Totals.Alcohol.Use Disorder Past Year.26+"
[9] "Rates.Alcohol.Use Disorder Past Year.12-17"
[10] "Rates.Alcohol.Use Disorder Past Year.18-25"
[11] "Rates.Alcohol.Use Disorder Past Year.26+"
[12] "Totals.Alcohol.Use Past Month.12-17"
[13] "Totals.Alcohol.Use Past Month.18-25"
[14] "Totals.Alcohol.Use Past Month.26+"
[15] "Rates.Alcohol.Use Past Month.12-17"
[16] "Rates.Alcohol.Use Past Month.18-25"
[17] "Rates.Alcohol.Use Past Month.26+"
[18] "Totals.Tobacco.Cigarette Past Month.12-17"
[19] "Totals.Tobacco.Cigarette Past Month.18-25"
[20] "Totals.Tobacco.Cigarette Past Month.26+"
[21] "Rates.Tobacco.Cigarette Past Month.12-17"
[22] "Rates.Tobacco.Cigarette Past Month.18-25"
[23] "Rates.Tobacco.Cigarette Past Month.26+"
[24] "Totals.Illicit Drugs.Cocaine Used Past Year.12-17"
[25] "Totals.Illicit Drugs.Cocaine Used Past Year.18-25"
[26] "Totals.Illicit Drugs.Cocaine Used Past Year.26+"
[27] "Rates.Illicit Drugs.Cocaine Used Past Year.12-17"
[28] "Rates.Illicit Drugs.Cocaine Used Past Year.18-25"
[29] "Rates.Illicit Drugs.Cocaine Used Past Year.26+"
[30] "Totals.Marijuana.New Users.12-17"
[31] "Totals.Marijuana.New Users.18-25"
[32] "Totals.Marijuana.New Users.26+"
[33] "Rates.Marijuana.New Users.12-17"
[34] "Rates.Marijuana.New Users.18-25"
[35] "Rates.Marijuana.New Users.26+"
[36] "Totals.Marijuana.Used Past Month.12-17"
[37] "Totals.Marijuana.Used Past Month.18-25"
[38] "Totals.Marijuana.Used Past Month.26+"
[39] "Rates.Marijuana.Used Past Month.12-17"
[40] "Rates.Marijuana.Used Past Month.18-25"
[41] "Rates.Marijuana.Used Past Month.26+"
[42] "Totals.Marijuana.Used Past Year.12-17"
[43] "Totals.Marijuana.Used Past Year.18-25"
[44] "Totals.Marijuana.Used Past Year.26+"
[45] "Rates.Marijuana.Used Past Year.12-17"
[46] "Rates.Marijuana.Used Past Year.18-25"
[47] "Rates.Marijuana.Used Past Year.26+"
[48] "Totals.Tobacco.Use Past Month.12-17"
[49] "Totals.Tobacco.Use Past Month.18-25"
[50] "Totals.Tobacco.Use Past Month.26+"
[51] "Rates.Tobacco.Use Past Month.12-17"
[52] "Rates.Tobacco.Use Past Month.18-25"
[53] "Rates.Tobacco.Use Past Month.26+"
head(drugs)
# A tibble: 6 × 53
State Year `Population.12-17` `Population.18-25` `Population.26+`
<chr> <dbl> <dbl> <dbl> <dbl>
1 Alabama 2002 380805 499453 2812905
2 Alaska 2002 69400 62791 368460
3 Arizona 2002 485521 602265 3329482
4 Arkansas 2002 232986 302029 1687337
5 California 2002 3140739 3919577 21392421
6 Colorado 2002 385648 493921 2798960
# ℹ 48 more variables: `Totals.Alcohol.Use Disorder Past Year.12-17` <dbl>,
# `Totals.Alcohol.Use Disorder Past Year.18-25` <dbl>,
# `Totals.Alcohol.Use Disorder Past Year.26+` <dbl>,
# `Rates.Alcohol.Use Disorder Past Year.12-17` <dbl>,
# `Rates.Alcohol.Use Disorder Past Year.18-25` <dbl>,
# `Rates.Alcohol.Use Disorder Past Year.26+` <dbl>,
# `Totals.Alcohol.Use Past Month.12-17` <dbl>, …
Cleaning the Data
#clean the data so that it only displays yearly drug abuse disordercleaned =select(drugs, Year, starts_with("Total") &contains("Year")) |>#rename variables so that they are easier to work with rename('Alcohol 12-17'='Totals.Alcohol.Use Disorder Past Year.12-17', 'Alcohol 18-25'='Totals.Alcohol.Use Disorder Past Year.18-25','Alcohol 26+'='Totals.Alcohol.Use Disorder Past Year.26+', 'Cocaine 12-17'='Totals.Illicit Drugs.Cocaine Used Past Year.12-17', 'Cocaine 18-25'='Totals.Illicit Drugs.Cocaine Used Past Year.18-25', 'Cocaine 26+'='Totals.Illicit Drugs.Cocaine Used Past Year.26+', 'Marijuana 12-17'='Totals.Marijuana.Used Past Year.12-17', 'Marijuana 18-25'='Totals.Marijuana.Used Past Year.18-25', 'Marijuana 26+'='Totals.Marijuana.Used Past Year.26+' ) |>group_by(Year) |>#group data by year(row)summarise(across(where(is.numeric), \(x) sum(x, na.rm =TRUE))) #add numeric values so that we have the full total of drug abuse for each year (instead of separated by state)head(cleaned)
Now that we have cleaned and mutated the data, we can visualize it.
Visualizing the Data
First begin by comparing total substance abuse across age groups.
#create a new column to display total drug disorder use age_abuse = cleaned |>mutate('Total Drug Abuse 12-17'=`Alcohol 12-17`+`Cocaine 12-17`+`Marijuana 12-17`, #add together drug abuse for age group 12-17'Total Drug Abuse 18-25'=`Alcohol 18-25`+`Cocaine 18-25`+`Marijuana 18-25`, #add together drug abuse for age group 18-25'Total Drug Abuse 26+'=`Alcohol 26+`+`Cocaine 26+`+`Marijuana 26+`) #add together drug abuse for age group 26+age_abuse
#wide --> long ,, collapsing data into two standarized columns pivot = age_abuse %>%pivot_longer(cols =c(`Total Drug Abuse 12-17`, `Total Drug Abuse 18-25`, `Total Drug Abuse 26+`), names_to ="Age Groups",values_to ="Drug Abuse Totals" )
#assigning x and y axes ggplot(pivot, aes(x = Year, y =`Drug Abuse Totals`, fill =`Age Groups`)) +#use exact values in dataset geom_bar(stat ="identity", position ="dodge") +#prevents the graphs from overlapping, and instead places them side-by-side for easy comparisontheme_minimal() +labs(title ="Total Substance Abuse Across Age Groups", #adding an appropriate title subtitle ="Drugs including: Alcohol, Cocaine, and Marijuana", #subtitle caption ="Source: CORGIS, gathered by NSDUH", #data source y ="Drug Abuse Totals") +#adding a subtitle to specifiy the drugs includedscale_fill_manual(values =c("deeppink3", "lightblue4", "gray80")) #customizing the colors of each bar
#wide data --> long data ,, creating two new categories and tidying numerical data within categories substance_pivot = age_abuse %>%pivot_longer(cols =c(`Alcohol 12-17`, `Alcohol 18-25`, `Alcohol 26+`, `Cocaine 12-17`, `Cocaine 18-25`, `Cocaine 26+`, `Marijuana 12-17`, `Marijuana 18-25`, `Marijuana 26+`),names_to =c("Substance", "Age Group"), names_sep =" ", values_to ="Abuse Counts" )
ggplot(substance_pivot, aes(x =`Age Group`, y =`Abuse Counts`, color = Substance, group = Substance,)) +geom_boxplot(alpha = .3, outlier.colour ="slateblue3") +#changing the color of the two outlier points theme_minimal() +stat_summary(fun = mean, geom ="line", linewidth = .8) +#graphing line to connect average points stat_summary(fun = mean, geom ="point", size =1.6) +#graphing the average points labs(title ="Relationship Between Substance Abuse Across Age Groups", #titlesubtitle ="Tracking Average Substance Abuse of Each Age Group", #subtitle caption ="Source: CORGIS, gathered by NSDUH", #data sourcey ="Average Abuse") +#y-axisscale_color_manual(values =c("hotpink3", "turquoise3", "snow4")) +#custom colors scale_fill_manual(values =c("hotpink3","turquoise3", "snow4" )) #custom colors
Linear Regression
fit1 =lm(`Abuse Counts`~`Age Group`* Substance, data = substance_pivot)summary(fit1)
I began by cleaning the dataset, as it contained a lot of data. Using the select() function and incorporating both starts_with() / contains() functions allowed me to keep the total substance abuse from the past year for every age group and substance type. The data was separated by state and year, so each year had 50 entries. To refine the data, I made use of the group_by() function and totaled the values for each year entry, leaving one row per year.
Visualizations
The first visualization dealt with comparing the total substance abuse across age groups. Each variable had its own column, resulting in wide data. In order to visualize it, I utilized pivot_longer() to collapse my data into two standard columns.
I then turned the data into a bar graph to easily compare the substance abuse of each age group visually. The visualization displayed a considerable difference in total substance abuse across age groups. The total substance abuse of those 26 and older was substantially higher compared to 12-17 and 18-25. Total substance abuse among 12-17 presented a downward trend (decrease in total substance abuse) as time went on, whereas 26+ exhibited an upward trend (increasing substance abuse). Total substance abuse among 18-25 was between the two and stayed relatively stable throughout the years.
Again, I used pivot_longer() to make the data suitable for the box plot and linear regression. This time, pivot_longer() created two new categories and tidied the numerical data within them.
I then used the new pivot data to create a box plot. Geom = “point” graphed the points of substance abuse averages for each age group. Geom = “line” connected the points, allowing comparison to be easier. Among the three substance types, marijuana had the highest abuse for all age groups. Cocaine had the lowest average use, and alcohol was in the middle.
Linear Regression
The linear regression was meant to evaluate the relationship between age groups (12-17, 18-25, 26+) and specific substance abuse (Alcohol, Cocaine, Marijuana). The p-value was extremely statistically significant at 2.2e-16 (almost 0). The p-value being as small as it was proved that there is a highly significant relationship between age group and specific substance use. We can understand that the model is highly accurate, as adjusted R-squared = .89. Overall, the model suggests there is a significant relationship between age group and specific substance abuse.
Technical Challenges
One technical challenge I faced was actually visualizing the data. Since I had wide data, I needed to incorporate the pivot() function to convert it into long data to visualize it properly. I struggled with the pivot() function even with the assistance of class slides and an RStudio Guide. It was definitely a trial-and-error process, with many errors.