-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_multivariate_analysis.R
More file actions
177 lines (163 loc) · 5.75 KB
/
3_multivariate_analysis.R
File metadata and controls
177 lines (163 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Final Project 3_multivariate_analysis ----
# Stat 301-1
## load packages ----
library(tidyverse)
library(ggthemes)
library(knitr)
## load dataset
YA_19_21 <-read_rds("data/YA_clean_19_21.rds")
#k6mon over year for grad/in
k6mon_comp_year <-YA_19_21 %>%
filter(postin_coll!="Neither") %>%
ggplot(aes(x=factor(year),y=k6scmon)) +
geom_boxplot() +
facet_wrap(~postin_coll) +
labs(title="Distribution of Current K6 Scores 2019-2021 vs College Completion",
x="Year",
y="K6 Score for Current Month") +
theme_light()
ggsave(k6mon_comp_year,filename="figures/3_k6mon_comp_year.png", scale=1.3)
#k6max over year for grad/in
k6max_comp_year <- YA_19_21 %>%
filter(postin_coll!="Neither") %>%
ggplot(aes(x=factor(year),y=k6scmax)) +
geom_boxplot() +
facet_wrap(~postin_coll) +
labs(title="Distribution of Worst K6 Scores 2019-2021 vs College Completion",
x="Year",
y="K6 Score for Worst Month")+
theme_light()
ggsave(k6max_comp_year,filename="figures/3_k6max_comp_year.png", scale=1.3)
#k6mon over year for ft
k6mon_ft_year <- YA_19_21 %>%
filter(collenrlft!="Unknown or not 18-22") %>%
ggplot(aes(x=factor(year),y=k6scmon)) +
geom_boxplot() +
facet_wrap(~collenrlft) +
labs(title="Distribution of Current K6 Scores 2019-2021 for College-Aged Adults",
x="Year",
y="K6 Score for Worst Month")+
theme_light()
ggsave(k6mon_ft_year,filename="figures/3_k6mon_ft_year.png", scale=1.3)
#k6max over year for ft
k6max_ft_year <- YA_19_21 %>%
filter(collenrlft!="Unknown or not 18-22") %>%
ggplot(aes(x=factor(year),y=k6scmax)) +
geom_boxplot() +
facet_wrap(~collenrlft) +
labs(title="Distribution of Worst K6 Scores 2019-2021 for College-Aged Adults",
x="Year",
y="K6 Score for Worst Month")+
theme_light()
ggsave(k6max_ft_year,filename="figures/3_k6max_ft_year.png", scale=1.3)
#month by drug per year coll complete
mondrugcomp <- YA_19_21 %>%
filter(postin_coll!="Neither")%>%
pivot_longer(
cols = contains("fm"),
names_to = "drug",
values_to = "frequency"
) %>%
group_by(drug,year,postin_coll) %>%
summarise(meanfq = mean(frequency,na.rm=TRUE)) %>%
mutate(drug=fct_recode(factor(drug),
"Alcohol"="iralcfm",
"Cigarettes"="ircigfm",
"Cocaine"="ircocfm",
"Marijuana"="irmjfm")) %>%
ggplot(aes(x=year,y=meanfq,color=drug)) +
geom_line() +
scale_x_continuous(breaks = c(2019, 2020,2021)) +
facet_wrap(~postin_coll) +
labs(title="Monthly Drug Use Among Graduated and In College from 2019-2021",
x="Year",
y="Average Times Used in Past Month",
color="Drug") +
theme_light()
ggsave(mondrugcomp,filename="figures/3_mondrugcomp.png",scale=1.3)
#month by drug per year 18-22
mondrugft <- YA_19_21 %>%
filter(collenrlft!="Unknown or not 18-22")%>%
pivot_longer(
cols = contains("fm"),
names_to = "drug",
values_to = "frequency"
) %>%
group_by(drug,year,collenrlft) %>%
summarise(meanfq = mean(frequency,na.rm=TRUE)) %>%
mutate(drug=fct_recode(factor(drug),
"Alcohol"="iralcfm",
"Cigarettes"="ircigfm",
"Cocaine"="ircocfm",
"Marijuana"="irmjfm")) %>%
ggplot(aes(x=year,y=meanfq,color=drug)) +
geom_line() +
scale_x_continuous(breaks = c(2019, 2020,2021)) +
facet_wrap(~collenrlft)+
labs(title="Monthly Drug Use Among College Aged Adults",
x="Year",
y="Average Times Used in Past Month",
color="Drug") +
theme_light()
ggsave(mondrugft,filename="figures/3_mondrugft.png",scale=1.3)
#vape without never
vapewonever <- YA_19_21 %>%
filter(!is.na(irvapnicrec),irvapnicrec!="Never") %>%
ggplot(aes(x=year,fill=irvapnicrec)) +
geom_bar(position="fill") +
scale_x_continuous(breaks = c(2020,2021)) +
facet_wrap(~postin_coll) +
labs(title="Nicotine Vaping Recency in College Aged Users",
x="Year",
y="Proportion",
fill="Vaping Recency")+
theme_light()
ggsave(vapewonever,filename="figures/3_vapewonever.png")
#vape with never
vapewnever <-YA_19_21 %>%
filter(!is.na(irvapnicrec)) %>%
ggplot(aes(x=year,fill=irvapnicrec)) +
geom_bar(position="fill") +
scale_x_continuous(breaks = c(2020,2021)) +
facet_wrap(~postin_coll)+
labs(title="Nicotine Vaping Recency in College Aged Adults",
x="Year",
y="Proportion",
fill="Vaping Recency")+
theme_light()
ggsave(vapewnever,filename="figures/3_vapewnever.png")
# collyear_drug
collyear_drug<- YA_19_21 %>%
filter(eduschgrd2=="4th year or higher"|
eduschgrd2=="2nd or 3rd year"|
eduschgrd2=="1st year")%>%
pivot_longer(
cols = contains("fm"),
names_to = "drug",
values_to = "frequency"
) %>%
group_by(drug,year,eduschgrd2) %>%
summarise(meanfq = mean(frequency,na.rm=TRUE)) %>%
mutate(drug=fct_recode(factor(drug),
"Alcohol"="iralcfm",
"Cigarettes"="ircigfm",
"Cocaine"="ircocfm",
"Marijuana"="irmjfm")) %>%
ggplot(aes(x=year,y=meanfq,color=drug)) +
geom_line() +
facet_wrap(~eduschgrd2) +
scale_x_continuous(breaks = c(2019, 2020,2021)) +
labs(title="Monthly Drug for Use for College Students by Year from 2019-2021",
x="Year",
y="Average Times Used in Past Month",
color="Drug") +
theme_light() +
theme(panel.spacing.x = unit(6, "mm"))
ggsave(collyear_drug,filename="figures/3_collyear_drug.png",scale=1.3)
#execsum k6 score table
YA_19_21 %>%
filter(postin_coll!="Neither") %>%
group_by(year,postin_coll) %>%
summarise(mean = mean(k6scmax, na.rm= TRUE),
median = median(k6scmax, na.rm= TRUE)) %>%
kable(cols = c("Year","College Completion", "Mean K6","Median K6"))